/////////////////////////////////////////////////////////////////// // // graphics2.cpp // // Started in Pascal by Jeff Ondich on 1/25/95 // Last modified 1/18/00 // // 1. Try it. // 2. The "polygon[3] = 100" notation is something // you will meet soon (polygon itself is // called an "array"). For this program, // all you need to know is that polygon[0] // and polygon[1] are the (x,y) coordinates // of the first corner of the polygon, // polygon[2] and polygon[3] are the coordinates // of the second corner, etc. // 3. Identify which corner of the polygon has // which coordinates as listed in the source code. // 4. Try to redesign the polygon to be a triangle // or a rectangle. // 5. Change g2_polygon to g2_filled_polygon and // try the program again. // /////////////////////////////////////////////////////////////////// #include #include #include const int windowHeight = 600; const int windowWidth = 600; int main() { int window = g2_open_X11( windowWidth, windowHeight ); g2_set_background( window, g2_ink(window,1,1,1) ); cout << "Click in this terminal window and " << "hit return when you're done." << endl; double polygon[100]; polygon[0] = 200; polygon[1] = 100; polygon[2] = 400; polygon[3] = 100; polygon[4] = 500; polygon[5] = 200; polygon[6] = 400; polygon[7] = 300; polygon[8] = 200; polygon[9] = 200; int red_ink = g2_ink( window, 1, 0, 0 ); g2_pen( window, red_ink ); g2_polygon( window, 5, polygon ); cin.get(); g2_close(window); return( 0 ); }