This repository contains several Python 3 modules for building and manipulating Penrose tilings. For now, only the kite-and-dart (P2) and rhombus (P3) tilings are supported (as well as the associated Robinson A and B tilings), but it should be fairly easy to add support for the P1 tiling as well.
NOTE: I (Zachary Catlin) do not intend to work on this further, package this for PyPI, etc. If you’re interested in developing this further, please feel free to fork this repository.
This is extracted from a private project of mine; as there’s nothing particularly secret about the code I wrote, I’m posting it in case someone else would find it useful.
The main show is in the following modules, listed by increasing level of abstraction:
-
pen_num
– the classNumber
is an implementation of the number field ℚ[√(10+2√5)], which allows for exact representation of tile coordinates (for the tile sets in question) and rotation matrices for multiples of 18° (also relevant for the tile sets in question). -
pen_geom
– geometric primitives—e.g., points, line segments, affine transforms—and operations and predicates involving these primitives. Usespen_num.Number
to represent coordinates and other numeric values. -
penrose
– contains a class to represent a tile with a matching rule; subclasses implement the tiles of the P2, P3, A, & B tilings. -
tile_manager
– a container for managing a set of positioned tiles, including making sure that intersection and edge-matching constraints are obeyed, as well as supporting whole-tiling manipulations like deflation. -
tile_output
– helper functions for outputting a tiling as SVG paths.
Also, there are several accessory modules and scripts:
-
pen_num_tests
,pen_geom_tests
, andtest_runner.py
– test suite for the lower-level modules. -
decomp_check.py
– a script I used to graphically verify several of the tile decompositions. -
deflate_sun.py
– a script that starts with a P2 sun vertex figure and proceeds to repeatedly deflate it, writing out SVG images of each step. The output of this script is what I wrote these modules for in the first place.
As it stands (March 2021), this code works well, but works
slowly—running deflate_sun.py
takes several hours on my vintage-2015
laptop. From profiling runs, the major culprit appears to be the enormous
number of memory allocations/deallocations needed: a pen_num.Number
is
a composite object of composite objects.
Streamlining the layout of Number
or rewriting it in a
compiled language are probably your best bets for making this run faster.