# Generalized Penrose tilings

**Example:**

**Requirements:**

`numpy`

and`cairocffi`

.- The free raytracer
`POV-Ray`

.

This program renders generalized Penrose tilings using de Bruijn's penragrid method.

# Usage

The code consists of three python scripts `penrose_debruijn.py`

, `penrose_kitedart`

, `penrose_rhombus.py`

and several `.inc`

, `.pov`

files for POV-Ray rendering.

Firstly run `python penrose_debruijn.py`

, this will output a png image of a generalized Penrose tiling rendered by `cairo`

and a POV-Ray include file `rhombus.inc`

, then you can render the `.pov`

file with POV-Ray (don't run the `.inc`

files, they are include files by the scenes).

The script `penrose_kitedart`

draws the "kite and dart" pattern by the inflation way. The script `penrose_rhombus`

draws the classical Penrose rhombus pattern by the inflation way.

One can also use `ImageMagick`

to add some shading effect on the image rendered by `cairo`

:

convert penrose_cairo.png +shade 20x20 -modulate 250 penrose_cairo.png |

# About the code

This program uses de Bruijn's pentagrid method to draw aperiodic tilings. The main steps are:

Define the directions of the five grids:

GRIDS = [np.exp(2*np.pi*1j/5) for j in range(5)]

and the number of lines in each grid.

Shift each grid with a real number between 0 and 1:

SHIFTS = np.random.random(5)

When the sum of these five real numbers is an integer then it gives the classical Penrose tiling, two different shifts give "the same" pattern (called "locally isomorphic") if and only if their sum are congruent mod 1.

Compute the tiling: for each intersection point of these grid lines there is a rhombus, i.e. for each

`0 <= r < s <= 4`

and`-nlines <= kr, ks <= nlines`

, the intersecting point of the`kr-th`

line in the`r-th`

grid and the`ks-th`

line in the`s-th`

grid correspondes to a rhombus in the tiling. If`s-r == 1 or 4`

then this is a thin rhombus, otherwise it's fat.Draw the tiling and assign different colors to the thin rhombus and the fat rhombus.

# References

Algebraic theory of Penrose's non-periodic tilings of the plane. N.G.de Bruijn.

上一篇：Reaction-Diffusion Simulation with pyglet and GLSL

下一篇：Perfectly random sampling (2): Wilson's uniform spanning tree algorithmcore