MCPcopy Create free account
hub / github.com/python/cpython / hilbert

Method hilbert

Lib/turtledemo/fractalcurves.py:19–38  ·  view source on GitHub ↗
(self, size, level, parity)

Source from the content-addressed store, hash-verified

17 # by Harold Abelson and Andrea diSessa
18 # p. 96-98
19 def hilbert(self, size, level, parity):
20 if level == 0:
21 return
22 # rotate and draw first subcurve with opposite parity to big curve
23 self.left(parity * 90)
24 self.hilbert(size, level - 1, -parity)
25 # interface to and draw second subcurve with same parity as big curve
26 self.forward(size)
27 self.right(parity * 90)
28 self.hilbert(size, level - 1, parity)
29 # third subcurve
30 self.forward(size)
31 self.hilbert(size, level - 1, parity)
32 # fourth subcurve
33 self.right(parity * 90)
34 self.forward(size)
35 self.hilbert(size, level - 1, -parity)
36 # a final turn is needed to make the turtle
37 # end up facing outward from the large square
38 self.left(parity * 90)
39
40 # Visual Modeling with Logo: A Structural Approach to Seeing
41 # by James Clayson

Callers 1

mainFunction · 0.95

Calls 3

leftMethod · 0.80
rightMethod · 0.80
forwardMethod · 0.45

Tested by

no test coverage detected