Five-Click House

We are continuing to become familiar with the GUI capabilities of the graphics.py module.  Today, our discussion focused on user interaction with the mouse. We have learned to intercept the mouse click event and associate the click with a location of a point in the window.  This exercise with further explore that concept.

Your task is described here:

You are to write a program named yourname-five-click-house.py that allows the user to draw a simple house using five mouse-clicks as described below.

five-click-house-notext

  • The first two clicks will be the opposite corners of the rectangular frame of the house.
  • The third click will indicate the center of the top edge of a rectangular door. The door should have a total width that is 1/5 of the width of the house frame. The sides of the door should extend from the corners of the top down to the bottom of the frame.
  • The fourth click will indicate the center of a square window. The window is half as wide as the door.
  • The last click will indicate the peak of the roof. The edges of the roof will extend from the point at the peak to the corners of the top edge of the house frame.

 

When finished, the house should resemble the following picture:

five-click-house-color

Keep in mind that you will have to do some math in your program. For example, to make the door 1/5 of the width of the house, you will have to make a variable called houseWidth, which will equal the difference of the x-coordinates of the house divided by 5.0.  To locate the upper right corner of the door, you’ll have to subtract half of the door width from the x-coordinate of the third click, and so on…

When you have completed the program, make sure you have included comments at the beginning of the code with your name, the file name and the date.

The file must be named yourname-five-click-house.py and submitted using this submission link.