Thue-Morse plotter
Draw a pretty pattern based on the Thue-Morse sequence.
This commit is contained in:
commit
850defccb7
32
plot.py
Normal file
32
plot.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import turtle
|
||||||
|
|
||||||
|
SIZE = 5
|
||||||
|
ANGLE = 108
|
||||||
|
X0 = 0
|
||||||
|
Y0 = 400
|
||||||
|
DOUBLES = 14 # 14 takes "many minutes" on my machine. Each extra double doubles space and time required.
|
||||||
|
thue = "ABBA"
|
||||||
|
turtle.penup()
|
||||||
|
turtle.speed(0)
|
||||||
|
turtle.setx(X0)
|
||||||
|
turtle.sety(Y0)
|
||||||
|
|
||||||
|
def extend(thue):
|
||||||
|
opp = ""
|
||||||
|
for i in thue:
|
||||||
|
if i == "A":
|
||||||
|
opp += "B"
|
||||||
|
else:
|
||||||
|
opp += "A"
|
||||||
|
return thue + opp
|
||||||
|
|
||||||
|
for i in range(14):
|
||||||
|
thue = extend(thue)
|
||||||
|
|
||||||
|
turtle.pendown()
|
||||||
|
for t in thue:
|
||||||
|
if t == "A":
|
||||||
|
turtle.forward(SIZE)
|
||||||
|
else:
|
||||||
|
turtle.forward(SIZE*2)
|
||||||
|
turtle.right(ANGLE)
|
||||||
Loading…
Reference in New Issue
Block a user