Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This program allows the user to draw a simple house in 5 clicks
- #by: Alexis Veras. CMP 230 Section B401 Problem set 4, program #4
- from graphics import *
- from math import *
- win = GraphWin('Simple house', 800, 600)#set window name, size
- p1 = win.getMouse()
- p2 = win.getMouse()
- #first click bottom left, second click top right, in order for door to draw properly
- rect = Rectangle(Point(p1.getX(), p1.getY()), Point(p2.getX(), p2.getY()))
- rect.setFill('pink')
- rect.draw(win)
- ldx= p1.getX() - p2.getX()
- ldy= p1.getY() - p1.getY()
- hwidth = sqrt(ldx**2 + ldy**2)#house width calc
- dwidth = hwidth/5#door width to 1/5 of house width
- p3 = win.getMouse()
- pd1 = Point(p3.getX() + (dwidth/2), p3.getY())
- pd2 = Point(pd1.getX(),p1.getY())
- dc1 = Point(p3.getX() - (dwidth/2), p3.getY())
- door = Rectangle(dc1,pd2)
- door.setFill('green')
- door.draw(win)
- wwidth = dwidth/2#window width to 1/2 of door
- p4 = win.getMouse()
- pd3 = Point(p4.getX() + (wwidth), p4.getY() + (wwidth))
- pd4 = Point(pd3.getX(),pd3.getY())
- wc1 = Point(p4.getX() - (wwidth/2), p4.getY()-(wwidth/2))
- wc2 = Point(pd4.getX() - (wwidth/2), pd4.getY() - (wwidth/2))
- window = Rectangle(wc1,wc2) #extremely stressful, can't set the window to center of click
- window.setFill('grey')
- window.draw(win)
- #ply= p2.getX(), p1.getY()
- p5 = win.getMouse()
- roof = Polygon(p5,p2,Point(p1.getX(), p2.getY()))
- roof.setFill('beige')
- roof.draw(win)
- input("Press <Enter> to quit")
- win.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement