AberdeenAngus

turtle rectangles

Aug 28th, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. """
  2. draw rectangles of different sizes and shapes
  3. """
  4. from turtle import *
  5. from random import *
  6.  
  7. colormode(255)
  8.  
  9. def randomColor():
  10. red = (randint(0,255))
  11. green = (randint(0,255))
  12. blue = (randint(0,255))
  13. color(red, green, blue)
  14.  
  15. def randomPlace():
  16. penup()
  17. x = (randint(-100, 100))
  18. y = (randint(-100, 100))
  19. goto(x,y)
  20. pendown()
  21.  
  22. #random direction
  23. def randomHeading():
  24. dir = (randint(0,360))
  25. setheading(dir)
  26.  
  27. def drawRectangle():
  28. randomColor()
  29. randomPlace()
  30. hideturtle()
  31. length = randint(1,100)
  32. height= randint(1,100)
  33. begin_fill()
  34. forward(length)
  35. right(90)
  36. forward(height)
  37. right(90)
  38. forward(length)
  39. right(90)
  40. forward(height)
  41. right(90)
  42. end_fill()
  43.  
  44. for i in range(20):
  45. drawRectangle()
Advertisement
Add Comment
Please, Sign In to add comment