/////////////////////////////////////////////////////////////////// // // graphics0.cpp // // Started in Pascal by Jeff Ondich on 1/25/95 // Last modified 1/17/00 // // // 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 -L/usr/X11R6/lib -lm -lX11 -lgd -lg2 // // 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.get()" 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. // /////////////////////////////////////////////////////////////////// #include #include #include const int windowHeight = 500; const int windowWidth = 500; const int circleRadius = 100; int main() { ///////////////////////////////////// // I. Open a graphics window on // screen. Save the return value // of g2_open_X11. This return value // will enable you to tell the // drawing operations which window // you want to draw in. ///////////////////////////////////// int window = g2_open_X11( windowWidth, windowHeight ); ///////////////////////////////////// // II. Define some colors. To do // color graphics, you specify // a color through an integer // constructed by the g2_ink // function. The parameters of // g2_ink include three real numbers // between 0.0 and 1.0, representing // the amount of red, green, and // blue in the color. So (0,0,0) // means no color (black), (1,0,1) // means a shade of purple, and // (.5,0,.5) is darker purple, etc. ///////////////////////////////////// int black_ink = g2_ink( window, 0, 0, 0 ); int red_ink = g2_ink( window, 1, 0, 0 ); ///////////////////////////////////// // III. Clear the window, giving it // a background the color of your // choosing. ///////////////////////////////////// g2_set_background( window, black_ink ); ///////////////////////////////////// // IV. Draw. ///////////////////////////////////// g2_pen( window, red_ink ); g2_filled_circle( window, windowWidth / 2, windowHeight / 2, circleRadius ); ///////////////////////////////////// // V. Wait for user input before // closing the window and finishing // the program. ///////////////////////////////////// cout << "Click in this terminal window and " << "hit return when you're done." << endl; cin.get(); ///////////////////////////////////// // VI. Clean up after yourself by // closing the graphics window. ///////////////////////////////////// g2_close(window); return( 0 ); }