/** * This file contains a simplified version of the House Demo from the * CMU Graphics Package. The CMU Graphics Library was written * at the Carnegie Mellon University School of Computer Science and * is available from Mark Stehlik's Advanced Placement web page: * http://www.cs.cmu.edu/~mjs/ * */ #include #include "CMUgraphicsLib\CMUgraphics.h" #include "waitnclear.h" int main() { // Create a new window 600 by 440 in size window myWindow(600, 440, 5, 5); // window for graphics // Change the window title to something different myWindow.ChangeTitle("CS 420: CMU Graphics Package Demo"); // Don't make us click on an empty window at the end myWindow.SetWaitClose(false); // -- HOUSE DEMO -- // House location: coordinates of upper-left corner // of house body (not including roof) const int HOUSE_LEFT = 100; // X-coord of left wall const int HOUSE_TOP = 150; // Y-coord of house body top // House, door, window dimensions const int HOUSE_WIDTH = 400; const int HOUSE_HEIGHT = 200; const int DOOR_WIDTH = 30; const int DOOR_HEIGHT = 50; const int WINDOW_WIDTH = 50; const int WINDOW_HEIGHT = 70; // We can derive the x-coordinate of the right wall, // the x-coordinate of the middle of the house, // and the y-coordinate of the bottom of the house. int HOUSE_RIGHT = HOUSE_LEFT + HOUSE_WIDTH; int HOUSE_MID = HOUSE_LEFT + HOUSE_WIDTH/2; int HOUSE_BOTTOM = HOUSE_TOP + HOUSE_HEIGHT; // House body: Draw a FILLED rectangle in brown without // a border myWindow.SetPen(BROWN, 0); myWindow.SetBrush(BROWN); myWindow.DrawRectangle(HOUSE_LEFT, HOUSE_TOP, HOUSE_RIGHT, HOUSE_BOTTOM, FILLED); // Roof: Draw two lines in black from the top-left // and top-right of the house body to the peak. // The x-coord of the peak is HOUSE_MID; // the y-coord is HOUSE_TOP - HOUSE_HEIGHT/2. int peak_y = HOUSE_TOP - HOUSE_HEIGHT/2; myWindow.SetPen(BLACK); myWindow.DrawLine(HOUSE_LEFT, HOUSE_TOP, HOUSE_MID, peak_y); myWindow.DrawLine(HOUSE_RIGHT, HOUSE_TOP, HOUSE_MID, peak_y); // Door: Draw a FILLED rectangle in brown without // a border, centered left-to-right myWindow.SetPen(BLACK); myWindow.SetBrush(BLACK); myWindow.DrawRectangle(HOUSE_MID - DOOR_WIDTH/2, HOUSE_BOTTOM - DOOR_HEIGHT, HOUSE_MID + DOOR_WIDTH/2, HOUSE_BOTTOM, FILLED); // Windows: Draw 2 windows, one on each side of the door, // evenly spaced between the door and the side of the // house. Evenly space the tops of the windows between // the top and bottom of the house body. Each window is // a FILLED rectangle in white with a black 1 pixel // border and two black lines to make 4 panes. // Window 1: int w_ul_x = HOUSE_LEFT + HOUSE_WIDTH/4 - WINDOW_WIDTH/2; int w_ul_y = HOUSE_TOP + HOUSE_HEIGHT/2 - WINDOW_HEIGHT/2; int w_mid_width = w_ul_x + WINDOW_WIDTH/2; int w_mid_height = w_ul_y + WINDOW_HEIGHT/2; myWindow.SetPen(BLACK, 1); myWindow.SetBrush(WHITE); myWindow.DrawRectangle(w_ul_x, w_ul_y, w_ul_x + WINDOW_WIDTH, w_ul_y + WINDOW_HEIGHT, FILLED); myWindow.DrawLine(w_ul_x, w_mid_height, w_ul_x + WINDOW_WIDTH, w_mid_height); myWindow.DrawLine(w_mid_width, w_ul_y, w_mid_width, w_ul_y + WINDOW_HEIGHT); // Window 2: w_ul_x = HOUSE_LEFT + 3*HOUSE_WIDTH/4 - WINDOW_WIDTH/2; w_mid_width = w_ul_x + WINDOW_WIDTH/2; myWindow.DrawRectangle(w_ul_x, w_ul_y, w_ul_x + WINDOW_WIDTH, w_ul_y + WINDOW_HEIGHT, FILLED); myWindow.DrawLine(w_ul_x, w_mid_height, w_ul_x + WINDOW_WIDTH, w_mid_height); myWindow.DrawLine(w_mid_width, w_ul_y, w_mid_width, w_ul_y + WINDOW_HEIGHT); // Wait for a mouse click and clear the window WaitNClear(myWindow); return 0; }