int main() { double swidth, sheight ; double i,x,y ; double z[2] ; swidth = 600 ; sheight = 600 ; G_init_graphics(swidth, sheight); i = 0; while(i<600){ G_rgb(0,0,1) ; G_line (i, 0, i, 599) ; G_line(0,i,599,i) ; i=i+10 ; } i=0; while(i<10){ G_wait_click(z) ; x = z[0] ; y = z[1] ; x=x-fmod(x,10); y=y-fmod(y,10); G_fill_rectangle(x, y ,10,10); i++; } G_wait_key(); }
int main(){ int x; G_init_graphics(600,600); int i; char prefix[100], filename[100]; strncpy(prefix, "tetrahedron", 100); scanf("%s", textureName); //tetrahedron0000 //14 for(i=0; i < 73; i++){ printf("%d\n", i); init_scene(i); sprintf(filename, "%s%04d", prefix, i); filename[15] = '.'; filename[16] = 'x'; filename[17] = 'w'; filename[18] = 'd'; G_save_image_to_file(filename); G_wait_key(); G_rgb(1,1,1); G_clear(); } //main->init scene->draw }
int main() { double xp[1000],yp[1000] ; int n,q ; double P[2] ; swidth = 700 ; sheight = 700 ; G_init_graphics(swidth, sheight) ; G_rgb(0,0,0) ; G_clear() ; G_rgb(1,0,0) ; n = click_and_save(xp,yp) ; G_rgb(0,1,0) ; G_fill_polygon(xp,yp,n) ; while(1==1){ G_wait_click(P) ; if(P[1] < 40){ break; } int r = in_out(xp,yp,n,P); if(r==1){ G_rgb(1,0,0); }else{ G_rgb(0,0,1) ; } G_fill_circle(P[0],P[1],2) ; } q = G_wait_key() ; }
int main() { double j,r,q ; size = 600 ; G_init_graphics(size, size) ; G_rgb(0, 0, 0) ; G_clear() ; G_rgb(1.0, 0.0, 0.0) ; j = 0 ; while (j < 500000) { r = drand48() ; // diagonal_line(r) ; filled_triangle(r) ; G_point (x[0], y[0]) ; j=j+1 ; } q = G_wait_key() ; }
int main(int argc, char const *argv[]) { double moveback[4][4]; double distance; for (int i=1; i<argc; i++) { FILE* f = fopen(argv[i], "r"); read_object3d_from_file(f, &objs[i-1]); obj = &objs[i-1]; //move the object backwards so that it doesn't intersect with the view distance = max(obj->zs, obj->n)+10; printf("initial distance is %f\n", distance); D3d_make_identity(moveback); D3d_translate(moveback, useless, 0, 0, -distance); //scale the object to fit the view double max_dim = 10; double m = max(obj->xs, obj->n); if (m > max_dim) max_dim = m; m = max(obj->ys, obj->n); if (m > max_dim) max_dim = m; printf("max dimension is %f\n", max_dim); //D3d_scale(moveback, useless, .1, .1, .1); transform_object3d(obj, moveback); } num_objs = argc-1; setup_matrices(); fov = M_PI/8.0; G_init_graphics(600, 600); key_handler(); return 0; }
int main(){ double x,y; G_init_graphics(600,600); G_wait_key(); }
int main() { double swidth, sheight ; swidth = 601 ; sheight = 601 ; G_init_graphics (swidth, sheight); int r, i; r = 300; i = 0; double x, y, p; p = M_PI / 18; while (i < 36) { x = 300 * cos(i * p); y = 300 * sin(i * p); G_line(300, 300, 300 + x, 300 + y); i++; } while (r > 0) { // if (fmod(r, 20) == 0) { // G_rgb(0, 0, 0); // } else { // G_rgb(1, 0, 0); // } G_circle(300, 300, r); r -= 10; } r = G_wait_key(); }
int main (int argc, char **argv) { int w,h,nrows, ncols ; double r[2],g[2],b[2] ; int i,j,k,q ; double dx,dy ; if (argc != 12) { printf("Usage : pgm xwd_res_file_name width height nrows ncols r0 g0 b0 r1 g1 b1\n") ; exit(0) ; } w = atoi(argv[2]) ; h = atoi(argv[3]) ; nrows = atoi(argv[4]) ; ncols = atoi(argv[5]) ; r[0] = atof(argv[6]) ; g[0] = atof(argv[7]) ; b[0] = atof(argv[8]) ; r[1] = atof(argv[9]) ; g[1] = atof(argv[10]) ; b[1] = atof(argv[11]) ; G_init_graphics(w,h) ; G_rgb(0,1,0) ; G_clear() ; // reveals a green bottom line...error in FPT's G_fill_rectangle // ...now fixed dx = 1.0*w/ncols ; dy = 1.0*h/nrows ; for (i = 0 ; i < ncols ; i++) { for (j = 0 ; j < nrows ; j++) { k = (i + j) % 2 ; G_rgb(r[k],g[k],b[k]) ; G_fill_rectangle(i*dx,j*dy,dx,dy) ; } } q = G_wait_key() ; G_save_image_to_file(argv[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(){ double ax[100], ay[100], bx[100], by[100]; int anum, bnum; G_init_graphics(WINDOW,WINDOW); G_rgb(0,0,0); G_clear(); G_clear(1,1,1); G_rgb(1,1,1); G_draw_string("Save", 0,585); G_rgb(0,1,0); anum = clickandsave(ax,ay); my_fill_polygon(ax, ay, anum); G_rgb(1,0,0); bnum = clickandsave(bx, by); //printf("anum: %d bnum %d \n", anum, bnum); my_fill_polygon(bx,by,bnum); G_wait_key(); }
int main() // this tests clipping of polygon to convex window //prefix -p == polygon; prefix -w == window { int pn, wn ; double pt[2], u, v, q ; double px[100] = { 70, 460, 400} ; double py[100] = { 350, 25, 550} ; pn = 3 ; double wx[100] = { 100, 600, 550, 150} ; double wy[100] = { 150, 200, 450, 500} ; wn = 4 ; srand48(100) ; G_init_graphics (700, 700) ; G_rgb (0, 0, 0) ; G_clear() ; G_rgb (1, 0, 0) ; G_polygon(wx, wy, wn) ; G_rgb (0, 0, 1) ; G_polygon(px, py, pn) ; q = G_wait_key() ; pn = Clip_Polygon_Against_Convex_Window (px, py, pn, wx, wy, wn) ; G_rgb (1, 1, 0) ; for (int i = 0; i < pn; i++) { G_fill_circle(px[i], py[i], 2); printf("x:%.2lf, y:%.2lf\n", px[i], py[i]); } G_fill_polygon(px, py, pn) ; q = G_wait_key() ; }
int main() { int q ; G_init_graphics(601, 601) ; G_rgb(0,0,0) ; G_clear() ; G_rgb(0,0,1) ; G_fill_polygon(x,y,n) ; q = G_wait_key() ; translate(150, 50) ; G_rgb(1,0,1) ; G_fill_polygon(x,y,n) ; q = G_wait_key() ; }
int main () { char prefix[100], sequence_name[100] ; int s,e,i ; double f ; printf("enter prefix name ") ; scanf("%s",prefix) ; printf("enter starting integer ") ; scanf("%d",&s) ; printf("enter ending integer ") ; scanf("%d",&e) ; /* printf("\n") ; for (i = s ; i <= e ; i++) { sprintf(sequence_name, "%s%04d.xwd", prefix, i) ; printf("%s\n",sequence_name) ; } */ G_init_graphics(400,400) ; for (i = s ; i <= e ; i++) { G_rgb(0,0,0) ; G_clear() ; f = 1.0*i/(e - s + 1) ; G_rgb(1,f,0) ; G_fill_circle(200,200,i) ; sprintf(sequence_name, "%s%04d.xwd", prefix, i) ; G_save_image_to_file(sequence_name) ; } G_close() ; }
int main(int argc, char **argv) { FILE *f; if(argc == 2) { f = fopen(argv[1], "r"); printf("File %s read.",argv[1]); } else if (argc == 1) { } else { printf("Please enter the correct amount of command line arguments.\n"); } /* * Initialize graphics engine using sizes defined */ G_init_graphics(x_size, y_size); /* * Display until a key is pressed */ G_wait_key(); }
int main() { G_init_graphics(600,600) ; G_rgb(0,0,0) ; G_clear() ; G_rgb(0,0,1) ; G_fill_polygon(jx,jy,5) ; G_wait_key(); double rot45[3][3]; double useless[3][3]; D2d_make_identity(rot45); D2d_rotate(rot45, useless, M_PI/4.0); D2d_mat_mult_points(jx, jy, rot45, jx, jy, 5); G_fill_polygon(jx, jy, 5); double upandover[3][3]; D2d_make_identity(upandover); D2d_translate(upandover, useless, 1, 1); int count = 0; while (G_wait_key()) { count = (count+1)%200; D2d_mat_mult_points(jx, jy, upandover, jx, jy, 5); G_rgb(0, 0, 0); G_clear(); G_rgb(0, 0, 1); if (count < 100) { G_fill_polygon(jx, jy, 5); } else { G_fill_polygon(jy, jx, 5); } G_rgb(1, 0, 0); G_line(0, 0, 600, 600); } }
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 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() { 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 main(int argc, char **argv){ char t; int i; int j, k; double minx[10], miny[10], maxx[10], maxy[10]; FILE *f; int numObjects = argc-1; for(thisObj=0; thisObj < numObjects; thisObj++){ f=fopen(argv[thisObj+1], "r"); if(f==NULL){ printf("Can't open file"); exit(1); } fscanf(f, "%d", &numPoints[thisObj]); for(i=0;i<numPoints[thisObj];i++){ fscanf(f, "%lf %lf", &xp[thisObj][i], &yp[thisObj][i]); } fscanf(f, "%d", &numPolygons[thisObj]); for(i=0;i<numPolygons[thisObj];i++){ fscanf(f, "%d", &shapes[thisObj][i][0]); for(j=1;j<=shapes[thisObj][i][0];j++){ fscanf(f, "%d", &shapes[thisObj][i][j]); } } for(i=0;i<numPolygons[thisObj]; i++){ fscanf(f, "%lf %lf %lf", &r[thisObj][i], &g[thisObj][i], &b[thisObj][i]); } //printf("heelo01\n") ; minx[thisObj] = xp[thisObj][0], miny[thisObj] = yp[thisObj][0],maxx[thisObj] = xp[thisObj][0], maxy[thisObj] = yp[thisObj][0]; //find min x for(i=0;i<numPoints[thisObj]; i++){ if(xp[thisObj][i]<minx[thisObj]){minx[thisObj] = xp[thisObj][i];} if(xp[thisObj][i]>maxx[thisObj]){maxx[thisObj] = xp[thisObj][i];} if(yp[thisObj][i]<miny[thisObj]){miny[thisObj] = yp[thisObj][i];} if(yp[thisObj][i]>maxy[thisObj]){maxy[thisObj] = yp[thisObj][i];} } vertc[thisObj] = (maxy[thisObj] + miny[thisObj])/2; horzc[thisObj] = (maxx[thisObj] + minx[thisObj])/2; double sf ; if(maxy[thisObj]-miny[thisObj]>maxx[thisObj]-minx[thisObj]){ sf = 550/(maxy[thisObj]-miny[thisObj]) ; }else { sf = 550/(maxx[thisObj]-minx[thisObj]) ; } D2d_make_identity(m); D2d_make_identity(minv); D2d_translate(m,minv, -horzc[thisObj],-vertc[thisObj]); D2d_scale(m,minv, sf,sf) ; D2d_translate(m,minv, 300,300) ; D2d_mat_mult_points( xp[thisObj],yp[thisObj], m, xp[thisObj],yp[thisObj],numPoints[thisObj]) ; horzc[thisObj]=300; vertc[thisObj] = 300; } // end for thisObj thisObj = 0; G_init_graphics(600,600); redraw(); buildClipWindow(); redraw(); D2d_make_identity(m); D2d_make_identity(minv); D2d_translate(m,minv, -300,-300) ; D2d_rotate(m,minv, 3*M_PI/180) ; D2d_translate(m,minv, 300, 300) ; while(1){ t = G_wait_key(); if(t>='0' && t<='9'){ thisObj = t-'0'; } D2d_mat_mult_points(xp[thisObj], yp[thisObj], m, xp[thisObj], yp[thisObj], numPoints[thisObj]); redraw(); } }
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") ; }
int main() { double swidth, sheight ; swidth = 601 ; sheight = 601 ; G_init_graphics (swidth, sheight); int res, numpoints; double r, x[3], y[3], p, i, k; k = 0; res = 47; p = (M_PI / (res / 2)); numpoints = 3; while (true) { G_rgb(1, 1, 1); G_clear(); G_rgb(0, 0, 0); i = 0; while(i < res) { x[1] = 240 * cos((i + 1 + k/4) * p) + 300; y[1] = 80 * sin((i + 1 + k/4) * p) + 450; x[2] = 240 * cos((i + k/4) * p) + 300; y[2] = 80 * sin((i + k/4) * p) + 450; x[0] = 300; y[0] = 450; G_fill_polygon (x, y, numpoints); i++; x[1] = 240 * cos((i + 1 + k/4) * p) + 300; y[1] = 80 * sin((i + 1 + k/4) * p) + 450; x[2] = 240 * cos((i + k/4) * p) + 300; y[2] = 80 * sin((i + k/4) * p) + 450; x[0] = 300; y[0] = 150; if (y[1] < 436 && y[2] < 436) { G_fill_polygon (x, y, numpoints); } i++; } G_rgb(1, 0, 0); x[1] = 240 * cos((1 + k/4) * p) + 300; y[1] = 80 * sin((1 + k/4) * p) + 450; x[2] = 240 * cos((k/4) * p) + 300; y[2] = 80 * sin((k/4) * p) + 450; x[0] = 300; y[0] = 450; G_fill_polygon (x, y, numpoints); if (y[1] < 436 && y[2] < 436) { x[0] = 300; y[0] = 150; G_fill_polygon (x, y, numpoints); } G_rgb(0, 0, 0); k++; i = G_wait_key(); if (i == 'q') { break; } } }
int main(int argc, char **argv){ char t; FILE *f; f=fopen(argv[1], "r"); if(f==NULL){ printf("Can't open file"); exit(1); } fscanf(f, "%d", &numPoints); int i; for(i=0;i<numPoints;i++){ fscanf(f, "%lf %lf", &xp[i], &yp[i]); } fscanf(f, "%d", &numPolygons); int j, k; for(i=0;i<numPolygons;i++){ fscanf(f, "%d", &shapes[i][0]); for(j=1;j<=shapes[i][0];j++){ fscanf(f, "%d", &shapes[i][j]); } } for(i=0;i<numPolygons; i++){ fscanf(f, "%lf %lf %lf", &r[i], &g[i], &b[i]); } double minx = xp[0], miny = yp[0],maxx = xp[0], maxy = yp[0]; //find min x for(i=0;i<numPoints; i++){ if(xp[i]<minx){minx = xp[i];} if(xp[i]>maxx){maxx = xp[i];} if(yp[i]<miny){miny = yp[i];} if(yp[i]>maxy){maxy = yp[i];} } vertc = (maxy + miny)/2; horzc = (maxx + minx)/2; G_init_graphics(600,600); if(maxy-miny>maxx-minx){ scale(550/(maxy-miny),550/(maxy-miny)); }else if(maxy-miny<maxx-minx){ scale(550/(maxx-minx),550/(maxx-minx)); } translate(300-horzc,300-vertc); horzc=300; vertc = 300; redraw(); //movement while(1){ t = G_wait_key(); if(t == 'd'){ translate(2,0); horzc+=2; }else if(t == 'a'){ translate(-2,0); horzc-=2; }else if(t == 's'){ translate(0,-2); vertc-=2; }else if(t == 'w'){ translate(0,2); vertc +=2; }else if(t == 'q'){ rotate(2); }else if(t == 'e'){ rotate(-2); } redraw(); } }
int main() { int swidth, sheight ; double lowleftx, lowlefty, width, height ; double x[10],y[10] ; double numpoints,q, x0,y0,x1,y1 ; double p[2] ; int i ; // must do this before you do 'almost' any other // graphical tasks swidth = 400 ; sheight = 500 ; G_init_graphics (swidth, sheight) ; // draw a point, a line, some rectangles, some triangles G_rgb(1, 0, 0) ; // red G_point(200, 380) ; G_fill_rectangle (300,400, 50, 20) ; G_rgb(0, 1, 0) ; // green // G_line (0, 0, 400, 400) ; // won't show if part is off screen G_line (0, 0, 399, 399) ; G_fill_triangle(50, 400, 100,400, 150,475) ; G_rgb(0, 0, 1) ; // blue lowleftx = 200 ; lowlefty = 50 ; width = 10 ; height = 30 ; G_rectangle (lowleftx, lowlefty, width, height) ; lowleftx = 250 ; G_fill_rectangle (lowleftx, lowlefty, width, height) ; G_rgb(1, 1, 0) ; // yellow G_triangle (10, 300, 40,300, 60,250) ; G_fill_triangle (10,100, 40,100, 60,150) ; G_rgb(1, 0.5, 0) ; // orange G_circle (100, 300, 75) ; G_fill_circle (370, 200, 50) ; // prints text in your graphics window G_rgb(0, 0, 0) ; // black G_draw_string ("hello",300,100) ; // draw a polygon x[0] = 100 ; y[0] = 100 ; x[1] = 100 ; y[1] = 300 ; x[2] = 300 ; y[2] = 300 ; x[3] = 300 ; y[3] = 100 ; x[4] = 200 ; y[4] = 175 ; numpoints = 5 ; G_polygon (x,y,numpoints) ; G_rgb (0.4, 0.2, 0.1) ; // brown G_fill_polygon (x,y,numpoints) ; G_rgb (0.5, 0.8, 0.4) ;// what color is this? int xc,yc ; int pixel ; int rgbI[3] ; double rgb[3] ; G_wait_click(p) ; xc = p[0] ; yc = p[1] ; while (yc > 20) { printf("%d %d\n",xc,yc) ; pixel = G_get_pixel(xc,yc) ; G_convert_pixel_to_rgbI(pixel, rgbI) ; G_convert_rgbI_to_rgb(rgbI, rgb) ; printf("pixel = %x\n",pixel) ; printf("%3d %3d %3d\n",rgbI[0],rgbI[1],rgbI[2]) ; printf("%lf %lf %lf\n",rgb[0],rgb[1],rgb[2]) ; printf("\n") ; G_wait_click(p) ; xc = p[0] ; yc = p[1] ; } }
int main() { double swidth, sheight ; double lowleftx, lowlefty, width, height ; double x[10],y[10] ; double numpoints,q, x0,y0,x1,y1 ; double p[2] ; // must do this before you do 'almost' any other // graphical tasks swidth = 400 ; sheight = 400 ; G_init_graphics (swidth, sheight) ; // draw a point, a line, some rectangles, some triangles G_rgb(1, 0, 0) ; // red G_point(200, 380) ; G_rgb(0, 1, 0) ; // green // G_line (0, 0, 400, 400) ; // won't show if part is off screen G_line (0, 0, 399, 399) ; G_rgb(0, 0, 1) ; // blue lowleftx = 200 ; lowlefty = 50 ; width = 10 ; height = 30 ; G_rectangle (lowleftx, lowlefty, width, height) ; lowleftx = 250 ; G_fill_rectangle (lowleftx, lowlefty, width, height) ; G_rgb(1, 1, 0) ; // yellow G_triangle (10, 300, 40,300, 60,250) ; G_fill_triangle (10,100, 40,100, 60,150) ; G_rgb(1, 0.5, 0) ; // orange G_circle (100, 300, 75) ; G_fill_circle (370, 200, 50) ; // prints text in your graphics window G_rgb(0, 0, 0) ; // black G_draw_string ("hello",300,100) ; // draw a polygon x[0] = 100 ; y[0] = 100 ; x[1] = 100 ; y[1] = 300 ; x[2] = 300 ; y[2] = 300 ; x[3] = 300 ; y[3] = 100 ; x[4] = 200 ; y[4] = 175 ; numpoints = 5 ; G_polygon (x,y,numpoints) ; q = G_wait_key() ; // pause to look ...any key to continue G_rgb (0.4, 0.2, 0.1) ; // brown G_fill_polygon (x,y,numpoints) ; G_rgb (0.5, 0.8, 0.4) ;// what color is this? G_wait_click(p) ; // wait for a mouse click x0 = p[0] ; y0 = p[1] ; // extract coordinates G_fill_rectangle (x0-2, y0-2, 4,4) ;// mark the clicked point G_wait_click(p) ; x1 = p[0] ; y1 = p[1] ; G_fill_rectangle (x1-2, y1-2, 4,4) ; G_rgb (0.5, 0.5, 0.5) ; // a grey G_line (x0,y0, x1,y1) ; q = G_wait_key() ; // pause again before exit G_save_image_to_file ("t01c.xwd") ; G_close() ; // terminate graphics...probably not fatal if forgotten }
int main (int argc, char **argv) { char q, action; double mat[4][4], minv[4][4], scaleFactor; double radians = 3 * (M_PI / 180); FILE *g; int cc, sign, currentObj, k, h; int increment = 15; int xcounter, ycounter, zcounter = 0; for (cc = 1; cc < argc; cc++) { g = fopen(argv[cc], "r"); //opens a file; r = read only if (g == NULL) { //if the file is empty, it will let me know printf("can't open (1)\n"); exit(1); } else { readobject(g, cc); D3d_make_identity(mat); D3d_make_identity(minv); scaleFactor = scale_n_fit(cc); D3d_translate(mat, minv, -centerx, -centery, -centerz); D3d_scale(mat, minv, scaleFactor, scaleFactor, scaleFactor); D3d_mat_mult_points(x[cc], y[cc], z[cc], mat, x[cc], y[cc], z[cc], points[cc]); // printarray(z[cc], points[cc]); } } welcome(argc - 1); scanf("%c", &q); currentObj = q - '0'; sign = 1 ; action = 't' ; if (currentObj < argc && currentObj > 0) { G_init_graphics(WIDTH, HEIGHT); while (1) { G_rgb(0, 0, 0); G_clear(); drawit(currentObj); D3d_make_identity (mat) ; D3d_make_identity (minv) ; q = G_wait_key() ; if (q == 'q') { exit(0) ; } else if (q == 'c') { sign = -sign ; } else if (q == 't') { action = q ; } else if (q == 's') { reverse = -reverse; } else if (q == 'r') { action = q ; } else if (('0' <= q) && (q <= '9')) { k = q - '0' ; if (h != currentObj) { currentObj = k; } } else if ((q == 'x') && (action == 't')) { D3d_translate (mat, minv, sign * increment, 0, 0); xcounter = xcounter + (sign * increment); } else if ((q == 'y') && (action == 't')) { D3d_translate (mat, minv, 0, sign * increment, 0); ycounter = ycounter + (sign * increment); } else if ((q == 'z') && (action == 't')) { D3d_translate(mat, minv, 0, 0, sign * increment); zcounter = zcounter + (sign * increment); } else if ((q == 'x') && (action == 'r')) { D3d_translate(mat, minv, -xcounter, -ycounter, -zcounter); D3d_rotate_x(mat, minv, sign * radians); D3d_translate(mat, minv, xcounter, ycounter, zcounter); } else if ((q == 'y') && (action == 'r')) { D3d_translate(mat, minv, -xcounter, -ycounter, -zcounter); D3d_rotate_y(mat, minv, sign * radians); D3d_translate(mat, minv, xcounter, ycounter, zcounter); } else if ((q == 'z') && (action == 'r')) { D3d_translate(mat, minv, -xcounter, -ycounter, -zcounter); D3d_rotate_z(mat, minv, sign * radians); D3d_translate(mat, minv, xcounter, ycounter, zcounter); } else { printf("no action\n") ; } D3d_mat_mult_points (x[currentObj], y[currentObj], z[currentObj], mat, x[currentObj], y[currentObj], z[currentObj], points[currentObj] + 1) ; //the numpoints[currentObj]+1 is because we have stored //the center of the object at the arrays' end G_rgb(0, 0, 0); G_clear(); drawit(currentObj); } } }
void setUp(){ G_init_graphics(WINDOW_WIDTH,WINDOW_WIDTH + 30); G_rgb(0,0,0); G_clear(); G_clear(1,1,1); }
int main(int argc, char **argv){ char t; int i; int j, k; double xmin, ymin, zmin, xmax, ymax, zmax; lightPos[0] = 100; lightPos[1] = 200; FILE *f; numObjects = argc-1; H = tan(M_PI/4); for(thisObj=0; thisObj < numObjects; thisObj++){ f=fopen(argv[thisObj+1], "r"); if(f==NULL){ //printf("Can't open file"); exit(1); } fscanf(f, "%d", &numPoints[thisObj]); fscanf(f, "%lf %lf %lf", &xp[thisObj][0], &yp[thisObj][0], &zp[thisObj][0]); xmin = xp[thisObj][0]; xmax = xmin; ymin = yp[thisObj][0]; ymax = ymin; zmin = zp[thisObj][0]; zmax = zmin; for(i=1;i<numPoints[thisObj];i++){ fscanf(f, "%lf %lf %lf", &xp[thisObj][i], &yp[thisObj][i], &zp[thisObj][i]); if(xp[thisObj][i] > xmax){ xmax = xp[thisObj][i]; }else if(xp[thisObj][i] < xmin){ xmin = xp[thisObj][i]; } if(yp[thisObj][i] > ymax){ ymax = yp[thisObj][i]; }else if(yp[thisObj][i] < ymin){ ymin = yp[thisObj][i]; } if(zp[thisObj][i] > zmax){ zmax = zp[thisObj][i]; }else if(zp[thisObj][i] < zmin){ zmin = zp[thisObj][i]; } } xc[thisObj] = (xmax + xmin)/2; yc[thisObj] = (ymax + ymin)/2; zc[thisObj] = (zmax + zmin)/2; fscanf(f, "%d", &numPolygons[thisObj]); for(i=0;i<numPolygons[thisObj];i++){ fscanf(f, "%d", &shapes[thisObj][i][0]); for(j=1;j<=shapes[thisObj][i][0];j++){ fscanf(f, "%d", &shapes[thisObj][i][j]); } } objectIsReversed[thisObj] = 0; } // end for thisObj thisObj = 0; G_init_graphics(600,600); redraw(); D3d_make_identity(m); D3d_make_identity(rotx); D3d_make_identity(roty); D3d_make_identity(rotz); D3d_make_identity(scaleup); D3d_make_identity(scaledown); D3d_make_identity(moveleft); D3d_make_identity(moveright); D3d_make_identity(moveup); D3d_make_identity(movedown); D3d_make_identity(push); D3d_make_identity(pull); D3d_make_identity(minv); D3d_rotate_y(roty, minv, 3*M_PI/180); D3d_rotate_z(rotz, minv, 3*M_PI/180); D3d_scale(scaleup, minv, 1.02, 1.02,1.02); D3d_scale(scaledown, minv, .98, .98, .98); D3d_translate(moveleft, minv, -.02, 0, 0); D3d_translate(moveright, minv, .02, 0, 0); D3d_translate(moveup, minv, 0, .02, 0); D3d_translate(movedown, minv, 0, -.02, 0); D3d_translate(push, minv, 0, 0, .02); D3d_translate(pull, minv, 0, 0, -.02); while(1){ t = G_wait_key(); if(t>='0' && t<='9'){ thisObj = t-'0'; redraw(); t = G_wait_key(); } switch(t){ case 'w': D3d_copy_mat(m, moveup); yc[thisObj] += .02; break; case 'a': D3d_copy_mat(m, moveleft); xc[thisObj] -= .02; break; case 's': D3d_copy_mat(m, movedown); yc[thisObj] -= .02; break; case 'd': D3d_copy_mat(m, moveright); xc[thisObj] += .02; break; case 'z': D3d_translate(m, minv, -xc[thisObj], -yc[thisObj], -zc[thisObj]); D3d_rotate_x(m, minv, 3*M_PI/180); D3d_translate(m, minv, xc[thisObj], yc[thisObj], zc[thisObj]); break; case 'x': D3d_translate(m, minv, -xc[thisObj], -yc[thisObj], -zc[thisObj]); D3d_rotate_y(m, minv, 3*M_PI/180); D3d_translate(m, minv, xc[thisObj], yc[thisObj], zc[thisObj]); break; case 'c': D3d_translate(m, minv, -xc[thisObj], -yc[thisObj], -zc[thisObj]); D3d_rotate_z(m, minv, 3*M_PI/180); D3d_translate(m, minv, xc[thisObj], yc[thisObj], zc[thisObj]); break; case 'q': D3d_copy_mat(m, push); zc[thisObj] += .02; break; case 'e': D3d_copy_mat(m, pull); zc[thisObj] -= .02; break; case 'r': D3d_copy_mat(m, scaleup); break; case 't': D3d_copy_mat(m, scaledown); break; case '`': objectIsReversed[thisObj] = 1; break; case 'j': lightPos[0] -= .2; break; case 'l': lightPos[0] += .2; break; case 'i': lightPos[1] += .2; break; case 'k': lightPos[1] -= .2; break; case 'u': lightPos[2] += .2; break; case 'o': lightPos[2] -= .2; break; } //printf("lightx: %lf \n lighty: %lf \n lightz: %lf \n\n", lightPos[0], lightPos[1], lightPos[2]); D3d_mat_mult_points(xp[thisObj], yp[thisObj], zp[thisObj], m, xp[thisObj], yp[thisObj], zp[thisObj], numPoints[thisObj]); D3d_make_identity(m); redraw(); } }
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) }