Advertisement
JkSoftware

Day 18 - Random Walk

Nov 27th, 2021
1,250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. from turtle import Turtle, Screen
  2. import turtle as t
  3. import random
  4.  
  5. t.colormode(255)
  6. timmy = Turtle()
  7. timmy.shape("arrow")
  8. timmy.pensize(15)
  9.  
  10. directions = [0, 90, 180, 270]
  11.  
  12. def random_color():
  13.     r = random.randint(0, 255)
  14.     g = random.randint(0, 255)
  15.     b = random.randint(0, 255)
  16.     random_color = (r, g, b)
  17.     return random_color
  18.  
  19. def draw_shape():
  20.     timmy.color(random_color())
  21.     timmy.forward(30)
  22.     timmy.setheading(random.choice(directions))
  23.  
  24.  
  25. for i in range(500):
  26.     draw_shape()
  27.  
  28. screen = Screen()
  29. screen.exitonclick()
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement