1
# examples derived from
2
# Visual Modeling with Logo: A Structural Approach to Seeing
5
# Turtle Geometry: The Computer as a Medium for Exploring Mathematics
6
# by Harold Abelson and Andrea diSessa
9
from tWrapper import tWrapper
11
#class turtleCurves(wxTurtle.Pen):
12
class turtleCurves(tWrapper):
14
def cCurve(self, size, level):
18
self.cCurve(size, level - 1)
20
self.cCurve(size, level - 1)
24
def lDragon(self, size, level):
28
self.lDragon(size, level - 1)
30
self.rDragon(size, level - 1)
33
def rDragon(self, size, level):
37
self.lDragon(size, level - 1)
39
self.rDragon(size, level - 1)
41
# example derived from
42
# Turtle Geometry: The Computer as a Medium for Exploring Mathematics
43
# by Harold Abelson and Andrea diSessa
45
def hilbert(self, size, level, parity):
48
# rotate and draw first subcurve with opposite parity to big curve
49
self.left(parity * 90)
50
self.hilbert(size, level - 1, -parity)
51
# interface to and draw second subcurve with same parity as big curve
53
self.right(parity * 90)
54
self.hilbert(size, level - 1, parity)
57
self.hilbert(size, level - 1, parity)
59
self.right(parity * 90)
61
self.hilbert(size, level - 1, -parity)
62
# a final turn is needed to make the turtle
63
# end up facing outward from the large square
64
self.left(parity * 90)
66
# Visual Modeling with Logo: A Structural Approach to Seeing
68
# Koch curve, after Helge von Koch who introduced this geometric figure in 1904
70
def fractalgon(self, n, rad, lev, dir):
73
# if dir = 1 turn outward
74
# if dir = -1 turn inward
75
edge = 2 * rad * math.sin(math.pi / n) # logo uses sin(180 / n); Python uses radians
79
self.rt(180 - (90 * (n - 2) / n))
81
self.fractal(edge, lev, dir)
83
self.lt(180 - (90 * (n - 2) / n))
89
def fractal(self, dist, depth, dir):
93
self.fractal(dist / 3, depth - 1, dir)
95
self.fractal(dist / 3, depth - 1, dir)
97
self.fractal(dist / 3, depth - 1, dir)
99
self.fractal(dist / 3, depth - 1, dir)