'''lecture_10_random_walk.py Have 3 turtles walk around randomly with their unique properties Oliver W. Layton CS 151: Computational Thinking: Visual Media Fall 2020 TODO: Move the screen creation and customization to a make_screen function ''' import turtle import random def make_screen(height, width): ''' Return: a Screen object ''' '''Screen''' # call Screen's constructor to make a new pop-up window/canvas screen = turtle.Screen() # Control how big we want it screen.setup(height=height, width=width) return screen # main code # height = 600 # width = 800 # screen = make_screen(height, width) my_screen = make_screen(800, 600) # Make turtles (turtle shape) and customize their properties (e.g. color) turtle1 = turtle.Turtle() turtle2 = turtle.Turtle() turtle3 = turtle.Turtle() turtle1.pencolor('blue') turtle2.pencolor('green') turtle3.pencolor('red') turtle1.shape('turtle') turtle2.shape('turtle') turtle3.shape('turtle') turtle1.speed(0) turtle2.speed(0) turtle3.speed(0) # Make turtles move randomly 1000 times. numSteps = 1000 for i in range(numSteps): # Change their direction (randomly) every 10 movements if i % 10 == 0: turtle1.right(random.randint(0, 360)) turtle2.setheading(360*random.random()) turtle3.setheading(360*random.random()) # Move them forward a random amount (1-3 pixels) turtle1.forward(random.randint(1, 3)) turtle2.forward(2*random.random() + 1) turtle3.forward(2*random.random() + 1) my_screen.exitonclick()