-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathartist.py
58 lines (40 loc) · 1.18 KB
/
artist.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
<<<<<<< HEAD
# Draw repeated random walks using a random colors
=======
# Drawing of repeated random walks using random colors for each walk.
>>>>>>> 8e77e8766d998dfd2f320ecceb76c1aa3cfa29e0
from turtle import *
from random import randint, uniform
width, height = 1000, 1000
def random_move(turtle, distance):
# turn turtle through random angle and move forward by random distance
angle = uniform(-90, 90)
d = uniform(0,distance)
turtle.color(randcolor(), randcolor())
turtle.left(angle)
turtle.forward(d)
def randcolor():
return (randint(0, 255), randint(0, 255), randint(0, 255))
def gohome(turtle):
# send turtle home without leaving a track.
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
def random_walk(turtle, distance, steps):
# Send turtle on random walk.
fred.pensize(1)
for step in range(0, steps):
random_move(turtle, distance)
gohome(turtle)
def repeat(trials):
steps = 5000 # length of one branch?
while True:
random_walk(fred, 5, steps)
fred = Turtle()
fred.speed("fastest")
fred.dot(2, "red")
colormode(255)
bgcolor("black")
print (' width, height = %d, %d' % (width, height) )
setup( width, height, startx = None, starty = None)
repeat(20)