TonyMo

my_shapes.py

Feb 23rd, 2021
693
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # House and random clouds
  2.  
  3. '''
  4. *   Create an Oval and call the randomize() method on it before calling the draw() method to display it.
  5. *    Create a drawing using rectangles, ovals, and triangles.
  6. '''
  7.  
  8. from shapes import Paper, Triangle, Rectangle, Oval
  9. from random import randint
  10.  
  11. ovalCount = 0
  12. paper = Paper()
  13.  
  14. # do an oval
  15. oval1 = Oval()  # static pink cloud at origin
  16. oval1.set_width(150)
  17. oval1.set_height(50)
  18. oval1.set_x(0) # = None
  19. oval1.set_y(0) # = None
  20. oval1.set_color("pink")
  21. oval1.draw()
  22.  
  23. # do lots of  ovals with random size, position, colour
  24. while ovalCount !=8:
  25.     oval2 = Oval()
  26.     oval2.set_width(50)
  27.     oval2.set_height(50)
  28.     oval2.set_x(randint(0,200))
  29.     oval2.set_y(randint(0,200))
  30.     oval2.set_color(randint(0,8))
  31.     oval2.randomize()
  32.     oval2.draw()
  33.     ovalCount +=1
  34.  
  35. # static oval sun
  36. sun = Oval()
  37. sun.set_width(30)
  38. sun.set_height(30)
  39. sun.set_x(400)
  40. sun.set_y(150)
  41. sun.set_color("gold")
  42. sun.draw()
  43.  
  44. # do a couple of different rectangles
  45. rect1 = Rectangle() # white house
  46. rect1.set_width(200)
  47. rect1.set_height(100)
  48. rect1.set_color("white")
  49. rect1.draw()
  50.  
  51. rect2 = Rectangle() # green door
  52. rect2.set_width(40)
  53. rect2.set_height(80)
  54. rect2.set_color("green")
  55. rect2.set_x(355)
  56. rect2.set_y(295)
  57. rect2.draw()
  58.  
  59. #red roof
  60. tri = Triangle(250,275, 500,275, 375,200)
  61. tri.set_color('red')
  62. tri.draw()
  63.  
  64. print("House in the sun with random clouds")
  65.  
  66. paper.display()
RAW Paste Data