-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathdennislangtonant.py
62 lines (44 loc) · 1.17 KB
/
dennislangtonant.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
# importing turtle module
import turtle
def langton():
# 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(10000)
# gives the coordinate of the ant
pos = coordinate(ant)
while True:
# distance the ant will move
step = 10
if pos not in maps or maps[pos] == "white":
#inverts the colour
ant.fillcolor("black")
#stamps a copy of the ant on the canvas
ant.stamp()
invert(maps, ant, "black")
ant.right(90)
#moves the ant forward
ant.forward(step)
pos = coordinate(ant)
elif maps[pos] == "black":
ant.fillcolor("white")
invert(maps, ant, "white")
ant.stamp()
ant.left(90)
ant.forward(step)
pos = coordinate(ant)
def invert(graph, ant, color):
graph[coordinate(ant)] = color
def coordinate(ant):
return (round(ant.xcor()), round(ant.ycor()))
langton()