A library to generate P3 tiles inside a polygon, based on apaleyes/penrose-tiling.
This library fills an approximate number of random rhombus Penrose P3 tiles tiles in a polygon, and calculates the neighbors of those rhombuses.
It uses an algorithm described by Simon Tatham in “Choosing a random patch from a fixed expansion”. (This works perfectly for a P3 tiling, so we don’t need the more advanced technique he describes later.)
We put the polygon in a random place and scale inside a starting Robinson triangle. By default, a golden gnomon is used. This is an isosceles triangles with an inverse golden ratio between the length of the equal sides and the length of the base.
Then we recursively split any triangles which intersect the polygon using Robinson triangle decompositions, and throw out the non-intersecting triangles, until we have generated enough tiles.
We also use Tatham’s combinatorial coordinates to deduce which triangles are neighbors. From there, we know which triangles to combine into rhombuses, and which rhombuses are neighbors.
Finally, we need to coalesce matching triangles into rhombuses, and clean up the border to avoid ragged edges (characterized by gaps and tiles connected by one or less sides). This part of the library is a work in progress. Currently there are two algorithms:
cull
removes any half-rhombs and then repeatedly removes any rhombus which only has one neighbor.fill
generates the other half of rhombuses when the first half has two neighbors (and we may want to fill whole rhombuses after)Perhaps the ideal algorithm would minimize the border length / tile count ratio using such primitives.
If you are interested in contributing to this library, help is welcome:
calculatePenroseTiling
function into modular steps - especially if you have a use case to motivate more flexibility.Thanks to Andrei Paleyes for the original penrose-tiling, which provides the Robinson triangle-splitting algorithm.
Thanks to Daria Vasyukova @gereleth for encouraging and helping implement a P3 tiling for hexapipes. demo here