Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import turtle, random
- wn = turtle.Screen()
- cols = ["red","yellow","blue","black","pink", "green", "cyan"] # list of colours
- tom = turtle.Turtle() # creates a turtle called tom
- tom.speed(100)
- for i in range(30):
- tom.penup()
- # create random x and y position
- xpos=random.randint(-450,450)
- ypos=random.randint(-350,350)
- size = random.randint(10,60) # sets a random size for tom
- mycol = random.choice(cols)# picks a random colour from the list of colours called cols
- tom.color(mycol) # makes tom the random colour
- tom.goto(xpos,ypos)
- # draw a square
- tom.pendown()
- tom.fillcolor(mycol) # make the fill colour as mycol
- tom.begin_fill() # start filling
- for i in range(4): # loop 4 times
- tom.fd(size) # make a line of length size
- tom.rt(90) # turn 90 degress right
- tom.end_fill()
- wn.exitonclick()
Add Comment
Please, Sign In to add comment