http://www.accu.org/bookreviews/public/reviews/0sb/graphics.htm
#include
#include
#include
const int HEIGHT= 200;
const int WIDTH = 200;
int main(void)
{
int window;
/* Open a window on screen. Keep it's device ID */
window = g2_open_X11(WIDTH, HEIGHT);
/* Let's define some colors now */
int black_ink = g2_ink(window,0,0,0);
int blue_ink = g2_ink(window,0,0,1);
int yellow_ink = g2_ink(window, 0.7,0.7,0);
int white_ink = g2_ink(window,1,1,1);
/* clear screen */
g2_clear(window);
g2_set_background(window, black_ink);
/* Give it a face */
g2_pen(window,yellow_ink);
g2_filled_circle(window,100,100,50);
/* and eyes */
g2_pen(window,white_ink);
g2_filled_ellipse(window,85,115,9,6);
g2_filled_ellipse(window,115,115,9,6);
g2_pen(window,blue_ink);
g2_filled_circle(window,83,115,5);
g2_filled_circle(window, 113,115,5);
g2_pen(window,black_ink);
g2_filled_circle(window,83,115,3);
g2_filled_circle(window,113,115,3);
/* and a nose */
g2_pen(window,black_ink);
g2_line(window,102,105,95,88);
g2_line(window,95,88,102,88);
/* and a mouth */
g2_line(window,90,80,110,80);
cin.get();
g2_close(window);
return 0;
}
Enter this in an Edit window and save it just as you would any other C++ program. (Remember to end the file name with .cpp to distinguish it as a C++ source code.) This example displays the picture to the right on the screen. There are a few things to note about this progam:
* The placement of the necessary lines to open up the graphics library,
* The last line, cin.get(), which makes the program wait for a return character from the keyboard.