-
Notifications
You must be signed in to change notification settings - Fork 3
/
drunkenturtle.py
35 lines (28 loc) · 986 Bytes
/
drunkenturtle.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
#-----------------------------------------------------------------------
# drunkenturtle.py
#-----------------------------------------------------------------------
import sys
import random
import stddraw
import turtle
#-----------------------------------------------------------------------
# Accept as command-line arguments an integer t specifying a number of
# iterations, and a float step specifying a step size. Create a Turtle
# object, and have it make random steps of the given step size. Repeat
# t times.
def main(args):
t = int(args[1])
step = float(args[2])
stddraw.createWindow()
myTurtle = turtle.Turtle(0.5, 0.5, 0.0)
for t1 in range(t):
myTurtle.turnLeft(360.0 * random.random())
myTurtle.goForward(step)
stddraw.show()
stddraw.wait()
if __name__ == '__main__':
main(sys.argv)
#-----------------------------------------------------------------------
# Example execution:
#
# python drunkenturtle.py 10000 .01