int Gi_wait_click(int p[2]) { int sig ; G_display_image(); do { sig = Gi_events(p) ; } while (sig != -3) ; return sig ; }
int G_wait_key() { int p[2] ; int sig ; G_display_image(); do { sig = Gi_events(p) ; } while (sig < 0) ; return sig ; }
void draw() { G_rgb(.1, .1, .1); G_clear(); draw_object3ds(objs, num_objs, fov, light_pos, lm); //printf("draw\n"); char fovstring[128]; sprintf(fovstring, "Fov: %.3f rad", fov); char camerastring[128]; sprintf(camerastring, "Camera: x:0 y:0 z:%f", 0.0); G_rgb(1, 1, 1); G_draw_string(fovstring, 0, 580); G_draw_string(camerastring, 0, 560); G_display_image(); }
int test01() { int sig = 0 ; int p[2], x,y, i ; double degrees ; swidth = 500 ; sheight = 600 ; if(! G_init_graphics (swidth, sheight)) return -1; Draw(0); G_display_image() ; i = 0 ; while(sig != 'q') { sig = Gi_events(p) ; x = p[0] ; y = p[1] ; degrees = sqrt(x*x + y*y) ; printf("i = %d sig = %d x = %d y = %d\n",i,sig,x,y) ; i++ ; if (sig == -4) { // window resize swidth = x ; sheight = y ; } Draw(degrees); G_display_image() ; } G_close(); return 1; }
int main() { double j ; char q ; G_init_graphics(601, 601) ; // the original design was for a 400x400 // window and the object is centered on 200,200 // so we recenter it and make it larger translate(-200, -200) ; scale(2.0) ; translate(300, 300) ; j = 0 ; while (j < 100) { G_rgb(0,0,0) ; G_clear() ; G_rgb(0, 0.5, 1) ; G_fill_polygon(x,y,n) ; G_rgb(1, 1, 0) ; G_polygon(x,y,n) ; // q = G_wait_key() ; G_display_image() ; usleep(25000) ; // microseconds translate(-300, -300) ; scale(0.95) ; rotate(4) ; translate(300, 300) ; j=j+1 ; } G_rgb(1,0,0) ; G_fill_circle(300,300, 50) ; q = G_wait_key() ; }
int main() { G_init_graphics(600, 600); for (int j = 0; j < 200; ++j) { { usleep(20000); G_rgb(drand48(),drand48(),drand48()); G_clear(); G_rgb(drand48(),drand48(),drand48()); G_fill_polygon(x,y,n) ; G_display_image(); // clearing, choosing random colors } translate(-300, -300) ; scale(0.98, 0.98) ; rotate(3.0) ; translate(300, 300) ; } int close = G_wait_key() ; }
int test02(int numreps, int sleepflag, int microseconds) { double degrees ; int i ; swidth = 500 ; sheight = 600 ; if(! G_init_graphics (swidth, sheight)) return -1; for (i = 0 ; i < numreps ; i++) { degrees = i ; Draw(degrees); G_display_image() ; if (sleepflag) usleep(microseconds) ; } G_close(); return 1; }
int main() { double pwidth, pheight, bwidth ; double angle,hx,hy,mx,my,sx,sy ; double hours,minutes,seconds ; double x,y,nx,ny,digit ; int theta ; //INTERESTING that this MUST be int to avoid flicker-WHY? double oldhourtheta,oldminutetheta,oldsecondtheta ; char text[3] ; double hms[3] ; // hours,minutes,seconds G_init_graphics(600,600) ; G_rgb (1,1,1) ; G_fill_rectangle (0,0, 600,600) ; // outer circle of the clock face G_rgb (1,0,0) ; // red theta = 0 ; // degrees x = 225*cos(theta*M_PI/180) + 300 ; y = 225*sin(theta*M_PI/180) + 300 ; while (theta <= 360) { theta = theta + 1 ; nx = 225*cos(theta*M_PI/180) + 300 ; ny = 225*sin(theta*M_PI/180) + 300 ; G_line(x,y,nx,ny) ; x = nx ; y = ny ; } G_display_image() ; // digits on the clock face G_rgb (0,0,0) ; // black theta = 90 ; // degrees digit = 0 ; while (theta > -270) { theta = theta - 30 ; digit = digit + 1 ; nx = 200*cos(theta*M_PI/180) + 300 ; ny = 200*sin(theta*M_PI/180) + 300 ; if (digit >= 10) { text[0] = '1' ; text[1] = '0' + digit - 10 ; text[2] = '\0' ; } else { text[0] = '0' + digit ; text[1] = '\0' ; } G_draw_string(text,nx-5,ny-5) ; } G_display_image() ; oldsecondtheta = oldminutetheta = oldhourtheta = -10000000 ; sx = sy = mx = my = hx = hy = 300 ; while (0 < 1) { /* watch out for SLIGHT FLAW : if one of the hands overlays another, then if it is erased, you'll erase the other as well...this should fix that...we erase them all and redraw them all */ get_timeD (hms) ; hours = hms[0] ; minutes = hms[1] ; seconds = hms[2] ; // set the second hand theta = 90 - 6*seconds ; if (theta != oldsecondtheta) { G_rgb (1,1,1) ; // white G_line(300,300,sx,sy) ; G_line(300,300,mx,my) ; G_line(300,300,hx,hy) ; angle = theta*M_PI/180 ; sx = 175*cos(angle) + 300 ; sy = 175*sin(angle) + 300 ; G_rgb (1,0,0) ; // red G_line(300,300,sx,sy) ; G_line(300,300,mx,my) ; G_line(300,300,hx,hy) ; G_display_image() ; oldsecondtheta = theta ; } // set the minute hand theta = 90 - 6*(minutes + seconds/60.0) ; if (theta != oldminutetheta) { G_rgb (1,1,1) ; // white G_line(300,300,sx,sy) ; G_line(300,300,mx,my) ; G_line(300,300,hx,hy) ; angle = theta*M_PI/180 ; mx = 140*cos(angle) + 300 ; my = 140*sin(angle) + 300 ; G_rgb (1,0,0) ; // red G_line(300,300,sx,sy) ; G_line(300,300,mx,my) ; G_line(300,300,hx,hy) ; G_display_image() ; oldminutetheta = theta ; } // set the hour hand theta = 90 - 30*(hours + minutes/60.0 + seconds/3600.0) ; if (theta != oldhourtheta) { G_rgb (1,1,1) ; // white G_line(300,300,sx,sy) ; G_line(300,300,mx,my) ; G_line(300,300,hx,hy) ; angle = theta*M_PI/180 ; hx = 75*cos(angle) + 300 ; hy = 75*sin(angle) + 300 ; G_rgb (1,0,0) ; // red G_line(300,300,sx,sy) ; G_line(300,300,mx,my) ; G_line(300,300,hx,hy) ; G_display_image() ; oldhourtheta = theta ; } } // end while (0 < 1) }
int main() { // analog clock using double buffering...simpler double hours,minutes,seconds,x,y,nx,ny,theta,digit ; double hx,hy,mx,my,sx,sy,angle ; double oldhourtheta,oldminutetheta,oldsecondtheta ; char text[3] ; double hms[3] ; double xx[100],yy[100] ; int num ; G_init_graphics(600,600) ; while (0 < 1) { // blank the window G_rgb(0.3, 0.3, 0.3) ; G_clear() ; // outer circle of the clock face G_rgb(0,0,1) ; G_fill_circle(300,300,230) ; G_rgb (1,0.5,0) ; G_fill_circle(300,300,220) ; // digits on the clock face G_rgb (0,0,0) ; theta = 90 ; // degrees digit = 0 ; while (theta > -270) { theta = theta - 30 ; digit = digit + 1 ; nx = 200*cos(theta*M_PI/180) + 300 ; ny = 200*sin(theta*M_PI/180) + 300 ; if (digit >= 10) { text[0] = '1' ; text[1] = '0' + digit - 10 ; text[2] = '\0' ; } else { text[0] = '0' + digit ; text[1] = '\0' ; } G_draw_string(text,nx-5,ny-5) ; } // get_timeD(hms) ; // hours = hms[0] ; // minutes = hms[1] ; // seconds = hms[2] ; printf("enter hours minutes seconds") ; scanf("%lf %lf %lf",&hours,&minutes,&seconds) ; G_rgb (0,0,0) ; // set the second hand theta = 90 - 6*seconds ; angle = theta*M_PI/180 ; sx = 175*cos(angle) + 300 ; sy = 175*sin(angle) + 300 ; // G_line(300,300,sx,sy) ; num = make_arrow (300,300, sx,sy, 3.0, xx,yy) ; G_fill_polygon(xx,yy,num) ; // set the minute hand theta = 90 - 6*(minutes + seconds/60.0) ; angle = theta*M_PI/180 ; mx = 140*cos(angle) + 300 ; my = 140*sin(angle) + 300 ; // G_line(300,300,mx,my) ; num = make_arrow (300,300, mx,my, 3.0, xx,yy) ; G_fill_polygon(xx,yy,num) ; // set the hour hand theta = 90 - 30*(hours + minutes/60.0 + seconds/3600.0) ; angle = theta*M_PI/180 ; hx = 75*cos(angle) + 300 ; hy = 75*sin(angle) + 300 ; // G_line(300,300,hx,hy) ; num = make_arrow (300,300, hx,hy, 3.0, xx,yy) ; G_fill_polygon(xx,yy,num) ; G_rgb(0,0,0) ; G_fill_circle(300,300,12) ; G_display_image() ; break ; } // end while (0 < 1) G_save_image_to_file("clock.xwd") ; }