/////////////////////////////////////////////////////////////////// // // graphics0.cpp // // Started in Pascal by Jeff Ondich on 1/25/95 // Last modified 5/19/98 // // // This program opens a graphics window, fills it with a black // background, and draws a red circle in the center. // // To compile this program, use the following command: // // g++ -o graphics0 graphics0.cpp -lg++ -lgraphics++ // // You will need to hit the Enter key to end the program. // // Try doing these things: // // 0. Compile and run the program as it is. // 1. Read the whole program to find out how it works. // 2. What happens if you remove the "cin.ignore()" at the // end of the main program? // 3. Modify the code to draw a tall and skinny graphics // window. Where does the circle get drawn when you // run your new version of the program? Why? // 4. Change the background color. Can you make it white? // 5. Make the circle green. // 6. After the cin.ignore() at the end of the main program, add // // setrgbcolor( 1, 0, 0 ); // flood(); // flushgraphics(); // cin.ignore(); // // What do you expect will happen? What does happen? // /////////////////////////////////////////////////////////////////// #include #include const int radius = 20; const int windowWidth = 600; const int windowHeight = 600; const int windowBottom = 100; const int windowLeft = 100; void StartGraphics( void ); /////////////////////////////////////////////////////////////////// // main program /////////////////////////////////////////////////////////////////// int main( void ) { StartGraphics(); // "RGB" stands for red-green-blue. The parameters for // setrgbcolor() can range in value from 0.0 to 1.0. All // zeros gives you no red, no green, and no blue. setrgbcolor( 1.0, 0.0, 0.0 ); circle( windowWidth / 2, windowHeight / 2, radius ); // When you're done with drawing a particular object, // you need to call flushgraphics(), or you won't see // anything. When you get to more complicated programs, // you can experiment leaving the flushgraphics() calls // out to see what happens. flushgraphics(); cin.ignore(); return( 0 ); } /////////////////////////////////////////////////////////////////// // StartGraphics initializes the graphics package // and opens a black window for drawing. /////////////////////////////////////////////////////////////////// void StartGraphics( void ) { // Call initializegraphics only once during the program, // before you do any other graphics initializegraphics(); // Open a window and flood it with a black background. createwindow( windowLeft, windowBottom, windowLeft + windowWidth, windowBottom + windowHeight ); setrgbcolor( 0.0, 0.0, 0.0 ); flood(); flushgraphics(); }