A Python library for generating multi-scale Truchet tile patterns and images using PyCairo
Project description
Truchet Viewer
A Python library for generating and exploring multi-scale Truchet tile patterns using PyCairo and Streamlit. This library provides tools for creating complex, visually appealing patterns through both interactive Jupyter notebooks and a web-based app.
Features
- Generate multi-scale Truchet tile patterns with customizable depth and complexity
- Rich set of predefined tiles including circles, lattices, and filled shapes
- Interactive exploration through Jupyter notebooks and Streamlit app
- Flexible Cairo-based rendering supporting SVG and PNG output
Description
The history of Truchet tiles begins in the early 18th century with Father Sebastien Truchet, who first described them in his 1704 memoir, Mémoire sur les combinaisons. Truchet's original square tiles were divided diagonally into two contrasting triangles, forming the basis for exploring intricate combinatorial patterns. The idea was significantly popularized in 1987 by Cyril Stanley Smith in his paper, The tiling patterns of Sebastian Truchet and the topology of structural hierarchy. Smith introduced the highly popular variation featuring quarter-circle arcs that connect the midpoints of adjacent sides, forming continuous, meandering paths when tiled. Building on this, Christopher Carlson later introduced multi-scale Truchet patterns by using "winged" tiles scaled by factors of 1/2, allowing different scale tiles to overlap and merge seamlessly.
The original implementation was done by Ned Batchelder using PIL and PyCairo. This library reimplements and extends that work, providing a more flexible and user-friendly interface for generating and exploring Truchet patterns.
Installation
Prerequisites
The package requires Python 3.12 or later and depends on PyCairo. On some systems, you may need to install Cairo development headers:
# Ubuntu/Debian
sudo apt-get install libcairo2-dev pkg-config python3-dev
# macOS
brew install cmake pkgconf cairo
# Windows
# Install Cairo through MSYS2 or use the wheels available on PyPI
Installing from PyPI
The package is available on PyPI and can be installed via pip:
pip install truchet-viewer
Installing from Source
Clone the repository and install in development mode:
git clone https://github.com/jobar8/truchet-viewer.git
cd truchet-viewer
pip install -e .
Instead of using pip, you can also use uv to install the development dependencies in a local virtual environment:
uv sync
source .venv/bin/activate
Quick Start
Using the Jupyter Notebooks
Launch Jupyter Notebook and open the example notebooks in the examples/ directory:
jupyter lab
Using the Streamlit App
Launch the Streamlit app to interactively explore Truchet patterns:
cd truchet-viewer
streamlit run streamlit_app.py
# or if uv is installed (also installs dependencies):
uv run streamlit run streamlit_app.py
Generating a Multi-Scale Truchet Pattern
Here is a simple example of generating a multi-scale Truchet pattern using the N6 tile set:
from truchet_viewer import multiscale_truchet, show_tiles
from truchet_viewer.n6 import n6_tiles
# Display available tiles
show_tiles(n6_tiles, with_value=True, with_name=True)
# Generate a multi-scale pattern
multiscale_truchet(
tiles=n6_tiles,
width=800,
height=600,
tilew=100,
nlayers=3,
chance=0.45
)
This will create a multi-scale Truchet pattern using the N6 tile set. The nlayers parameter controls the number of levels.
It should look something like this:
Examples
Check out the example notebooks in the examples/ directory:
Truchet.ipynb- Basic usage and pattern generationN6.ipynb- Exploring different tile types
Acknowledgments
This project implements Christopher Carlson's work on multi-scale Truchet tiles. The original inspiration came from a blog post by Ned Batchelder, who implemented the first version.
License
This code is Apache licensed. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file truchet_viewer-1.0.0.tar.gz.
File metadata
- Download URL: truchet_viewer-1.0.0.tar.gz
- Upload date:
- Size: 2.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5438335da2917c4d328cfc355a498c7b085c030ae9766cafe09ad5b009a8ea5c
|
|
| MD5 |
370f5ffe9ec55ba28aaf63222e474066
|
|
| BLAKE2b-256 |
9d298cc13dd6278f279414509476fd71706e084ae5d7b7b54550707526145a49
|
File details
Details for the file truchet_viewer-1.0.0-py3-none-any.whl.
File metadata
- Download URL: truchet_viewer-1.0.0-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f9ad893a99dde32ec216b67bd39a05ef5d3199d505ace7f6ea7eea2913e3d1e
|
|
| MD5 |
5da6d7c443ac9850c32212d2493c5a08
|
|
| BLAKE2b-256 |
b94bd8437d7f1a0ead97ae8d627a3ca91d7d44d328eee739f59a44c47db1ea3b
|