Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.44 KB | None | 0 0
  1. #This program allows the user to draw a simple house in 5 clicks
  2. #by: Alexis Veras. CMP 230 Section B401  Problem set 4, program #4
  3.  
  4. from graphics import *
  5. from math import *
  6. win = GraphWin('Simple house', 800, 600)#set window name, size
  7.  
  8. p1 = win.getMouse()
  9. p2 = win.getMouse()
  10.  
  11. #first click bottom left, second click top right, in order for door to draw properly
  12. rect = Rectangle(Point(p1.getX(), p1.getY()), Point(p2.getX(), p2.getY()))
  13. rect.setFill('pink')
  14. rect.draw(win)
  15.  
  16. ldx= p1.getX() - p2.getX()
  17. ldy= p1.getY() - p1.getY()
  18. hwidth = sqrt(ldx**2 + ldy**2)#house width calc
  19. dwidth = hwidth/5#door width to 1/5 of house width
  20.  
  21. p3 = win.getMouse()
  22. pd1 = Point(p3.getX() + (dwidth/2), p3.getY())
  23. pd2 = Point(pd1.getX(),p1.getY())
  24. dc1 = Point(p3.getX() - (dwidth/2), p3.getY())
  25.  
  26. door = Rectangle(dc1,pd2)
  27. door.setFill('green')
  28. door.draw(win)
  29.  
  30. wwidth = dwidth/2#window width to 1/2 of door
  31.  
  32. p4 = win.getMouse()
  33. pd3 = Point(p4.getX() + (wwidth), p4.getY() + (wwidth))
  34. pd4 = Point(pd3.getX(),pd3.getY())
  35. wc1 = Point(p4.getX() - (wwidth/2), p4.getY()-(wwidth/2))
  36. wc2 = Point(pd4.getX() - (wwidth/2), pd4.getY() - (wwidth/2))
  37.  
  38. window = Rectangle(wc1,wc2) #extremely stressful, can't set the window to center of click
  39. window.setFill('grey')
  40. window.draw(win)
  41.  
  42. #ply= p2.getX(), p1.getY()
  43. p5 = win.getMouse()
  44. roof = Polygon(p5,p2,Point(p1.getX(), p2.getY()))
  45. roof.setFill('beige')
  46. roof.draw(win)
  47.  
  48. input("Press <Enter> to quit")
  49. win.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement