Advertisement
ceiszele

modern art

Dec 5th, 2019
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #modern art
  2. from turtle import *
  3. from random import *
  4. colormode(255)
  5.  
  6. #create random colours by generating a random integer for each color element
  7. def randomcolor():
  8. red = randint(0, 255)
  9. green = randint(0, 255)
  10. blue = randint(0, 255)
  11. color(red, green, blue)
  12.  
  13. #use a random number to determine the where the shape should be placed
  14. def randomplace():
  15. penup()
  16. n = 200
  17. x = randint(-n, n)
  18. y = randint(-n, n)
  19. goto(x,y)
  20. pendown()
  21.  
  22. #draw a rectangle passing in the speed and calling the color and place functions
  23. def drawrectangle(spd):
  24. speed(spd)
  25. randomcolor()
  26. randomplace()
  27. length=randint(10,100)
  28. height=randint(10,100)
  29. #color in the rectangle
  30. begin_fill()
  31. forward(length)
  32. right(90)
  33. forward(height)
  34. right(90)
  35. forward(length)
  36. right(90)
  37. forward(height)
  38. right(90)
  39. end_fill()
  40. #using the dot function to create circles of diferent sizes and colors
  41. def draw_circle(spd):
  42. speed(spd)
  43. randomcolor()
  44. randomplace()
  45. r = randint(1,100)
  46. dot(r*2)
  47.  
  48. #function for looping through the rectangles and circles
  49. def modern_art(n, spd):
  50. for i in range(n):
  51. drawrectangle(spd)
  52. print(spd,n)
  53. # randomly generate the number of loops of circles based on the number of rectangles.
  54. n = randint(1,4) * n
  55. for i in range(n):
  56. draw_circle(spd)
  57. print(spd, n)
  58.  
  59. #call the function passing the number of iterations and the speed.
  60. modern_art(10, 9)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement