Пример #1
0
void buildPoly(int i){
  
  double xx[20], yy[20], zz[20] ;
  double xpoly[20], ypoly[20];
  int j,k,n;
  
  n = shapes[polyDistance[i].objNum][polyDistance[i].polyNum][0];
  
  for(j=1;j<=n;j++){
    xx[j-1] = xp[polyDistance[i].objNum][shapes[polyDistance[i].objNum][polyDistance[i].polyNum][j]] ;
    yy[j-1] = yp[polyDistance[i].objNum][shapes[polyDistance[i].objNum][polyDistance[i].polyNum][j]] ;
    zz[j-1] = zp[polyDistance[i].objNum][shapes[polyDistance[i].objNum][polyDistance[i].polyNum][j]] ;
  }
  
  for(j=0;j<n;j++){
    xpoly[j] = (300/H)*xx[j]/zz[j] + 300 ;
    ypoly[j] = (300/H)*yy[j]/zz[j] + 300 ;
  }
  
  if(thisObj == polyDistance[i].objNum){
    calcColor(xx, yy, zz, 1, .4, .4);
  }else{
    calcColor(xx, yy, zz, .1,.3,.6);
  }
  
  G_fill_polygon(xpoly, ypoly, n);
  //G_rgb(0,0,0);
  //G_polygon(xpoly, ypoly, n);
  
  
} 
Пример #2
0
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() ;
}
Пример #3
0
void display(int pnum){
	int i, j, k;
	G_rgb(0,0,0);
  G_clear();
  G_clear(1,1,1);
// printf("enter disp\n");
for(i=0;i<numpolys[pnum];i++){
	double xtemp[poly_sizes[pnum][i]], ytemp[poly_sizes[pnum][i]];
	// printf("New display\n");
	for(j=0; j<poly_sizes[pnum][i];j++){
 		xtemp[j] = x[pnum][polygons[pnum][i][j]];
 		ytemp[j] = y[pnum][polygons[pnum][i][j]];
 		// printf("X = %lf Y = %lf \n",xtemp[j],ytemp[j] );
	}
	
 	G_rgb(colors[pnum][i][0],colors[pnum][i][1],colors[pnum][i][2]);
 	G_fill_polygon(xtemp, ytemp ,poly_sizes[pnum][i]);
 	}
 	double a[3][3], b[3][3];
 	D2d_make_identity(a);
 	D2d_make_identity(b);
 	D2d_translate(a, b, -WINDOW_WIDTH/2, -WINDOW_WIDTH/2);
 	D2d_rotate(a,b, ROTATE_SPEED);
 	D2d_translate(a, b, WINDOW_WIDTH/2, WINDOW_WIDTH/2);
 	D2d_mat_mult_points(x[pnum], y[pnum], a, x[pnum], y[pnum],numpoints[pnum]);

}
Пример #4
0
void display(int pnum){
	int i, j, k;
	G_rgb(0,0,0);
  G_clear();
  G_clear(1,1,1);
// printf("enter disp\n");
for(i=0;i<numpolys[pnum];i++){
	double xtemp[1000], ytemp[1000];
	// printf("New display\n");
	for(j=0; j<poly_sizes[pnum][i];j++){
 		xtemp[j] = x[pnum][polygons[pnum][i][j]];
 		ytemp[j] = y[pnum][polygons[pnum][i][j]];
 		// printf("X = %lf Y = %lf \n",xtemp[j],ytemp[j] );
	}
	int tsize = clip(xtemp,ytemp,poly_sizes[pnum][i]);
 	G_rgb(colors[pnum][i][0],colors[pnum][i][1],colors[pnum][i][2]);
 	G_fill_polygon(xtemp, ytemp ,tsize);
 	}
 	double a[3][3], b[3][3];
 	D2d_make_identity(a);
 	D2d_make_identity(b);
 	D2d_translate(a, b, -WINDOW_WIDTH/2, -WINDOW_WIDTH/2);
 	D2d_rotate(a,b, ROTATE_SPEED);
 	D2d_translate(a, b, WINDOW_WIDTH/2, WINDOW_WIDTH/2);
 	
 	D2d_mat_mult_points(x[pnum], y[pnum], a, x[pnum], y[pnum],numpoints[pnum]);

for(i=0; i<cSize;i++){//show clipping box
	G_rgb(255,255,255);
	G_line(cx[i], cy[i], cx[(i+1)%cSize], cy[(i+1)%cSize]);
}

}
Пример #5
0
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() ;

}
Пример #6
0
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);
  }
}
Пример #7
0
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() ;

}
Пример #8
0
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() ;
}
Пример #9
0
void buildPoly(int i){

  double R, G, B;

  G_rgb(r[i],g[i],b[i]);

  double xpoly[20], ypoly[20];

  int j,k,n;

  n = shapes[i][0];

  for(j=1;j<=n;j++){
    xpoly[j-1] = xp[shapes[i][j]];
    ypoly[j-1] = yp[shapes[i][j]];

  }

  G_fill_polygon(xpoly,ypoly,n);

} 
Пример #10
0
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() ;
}
Пример #11
0
void buildPoly(int i){

  double R, G, B;

  G_rgb(r[thisObj][i],g[thisObj][i],b[thisObj][i]);

  double xpoly[20], ypoly[20];

  int j,k,n;

  n = shapes[thisObj][i][0];

  for(j=1;j<=n;j++){
    xpoly[j-1] = xp[thisObj][shapes[thisObj][i][j]];
    ypoly[j-1] = yp[thisObj][shapes[thisObj][i][j]];

  }
  
  clipHitheryon

  G_fill_polygon(xpoly,ypoly,n);


} 
Пример #12
0
void display(int pnum, int sign, int specpow, double diffusepro, double ambient, double lightx, double lighty, double lightz){
	int i, j, k, m;
	G_rgb(0,0,0);
	G_clear();
	double halfAngle = 30*M_PI/180;
	G_clear(1,1,1);
	if(sign == 0){
			sign = -1;
		}else{
			sign=1;
		}
int n=0;
for(n=0; n<plsize; n++){
double xtemp[100];
double ytemp[100];
double ztemp[100];
	for(j=0; j<poly_sizes[polyLoc[n].objnum][polyLoc[n].polynum];j++){
 		xtemp[j] = x[polyLoc[n].objnum][polygons[polyLoc[n].objnum][polyLoc[n].polynum][j]];
 		ytemp[j] = y[polyLoc[n].objnum][polygons[polyLoc[n].objnum][polyLoc[n].polynum][j]];
 		ztemp[j] = z[polyLoc[n].objnum][polygons[polyLoc[n].objnum][polyLoc[n].polynum][j]];

 	
	}

		int tempsize = poly_sizes[polyLoc[n].objnum][polyLoc[n].polynum];
		double perpendicular[3], first[3], second[3], eye[3], light[3],reflection[3];

		


	 tempsize = Clip_Polygon_Against_Window(xtemp,ytemp,ztemp, poly_sizes[polyLoc[n].objnum][polyLoc[n].polynum]);
	 if(tempsize < 1)continue;

	 	first[0] = xtemp[0]-xtemp[1];
		first[1] = ytemp[0]-ytemp[1];
		first[2] = ztemp[0]-ztemp[1];

		second[0] = xtemp[0]-xtemp[2];
		second[1] = ytemp[0]-ytemp[2];
		second[2] = ztemp[0]-ztemp[2];

		eye[0] = 0 - xtemp[0] ;
		eye[1] = 0 - ytemp[0] ;
		eye[2] = 0 - ztemp[0] ;

		light[0]= lightx - xtemp[0] ;
		light[1]= lighty - ytemp[0] ;
		light[2]= lightz - ztemp[0] ;

		double xfinal[tempsize], yfinal[tempsize];
for(j=0; j<tempsize;j++){

		xfinal[j] = xtemp[j]/ztemp[j];
		yfinal[j] = ytemp[j]/ztemp[j];
		xfinal[j] = (xfinal[j] * (300/tan(halfAngle))) + 300;
		yfinal[j] = (yfinal[j] * (300/tan(halfAngle))) + 300;
}

		D3d_x_product(perpendicular,first,second);
		double length = sqrt(perpendicular[0]*perpendicular[0] + perpendicular[1]*perpendicular[1] + perpendicular[2]*perpendicular[2]);
		perpendicular[0] = perpendicular[0]/length;
		perpendicular[1] = perpendicular[1]/length;
		perpendicular[2] = perpendicular[2]/length;

		double lightLength =  sqrt(light[0]*light[0] + light[1]*light[1] + light[2]*light[2]);
		light[0] = light[0]/lightLength;
		light[1] = light[1]/lightLength;
		light[2] = light[2]/lightLength;
		double eyelength =  sqrt(eye[0]*eye[0] + eye[1]*eye[1] + eye[2]*eye[2]);
		eye[0] = eye[0]/eyelength;
		eye[1] = eye[1]/eyelength;
		eye[2] = eye[2]/eyelength;


		double pl = dot_product(perpendicular, light);

		if(pl < 0){
			perpendicular[0] = -1 * perpendicular[0];	
			perpendicular[1] = -1 * perpendicular[1];
			perpendicular[2] = -1 * perpendicular[2];
			pl = dot_product(perpendicular, light);
		}


		double pe = dot_product(perpendicular, eye);
		double intensity;
                if (pe < 0) { intensity = ambient ; goto JJJ ; }

		double diffuse = diffusepro * pl;

		reflection[0] = ((2 * pl) * perpendicular[0]) - light[0];
		reflection[1] = ((2 * pl) * perpendicular[1]) - light[1];
		reflection[2] = ((2 * pl) * perpendicular[2]) - light[2];
		double specular;
	
		specular = (1 - ambient - diffusepro) * pow((dot_product(eye, reflection)),specpow);	
		
		 intensity = ambient + diffuse + specular;


 JJJ : ;
		double redt, greent, bluet;

		if(intensity <= ambient + diffusepro){
			double f = intensity/ (ambient + diffusepro);
			redt = f*red[polyLoc[n].objnum];
			greent = f* green[polyLoc[n].objnum];
			bluet = f*blue[polyLoc[n].objnum];
		}
		else{
			double I[3];
			I[0] = 1-red[polyLoc[n].objnum];
			I[1] = 1-green[polyLoc[n].objnum];
			I[2] = 1-blue[polyLoc[n].objnum];
			double f = (intensity - ambient - diffusepro)/ (1 - ambient - diffusepro);
			redt = f*I[0] + red[polyLoc[n].objnum];
			greent = f*I[1] + green[polyLoc[n].objnum];
			bluet = f*I[2] + blue[polyLoc[n].objnum];
		}
	
	


		G_rgb(redt,greent,bluet);
 		G_fill_polygon(xfinal, yfinal, tempsize);
 		G_rgb(0,0,0);
 		G_polygon(xfinal, yfinal, tempsize);
}
}
Пример #13
0
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

}
Пример #14
0
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] ;
   }





}
Пример #15
0
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") ;

}
Пример #16
0
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;

    }

  }
}