timber101

Turtle_Basics_Part_6

Apr 18th, 2022 (edited)
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. import turtle, random
  2.  
  3. wn = turtle.Screen()
  4.  
  5. cols = ["red","yellow","blue","black","pink", "green", "cyan"] # list of colours
  6.  
  7. tom = turtle.Turtle() # creates a turtle called tom
  8.  
  9. tom.speed(100)
  10.  
  11. for i in range(30):
  12.     tom.penup()
  13.  
  14.     # create random x and y position
  15.     xpos=random.randint(-450,450)
  16.     ypos=random.randint(-350,350)
  17.     size = random.randint(10,60) # sets a random size for tom
  18.     mycol = random.choice(cols)# picks a random colour from the list of colours called cols
  19.     tom.color(mycol) # makes tom the random colour
  20.     tom.goto(xpos,ypos)
  21.  
  22.     # draw a square
  23.     tom.pendown()
  24.     tom.fillcolor(mycol) # make the fill colour as mycol
  25.     tom.begin_fill() # start filling
  26.     for i in range(4): # loop 4 times
  27.         tom.fd(size) # make a line of length size
  28.         tom.rt(90) # turn 90 degress right
  29.     tom.end_fill()
  30.  
  31.  
  32. wn.exitonclick()
  33.  
Add Comment
Please, Sign In to add comment