#include #include #include #include #define PI 3.1415926 /* gcc g2_animation.c -lm -lg2 -lX11 */ /* simple animation trubasic style */ int n,m; float x,dt,t,y,sx,sy,X0,Y0; int main() { int d; /* a g2-object file handle */ dt=0.01; /* open a 400 by 400 pixel window */ /* lower left is (0,0), upper right is (400,400) */ d=g2_open_X11(400, 400); /* draw a bounding box */ g2_rectangle(d,4,4,396,396); /* draw in some coordinate axes */ g2_line(d, 200,4, 200, 396); /* y axis */ g2_line(d, 4, 200, 396, 200); /* x axis */ /* draw tick-marks */ for(n=1; n<20;n++){ g2_line(d,20*n,196,20*n,204); g2_line(d,196,20*n,204,20*n); } /* create a curve, but scale it */ g2_move(d,200,200); /* go to origin */ sx=396.0/(2.0*PI); /* horizontal and vertical scale factors */ sy=396.0/2.0; X0=0.0; Y0=0.0; for(n=0;n<628;n++){ /* create an x; 0 < x < 2PI */ t=(float)n*dt; /* create Lissojou data */ x=sin(3.0*t+PI/4.0); y=0.7*sin(5.0*t); /* map this into pixel interval from 0 to 400 */ g2_pen(d,1); /* draw in some coordinate axes */ g2_line(d, 200,4, 200, 396); /* y axis */ g2_line(d, 4, 200, 396, 200); /* x axis */ /* draw tick-marks */ for(m=1; m<20;m++){ g2_line(d,20*m,196,20*m,204); g2_line(d,196,20*m,204,20*m); } /* draw object as a circle */ g2_circle(d,sx*x+200.0,sy*y+200.0, 5.0); g2_rectangle(d,4,4,396,396); g2_string(d,10,350,"A Lissojou figure"); usleep(5000); g2_flush(d); /* erase the circle */ g2_pen(d,0); g2_filled_circle(d,sx*x+200.0,sy*y+200.0, 6.0); } /* wait until a character is entered, then exit */ getchar(); g2_close(d); return 0; }