HOME

Danah and Andrea were sitting around trying to decide where to hold their first wild party of the summer. For some reason, they couldn't convice their housemates to host it. So they decided to build a house to hold the party in. And rather than pay an exorbitant fee for an architect's services, they decided to ask the students to lend a hand...

Your mission is to draw a comfy home for the party. The house will be drawn using Quickdraw. Your home must possess the following features:

We are going to write the code together. When you open up the project, you will find that we have written some of the code for you. At the end of this document, you'll find a printout of the code that we are giving you an dthat you'll find initially in your project.

What is difficult about this program?

This program must be able to generate homes in a variety of dimensions. House dimensions are measured in tiles, which are squares of fixed size. The symbolic constant TILE_SIZE specifies the edge length of a tile to be 50 pixels. The constants HOUSE_HEIGHT and HOUSE_WIDTH specify the house dimensions, measured in tiles. Each tile must hold one window or one door. Your program should eb able to draw any house with height and width of 3 or more tiles, up to the maximum size of the Quickdraw window. We will test your code by altering HOUSE_HEIGHT and HOUSE_WIDTH, running your code several times. So you should do the same to make sure it works correctly. Therefore, if youincrease HOUSE_WIDTH from 5 to 6, your house should have one additional window per floor. HOUSE_HEIGHT and HOUSE_WIDTH are the only two constants which we will change. TILE_SIZE, WINDOW_SIZE, and any other constants you define will remain... well, constant.

Parameters

When you are writing your functions, you should try and use parameters to make them very general. Then you can re-use the same function to do a lot of work for you. For instance, the window-drawing function takes the x and y locations of the windwo as parameters, and draws the window at the correct location. Think carefully about your design before you start coding.

HINT: The first floor is different from the others and needs its own function, which we have provided. But the second, third, and all other floors appear identical. Can you take advantage of this fact?

OtherThings You Should Know

When you are ready to start HOME, go to a shell and type:
install Home
When you first open the stencil, you will find that a few of the lines "commented out"; these lines are surrounded by comment braces /* */, which tell the compiler to ignore them. These lines call functions that you need to write. Be careful to make sure that your functions will accept the parameters listed in the commented out code.

A Word on GUIs

This program also introduces you to GUIs (Graphical User Interfaces). You have used a GUI if you have used a Windows or Macintosh machine, or if you did Fractal on the Suns.

The GUI for Home is not complicated. All we are asking you to do is add a quit button, so that the program will only quit when the user clicks the button. The Quickdraw guide deals thoroughly with the topic of implementing a button. Read it carefully! The Quickdraw guide is your friend and mine!

Extra Stuff!

If you have time and feel ambitious, add more features, like a chimney or garagem window shutters or a picket fence. Be artistic! Add more buttons to let the user specify the size of the house.

The Stencil

On the next few pages is the code that we give you to start the program. Please use it as is and do not change it without talking to Danah or Andrea. If you think you have come up with a better way to do the program, the feel free to discuss your ideas with Danah or Andrea and they will give you the go ahead to do it your way.

Remember, you must remove the brackets and asterisks on the commented out lines and write the necessary functions. If you are confused or have any questions, please feel free to ask. Have fun!




/***********************************************************************
 * Name: Put Your Name Here                                             
 * Account: Put Your Account Number Here                                
 * Program: Home
 *
 * Home draws a house with three or more floors, two doors, doorknobs,
 * windows, and a roof. 
 ***********************************************************************/

/* NOTE: This program has lines commented out.  They are all lines that 
  invoke functions that YOU need to write!  These lines begin with a  
  bracket and two asterisks and ends with two asterisks and a bracket. 
  Once you have written the invoked function, delete those six bracket
  and asterisk characters, and then delete this comment...If you have  
  any questions, please see a TA.                                     */

#include "genlib.h"
#include "quickdraw.h"

#define HOUSE_HEIGHT 5   /* Height of the house, in tiles */
#define HOUSE_WIDTH 5    /* Width of the house, in tiles */
#define WINDOW_SIZE 30   /* Edge length of window */
#define BORDER 100       /* White space around house */
#define TILE_SIZE 50     /* Edge length of tile */

/***********************************************************************
 * function: HouseFrame                                               
 *
 * Draws the the main body of the house                                
 * parameters: none
 * returns: none
 ***********************************************************************/

void HouseFrame() {
    int left,          /* the left boundary of the house */
        top,           /* the top boundary of the house */
        right,         /* the right boundary of the house */
        bottom;        /* the bottom boundary of the house */
    Rect houseRect;    /* the rectangle representing the house */

    left = BORDER;
    top = BORDER;
    right = left + HOUSE_WIDTH * TILE_SIZE;
    bottom = top + HOUSE_HEIGHT * TILE_SIZE;
    SetRect(houseRect, left, top, right, bottom);

    /* draw a blue house; you may change the color */

    SetColor(blueColor);
    PaintRect(houseRect);

    /* draw a black boundary around the house */
    SetColor(blackColor);
    FrameRect(houseRect);
}

/***********************************************************************
 *  function: DrawWindow                                                   
 *
 * Draws a window with cross-bars                                      
 * parameters: xTile, yTile - x and y location of window, in tiles
 * returns: none
 ***********************************************************************/

void DrawWindow(int xTile,              /* window's x-location, in tiles */
            int yTile) {            /* window's y-location, in tiles */
    int left,                 /* left boundary of window */
        top,                  /* top boundary of window */
        right,                /* right boundary of window */
        bottom;               /* bottom boundary of window */
    Rect windowRect;          /* defines dimensions of window */

    /* sets coordinates by :
     starting at the border of the house,
     moving over to the tile on which to draw the window, and
     moving to the edge of the window such that the window is centered */

    left = BORDER + (xTile - 1) * TILE_SIZE + ((TILE_SIZE - WINDOW_SIZE) / 2);
    top = BORDER + (HOUSE_HEIGHT - yTile) * TILE_SIZE +
        ((TILE_SIZE - WINDOW_SIZE) / 2);
    right = left + WINDOW_SIZE;
    bottom = top + WINDOW_SIZE;
    SetRect(windowRect, left, top, right, bottom);

    /* draw window box now that the coordinates are set */
    SetColor(whiteColor);
    PaintRect(windowRect);

    /* draw black boundary for window */
    SetColor(blackColor);
    FrameRect(windowRect);

    /* divide the window into four square window panes */
    /* HINT: Try using MoveTo and LineTo -- read the QuickDraw Guide */
    /**   YOUR CODE HERE   **/
}

/***********************************************************************
 * function:  DrawDoor
 *
 * Draws a Door with a doorknob.
 * parameters:
 * returns:
 ***********************************************************************/






/***********************************************************************
 * function: FirstFloor                                               
 *
 * Draws the first floor of the home                                   
 * parameters: none
 * returns: none
 ***********************************************************************/

void FirstFloor() {
    int windowCounter;        /* loop variable for drawing windows */

    /* Draw the front door, don't forget the doorknob. */
    /**    DrawDoor(1,1);    **/

    /* Draw first-floor windows */
    for(windowCounter = 2; windowCounter < HOUSE_WIDTH; windowCounter++)
        DrawWindow(windowCounter,1);

    /* Draw the back door, don't forget doorknob. */
    /**    DrawDoor(HOUSE_WIDTH, 1);   **/
}

/***********************************************************************
 * function: NextFloors                                               
 *
 * Starts drawing the other floors of the house  
 * parameters:
 * returns:
 ***********************************************************************/






/***********************************************************************
 * function: Roof                                               
 *
 * Finishes the house by drawing the Roof. 
 * parameters:
 * returns:
 ***********************************************************************/







/***********************************************************************
 * function: DrawQuitButton
 *
 * Draw a quit button on the screen. Hint: make your own constants above
 * to define where the quit button appears.
 ***********************************************************************/






/***********************************************************************
 * function: main
 *
 * main() controls the program.  So far, it initializes the
 * quickdraw window, and calls the calls the draw functions for the   
 * HouseFrame and the FirstFloor.                                      
 ***********************************************************************/

void main() {
    int qDrawWidth,              /* width of quickdraw window */
        qDrawHeight;             /* height of quickraw window */

   qDrawWidth = 2 * BORDER + HOUSE_WIDTH * TILE_SIZE;
   qDrawHeight = 2 * BORDER + HOUSE_HEIGHT * TILE_SIZE;
   InitDraw(qDrawWidth, qDrawHeight);
   HouseFrame();
   FirstFloor();
   /**  NextFloors()  **/
   /**  Roof()   **/

   /* Right now, we just quit after one click. You should modify this
    * code to quit only when the user clicks in the quit button.
    */
   while(!Button()) ;
   QuitDraw();
}


HOME