-
Notifications
You must be signed in to change notification settings - Fork 0
/
Langton's Ant Pattern RRLLLRLLLRRR.py
168 lines (131 loc) · 4.8 KB
/
Langton's Ant Pattern RRLLLRLLLRRR.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import turtle
def langton():
step_counter=0
# Initializing the Window
window = turtle.Screen()
window.bgcolor('white')
window.screensize(1000,1000)
# Contains the coordinate and colour
maps = {}
# Initializing the Ant
ant = turtle.Turtle()
# shape of the ant
ant.shape('square')
# size of the ant
ant.shapesize(0.5)
# speed of the ant
ant.speed(100000000000)
# gives the coordinate of the ant
pos = coordinate(ant)
counter=turtle.Turtle(visible=False)
while True:
counter.undo()
counter.penup()
counter.setposition(-600,350)
counter.write("Steps=" +str(step_counter),font=("Arial",20,"normal"))
# print(step_counter)
# distance the ant will move
step = 10
if pos not in maps or maps[pos] == "white":
ant.fillcolor("red")
invert(maps, ant, "red")
ant.stamp()
ant.right(90)
ant.forward(step)
pos = coordinate(ant)
step_counter=step_counter+1
elif maps[pos] == "red":
ant.fillcolor("light green")
invert(maps, ant, "light green")
ant.stamp()
ant.right(90)
ant.forward(step)
pos = coordinate(ant)
step_counter=step_counter+1
elif maps[pos] == "light green":
ant.fillcolor("cyan")
invert(maps, ant, "cyan")
ant.stamp()
ant.left(90)
ant.forward(step)
pos = coordinate(ant)
step_counter=step_counter+1
elif maps[pos] == "cyan":
ant.fillcolor("orange")
invert(maps, ant, "orange")
ant.stamp()
ant.left(90)
ant.forward(step)
pos = coordinate(ant)
step_counter=step_counter+1
elif maps[pos] == "orange":
ant.fillcolor("pink")
invert(maps, ant, "pink")
ant.stamp()
ant.left(90)
ant.forward(step)
pos = coordinate(ant)
step_counter=step_counter+1
elif maps[pos] == "pink":
ant.fillcolor("light grey")
invert(maps, ant, "light grey")
ant.stamp()
ant.right(90)
ant.forward(step)
pos = coordinate(ant)
step_counter=step_counter+1
elif maps[pos] == "light grey":
ant.fillcolor("dark red")
invert(maps, ant, "dark red")
ant.stamp()
ant.left(90)
ant.forward(step)
pos = coordinate(ant)
step_counter=step_counter+1
elif maps[pos] == "dark red":
ant.fillcolor("green")
invert(maps, ant, "green")
ant.stamp()
ant.left(90)
ant.forward(step)
pos = coordinate(ant)
step_counter=step_counter+1
elif maps[pos] == "green":
ant.fillcolor("blue")
invert(maps, ant, "blue")
ant.stamp()
ant.left(90)
ant.forward(step)
pos = coordinate(ant)
step_counter=step_counter+1
elif maps[pos] == "blue":
ant.fillcolor("yellow")
invert(maps, ant, "yellow")
ant.stamp()
ant.right(90)
ant.forward(step)
pos = coordinate(ant)
step_counter=step_counter+1
elif maps[pos] == "yellow":
ant.fillcolor("purple")
invert(maps, ant, "purple")
ant.stamp()
ant.right(90)
ant.forward(step)
pos = coordinate(ant)
step_counter=step_counter+1
elif maps[pos] == "purple":
ant.fillcolor("white")
invert(maps, ant, "white")
ant.stamp()
ant.right(90)
ant.forward(step)
pos = coordinate(ant)
step_counter=step_counter+1
def invert(graph, ant, color):
graph[coordinate(ant)] = color
def coordinate(ant):
return (round(ant.xcor()), round(ant.ycor()))
#------------ΜΑΙΝ------------#
if __name__=="__main__":
langton()