{---------------------------------------------------------------------- graphics0.p Started by Jeff Ondich on 1/25/95 Last modified 10/11/96 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: gpc -o myProgram myProgram.p -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 "readln" 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 readln at the end of the main program, add setrgbcolor( 1, 0, 0 ); flood; flushgraphics; readln What do you expect will happen? What does happen? ----------------------------------------------------------------------} #include program OneCircle(input,output); import graphics; const radius = 20; windowWidth = 600; windowHeight = 600; windowBottom = 100; windowLeft = 100; {---------------------------------------------------------------------- StartGraphics initializes the graphics package and opens a black window for drawing. ----------------------------------------------------------------------} procedure StartGraphics; begin { 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 end; {---------------------------------------------------------------------- main program ----------------------------------------------------------------------} begin 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 div 2, windowHeight div 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; { This is here so the program won't end until the user hits the return key. Otherwise, the program will end and the window will just disappear as soon as the drawing is done. } readln end.