/
test.py
101 lines (80 loc) · 3.09 KB
/
test.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from twisted.internet import reactor
from twisted.internet.task import cooperate, LoopingCall
from turtles import setup_window, TurtleContext, Dispatcher
if __name__ == "__main__":
canvas = setup_window("Logo140 - Leeds Hack 2012")
#create some demo turtles
tc1 = TurtleContext(canvas)
tc2 = TurtleContext(canvas)
tc3 = TurtleContext(canvas)
tc4 = TurtleContext(canvas)
tc5 = TurtleContext(canvas)
tc6 = TurtleContext(canvas)
tc7 = TurtleContext(canvas)
tc8 = TurtleContext(canvas)
tc9 = TurtleContext(canvas)
tc10 = TurtleContext(canvas)
tc1.parse('setpc blue')
tc2.parse('setpc red')
tc3.parse(u'setpc green')
tc4.parse('setpc orange')
tc5.parse('setpc purple')
tc6.parse('setpc blue')
tc7.parse('setpc red')
tc8.parse('setpc green')
tc9.parse('setpc orange')
tc10.parse('setpc purple')
tc2.turtle.left(180)
tc3.turtle.left(90)
tc4.turtle.left(270)
tc5.turtle.left(230)
tc7.turtle.left(130)
tc8.turtle.left(40)
tc9.turtle.left(220)
tc10.turtle.left(190)
#tc1.parse('to square repeat 4 [fd 50 rt 90] end')
##tc1.parse('to square repeat 4 [fd 50 rt 90 square] end') #recursive
##tc1.parse('square')
##tc1.parse('repeat 36 [ square rt 10] ')
#tc1.parse('to flower repeat 36 [rt 10 square] end')
#tc1.parse('flower') #nested function call
s= 'repeat 10 [REpEAT 90[fd 4 rt 4] rt 36]' #nested repeat
s = """TO sawtooth RT 45 FD 56 LT 135 FD 40 RT 90 END
TO sawblade REPEAT 12 [ sawtooth rt 30 ] END
TO eyeball REPEAT 36 [ sawblade rt 10] END
eyeball"""
tc1.parse(s)
tc2.parse(s)
s='TO square REPEAT 4 [FD 30 RT 90] END REPEAT 10 [square RT 36]'
tc3.parse(s)
#s = 'repeat 10 [ pu fd 5 pd fd 5 ]' #dotted
s = 'FD 50 setpc magenta fd 50'
tc4.parse(s)
#s = 'repeat 18 [repeat 5 [rt 40 fd 100 rt 120] rt 20]'
#tc5.parse(s)
#s = 'repeat 36 [repeat repcount [repeat repcount [fd repcount lt 15] home] lt 1]' #growing (may want to stop before done)
#s= 'repeat 36 [repeat 36 [fd 10 rt 10] fd repcount rt 90 fd repcount]'
tc6.parse(s)
#s='repeat 12 [repeat 75 [fd 100 bk 100 rt 2] fd 250]' #fanflower
#tc7.parse(s)
#s = 'repeat 8 [repeat 4 [rt 90 fd 100] bk 100 lt 45]' #hypercube
#tc8.parse(s)
#s = 'repeat 100 [ fd repcount rt 90 ]' #todo repcount*2
#tc9.parse(s)
#s = 'to SAWTOOTH rt 45 fd 56 lt 135 fd 40 rt 90 end'
#tc10.parse(s)
#s= 'to SAWBLADE repeat 12 [ SAWTOOTH rt 30 ] end'
#tc10.parse(s)
#s = 'SAWBLADE'
#tc10.parse(s)
#tc1.parse('to SAWTOOTH rt 45 fd 56 lt 135 fd 40 rt 90 end')
#tc1.parse('to SAWBLADE repeat 12 [ SAWTOOTH rt 30 ] end')
#tc1.parse('to eyeball repeat 36 [ SAWBLADE rt 10] end')
#tc1.parse('eyeball')
#for tc in tcs:
# print unicode(tcs[tc])
#no SQS for testing
#dispatcher = Dispatcher(canvas=canvas)
#l = LoopingCall(dispatcher.dispatcher)
#l.start(5.0)
reactor.run() #no need for tk mainloop