3
# [SNIPPET_NAME: Penrose]
4
# [SNIPPET_CATEGORIES: PyTurtle]
5
# [SNIPPET_DESCRIPTION: Use turtle to draw two Penrose tilings.]
6
# [SNIPPET_DOCS: http://docs.python.org/library/turtle.html]
7
# [SNIPPET_AUTHOR: Grant Bowman <grantbow@ubuntu.com>]
8
# [SNIPPET_LICENSE: PSF]
9
# Code authorship from http://python.org/download/releases/2.6.4/
12
""" xturtle-example-suite:
14
xtx_kites_and_darts.py
16
Constructs two aperiodic penrose-tilings,
17
consisting of kites and darts, by the method
18
of inflation in six steps.
20
Starting points are the patterns "sun"
21
consisting of five kites and "star"
22
consisting of five darts.
24
For more information see:
25
http://en.wikipedia.org/wiki/Penrose_tiling
26
-------------------------------------------
29
from math import cos, pi
30
from time import clock, sleep
32
f = (5**0.5-1)/2.0 # (sqrt(5)-1)/2 -- golden ratio
59
def inflatekite(l, n):
62
h, x, y = int(heading()), round(px,3), round(py,3)
63
tiledict[(h,x,y)] = True
81
def inflatedart(l, n):
84
h, x, y = int(heading()), round(px,3), round(py,3)
85
tiledict[(h,x,y)] = False
100
def draw(l, n, th=2):
103
shapesize(l/100.0, l/100.0, th)
110
color("black", (0, 0.75, 0))
113
color("black", (0.75, 0, 0))
131
register_shape("kite", get_poly())
135
register_shape("dart", get_poly())
145
def test(l=200, n=4, fun=sun, startpos=(0,0), th=2):
157
print "Calculation: %7.4f s" % (b - a)
158
print "Drawing: %7.4f s" % (c - b)
159
print "Together: %7.4f s" % (c - a)
160
nk = len([x for x in tiledict if tiledict[x]])
161
nd = len([x for x in tiledict if not tiledict[x]])
162
print "%d kites and %d darts = %d pieces." % (nk, nd, nk+nd)
175
#title("Penrose-tiling with kites and darts.")
184
write("Please wait...",
185
align="center", font=('Arial Black', 36, 'bold'))
186
test(600, 8, startpos=(70, 117))
189
if __name__ == "__main__":