-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdragon_curve.py
47 lines (38 loc) · 930 Bytes
/
dragon_curve.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
###################################################
# dragon_curve.py
# lsystem representation of a dragon curve...?
# author: stphndemos
###################################################
import sys
from lsys import gen_lsys
import turtle
segment_length = 5
angle = 90
def draw_segment():
turtle.forward(segment_length)
def turn_left():
turtle.left(angle)
def turn_right():
turtle.right(angle)
def init_turtle():
turtle.ht()
turtle.up()
turtle.speed(0)
# turtle.setpos(-600, -300)
turtle.down()
alphabet = { 'A' : draw_segment,
'B' : draw_segment,
'+' : turn_left,
'-' : turn_right,
}
axiom = 'A'
rules = { 'A' : 'A+B',
'B' : 'A-B'
}
def main():
init_turtle()
gen_lsys(alphabet, axiom, rules, int(sys.argv[1]))
print 'click to exit'
turtle.exitonclick()
if __name__ == '__main__':
main()