-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecaman.py
More file actions
50 lines (38 loc) · 1.16 KB
/
recaman.py
File metadata and controls
50 lines (38 loc) · 1.16 KB
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
#source - https://simpleprogrammer.com/python-generative-art-math/
import turtle
window = turtle.Screen();
turtlePen = turtle.Turtle();
scale = 1;
speed = 20
colors = ["red", "green", "blue", "yellow", "black", "orange"]
def init():
turtlePen.shape("turtle");
turtlePen.speed(speed);
screenOffset = turtle.window_width() / 2 * -1;
moveTurtle(0,0)
def moveTurtle(x,y):
turtlePen.penup();
turtlePen.setpos(x,y);
turtlePen.pendown();
def setTurtleColorByIndex(index):
turtlePen.color(colors[index%len(colors)])
def startRecaman():
currentIndex = 0;
visited = set();
for index in range(1,200):
backIndex = currentIndex - index
setTurtleColorByIndex(index);
if backIndex > 0 and backIndex not in visited:
turtlePen.setheading(90);
turtlePen.circle(index/2 * scale, 180);
currentIndex = index;
visited.add(index);
else:
turtlePen.setheading(270);
turtlePen.circle(index/2 * scale, 180);
currentIndex += index;
visited.add(currentIndex);
print(currentIndex);
turtle.done();
init();
startRecaman();