コード例 #1
0
ファイル: test5vt.c プロジェクト: chrisburnham/graphics
int main(int argc, char *argv[]) {
  const int rows = 100;
  const int cols = 100;
  const int nFrames = 16;
  // View3D view3D;
  View2D view;
  //Matrix vtm;
  Matrix vtm, gtm, ltm;
  Polygon poly[16];
  Point vp[4];
  FILE *fp;

  fp = fopen("matrix_info.txt","w");

  Image *src;
  int i, j, t;
  char filename[256];

  Color color[6];
  
  // set some colors
  color_set( &color[0], 0, 0, 1 ); // blue
  color_set( &color[1], 0, 1, 0 ); // green
  color_set( &color[2], 1, 0, 0 ); // red
  color_set( &color[3], 1, 0, 1 ); // magenta
  color_set( &color[4], 0, 1, 1 ); // cyan
  color_set( &color[5], 1, 1, 0 ); // yellow

  // optional theta value
  // if(argc > 1) {
  //   theta = atoi(argv[1]);
  // }

  // initialize the three matrices
  matrix_identity(&vtm);
  matrix_identity(&gtm);
  matrix_identity(&ltm);
  // create image
  src = image_create( rows, cols );

  srand ( time(NULL) );

  for (i=0; i<16; i++){
    for (j=0; j<4; j++){
      point_set2D(&(vp[j]), rand()%cols, rand()%rows);
    }
    poly[i] = *(polygon_createp(4, vp));
  }

  // grab command line argument to determine viewpoint
  // and set up the view structure
  if( argc > 1 ) {
    float alpha = atof( argv[1] );
    if( alpha < 0.0 || alpha > 1.0 ){
      alpha = 0.0;
    }
    point_set1( &(view.vrp), 3*alpha, 2*alpha, -2*alpha - (1.0-alpha)*3 );
  }
  else {
    point_set1( &(view.vrp), 3, 2, -2 );
  }

  vector_set( &(view.x), -view.vrp.val[0], -view.vrp.val[1], -view.vrp.val[2] );
  view.dx = 1;  // focal length
  view.screenx = cols;
  view.screeny = rows;

  matrix_setView2D( &vtm, &view );
  matrix_print(&vtm, fp);
  // create image in arbitrary world coordinates
   
  for(t=0;t<nFrames;t++) {
    
    setWhite( src );

    for (i=0; i<16; i++){
      // need to add print statements to follow the ltm and polygons
      // Polygons not drawing
      matrix_identity(&ltm);
      matrix_translate2D(&ltm, -vp[0].val[0], -vp[0].val[1]);
      matrix_shear2D(&ltm, t, 0);
      matrix_translate2D(&ltm, vp[0].val[0], vp[0].val[1]);
      matrix_xformPolygon(&ltm, &poly[i]);
      matrix_xformPolygon(&vtm, &poly[i]);
      printf("begin scanline fill...\n");
      polygon_drawFill(&poly[i], src, color[i%5]);
      printf("...end scanline fill\n");
    }
    printf("hello: %d\n", t);
    sprintf(filename, "test5vt-%04d.ppm", t );
    image_write( src, filename );

    // translate the view across the scene
    point_set2D( &(view.vrp), 1.8 - 2.4*(t+1)/nFrames, 1.8 - 2.4*(t+1)/nFrames );
    matrix_setView2D( &vtm, &view );
  }
  fclose(fp);
  system("convert test5vt-*.ppm test5vt.gif");
  //system("rm test5vt-*.ppm");
}
コード例 #2
0
ファイル: space.c プロジェクト: chrisburnham/graphics
int main(int argc, char *argv[]) {
  Image *src;
  const int rows = 600;
  const int cols = 800;
  const int Resolution = 50;
	Color white;
  Color Grey;
  Color dkGrey;
  Color Red;
  Color Blue;
  Point unitCircle[Resolution];
  Point unitSquare[4];
  Point pt[Resolution];
  Point ptt[Resolution];
  int i, j, index = 0;
  Matrix VTM, GTM, LTM;
  Polygon *ship[50];
  Color shipColor[50];
  double theta = 0.0;
  double phaserAngle = 0.0;
  int firePhase = 0;

  color_set(&Grey, 180/255.0, 180/255.0, 183/255.0);
  color_set(&dkGrey, 140/255.0, 140/255.0, 143/255.0);
  color_set(&Red, 250/255.0, 40/255.0, 40/255.0);
  color_set(&Blue, 30/255.0, 20/255.0, 250/255.0);

  if(argc > 1) {
    theta = atoi(argv[1]);
  }
  printf("Drawing ship with orientation %.2f degrees\n", theta);

  if(argc > 2) {
    phaserAngle = atoi(argv[2]);
    firePhase = 1;

    printf("Drawing phaser with angle %.2f degrees\n", phaserAngle);
  }

  srand(42);

  src = image_create(rows, cols);
	color_set(&white, 1.0, 1.0, 1.0);
	for(i=0; i<rows; i++){
		for(j=0; j<cols; j++){
			if((rand()%50) == 13){
				image_setColor(src, i, j, white);
			}
		}
	}

  // initialize the three matrices
  matrix_identity(&VTM);
  matrix_identity(&GTM);
  matrix_identity(&LTM);

  // Fix world coordinates as normal (x, y) 

  // give the view window an origin at -180m, -150m
  // size is a 4x3 ratio
  // VTM = T(0, rows-1)S(cols/vx, rows/vy)T(180, 150)
  matrix_translate2D(&VTM, 120, 100);
  matrix_scale2D(&VTM, cols/(4*60), -rows/(3*60));
  matrix_translate2D(&VTM, 0, rows-1);
  printf("VTM\n");
  matrix_print(&VTM, stdout);

  // make a space ship oriented along the positive X axis
  // use the LTM to move simple primitives into place
  // use the GTM to rotate the ship
  // use the VTM to change the view

  // make a list of points that form the unit circle
  for(i=0;i<Resolution;i++) {
    point_set2D(&(unitCircle[i]), 
    cos( i * 2.0 * M_PI / (float)Resolution), 
    sin( i * 2.0 * M_PI / (float)Resolution));
  }
  // set up the unit square
  point_set2D(&(unitSquare[0]), 0, 0);
  point_set2D(&(unitSquare[1]), 1, 0);
  point_set2D(&(unitSquare[2]), 1, 1);
  point_set2D(&(unitSquare[3]), 0, 1);

  // build a set of polygons that form the ship in model space
  // put the origin of the model between the engines

  // outline for the main disk
  matrix_identity(&LTM);
  matrix_scale2D(&LTM, 31, 31);
  // move it 20m along the X-axis
  matrix_translate2D(&LTM, 60, 0);
  // transform the circle points using LTM
  for(i=0;i<Resolution;i++) {
    matrix_xformPoint(&LTM, &(unitCircle[i]), &(pt[i]));
  }

  // add the polygon
  matrix_print(&LTM, stdout);
  ship[index] = polygon_createp(Resolution, pt);
  shipColor[index++] = Red;

  printf("Post-LTM\n");
  polygon_print(ship[0], stdout);

  // main disk
  matrix_identity(&LTM);
  matrix_scale2D(&LTM, 30, 30);
  // move it 20m along the X-axis
  matrix_translate2D(&LTM, 60, 0);
  // transform the circle points using LTM
  for(i=0;i<Resolution;i++) {
    matrix_xformPoint(&LTM, &(unitCircle[i]), &(pt[i]));
  }

  // add the polygon
  matrix_print(&LTM, stdout);
  ship[index] = polygon_createp(Resolution, pt);
  shipColor[index++] = Grey;

  // central bridge disk
  matrix_identity(&LTM);
  matrix_scale2D(&LTM, 10, 10);
  // move it 20m along the X-axis
  matrix_translate2D(&LTM, 60, 0);
  // transform the circle points using LTM
  for(i=0;i<Resolution;i++) {
    matrix_xformPoint(&LTM, &(unitCircle[i]), &(pt[i]));
  }

  // add the polygon
  matrix_print(&LTM, stdout);
  ship[index] = polygon_createp(Resolution, pt);
  shipColor[index++] = dkGrey;

  // make the body disk elongated along the X axis
  matrix_identity(&LTM);
  matrix_scale2D(&LTM, 30, 12);
  matrix_translate2D(&LTM, 2.5, 0);

  // transform the circle points using LTM
  for(i=0;i<Resolution;i++) {
    matrix_xformPoint(&LTM, &(unitCircle[i]), &(pt[i]));
  }

  // add the polygon
  matrix_print(&LTM, stdout);
  ship[index] = polygon_createp(Resolution, pt);
  shipColor[index++] = Grey;
  
  // make a trapezoidal strut out of the unit square
  matrix_identity(&LTM);
  matrix_translate2D(&LTM, -0.5, 0.0);
  matrix_scale2D(&LTM, 10, 10);
  matrix_shear2D(&LTM, .2, 0.0);

  for(i=0;i<4;i++) {
    matrix_xformPoint(&LTM, &(unitSquare[i]), &(pt[i]));
  }

  // move the strut out from the origin along the Y axis
  matrix_identity(&LTM);
  matrix_translate2D(&LTM, 0, 12);

  for(i=0;i<4;i++) {
    matrix_xformPoint(&LTM, &(pt[i]), &(ptt[i]));
  }

  // add the polygon
  matrix_print(&LTM, stdout);
  ship[index] = polygon_createp(4, ptt);
  shipColor[index++] = Grey;

  // place the second strut
  matrix_identity(&LTM);
  matrix_scale2D(&LTM, 1, -1);
  matrix_translate2D(&LTM, 0, -12);

  for(i=0;i<4;i++) {
    matrix_xformPoint(&LTM, &(pt[i]), &(ptt[i]));
  }

  // add the polygon
  ship[index] = polygon_createp(4, ptt);
  shipColor[index++] = Grey;

  // create an engine outline from the unit circle
  matrix_identity(&LTM);
  matrix_scale2D(&LTM, 31, 6);

  // make the engine
  for(i=0;i<Resolution;i++) {
    matrix_xformPoint(&LTM, &(unitCircle[i]), &(pt[i]));
  }

  // send one engine to the right location
  matrix_identity(&LTM);
  matrix_translate2D(&LTM, -5, 27);

  // move the engine
  for(i=0;i<Resolution;i++) {
    matrix_xformPoint(&LTM, &(pt[i]), &(ptt[i]));
  }

  // add the polygon
  ship[index] = polygon_createp(Resolution, ptt);
  shipColor[index++] = Blue;

  // send the other engine to the right location
  matrix_identity(&LTM);
  matrix_translate2D(&LTM, -5, -27);

  // move the engine
  for(i=0;i<Resolution;i++) {
    matrix_xformPoint(&LTM, &(pt[i]), &(ptt[i]));
  }

  // add the polygon
  ship[index] = polygon_createp(Resolution, ptt);
  shipColor[index++] = Blue;

  // create an engine
  matrix_identity(&LTM);
  matrix_scale2D(&LTM, 30, 5);

  // make the engine
  for(i=0;i<Resolution;i++) {
    matrix_xformPoint(&LTM, &(unitCircle[i]), &(pt[i]));
  }

  // send one engine to the right location
  matrix_identity(&LTM);
  matrix_translate2D(&LTM, -5, 27);

  // move the engine
  for(i=0;i<Resolution;i++) {
    matrix_xformPoint(&LTM, &(pt[i]), &(ptt[i]));
  }

  // add the polygon
  ship[index] = polygon_createp(Resolution, ptt);
  shipColor[index++] = Grey;

  // send the other engine to the right location
  matrix_identity(&LTM);
  matrix_translate2D(&LTM, -5, -27);

  // move the engine
  for(i=0;i<Resolution;i++) {
    matrix_xformPoint(&LTM, &(pt[i]), &(ptt[i]));
  }

  // add the polygon
  ship[index] = polygon_createp(Resolution, ptt);
  shipColor[index++] = Grey;

  // set up the phaser
  if(firePhase) {
    matrix_identity(&LTM);

    matrix_scale2D(&LTM, 100, 2);

    // orient the phaser
    matrix_rotateZ(&LTM, cos(phaserAngle*M_PI/180.0), sin(phaserAngle*M_PI/180.0));
    
    // translate it to the center of the disk and out
    matrix_translate2D(&LTM, 
           60 + 30 * cos(phaserAngle*M_PI/180.0), 
           30 * sin(phaserAngle*M_PI/180.0) );

    // use the unit square
    for(i=0;i<4;i++) {
      matrix_xformPoint(&LTM, &(unitSquare[i]), &(pt[i]));
    }
    
    // add the polygon
    ship[index] = polygon_createp(4, pt);
    shipColor[index++] = Red;
  }

  matrix_rotateZ(&GTM, cos(theta*M_PI/180.0), sin(theta*M_PI/180.0));

  printf("GTM:\n");
  matrix_print(&GTM, stdout);

  printf("Pre-GTM/VTM\n");
  polygon_print(ship[0], stdout);

  for(i=0;i<index;i++) {

    // multiply the polygon by the global transform matrix
    matrix_xformPolygon(&GTM, ship[i]);
    if(i==0) {
      printf("Pre-VTM\n");
      polygon_print(ship[i], stdout);
    }

    // multiply the polygon by the view transformation matrix
    matrix_xformPolygon(&VTM, ship[i]);

    if(i==0) {
      printf("Pre-draw\n");
      polygon_print(ship[i], stdout);
    }

    // draw the polygon
    polygon_drawFill(ship[i], src, shipColor[i]);
  }

  image_write(src, "space.ppm");


  image_free(src);

  return(0);
}
コード例 #3
0
ファイル: up.c プロジェクト: jwalpuck/graphics
int main(int argc, char *argv[]){
  Image *src; 
  const int rows = 500; 
  const int cols = 500; 
  Circle circ; 
  Color white, yellow, blue,red, sky;
  Point p;
  Point pt[50];
  Polygon *poly;
  int i,j;

  color_set(&yellow, 1.0, 1.0, 0.2);
  color_set(&blue, 0.0, 0.2, 0.4);
  color_set(&red, 0.2,0.0, 0.0);
  color_set(&white, 1.0, 1.0, 1.0);
  color_set(&sky,0.4 ,0.6 , 1.0);

  src = image_create(rows, cols);

 for(i = 0; i< rows; i++) {
    for(j = 0; j<cols; j++){
      image_setColor(src, i, j, sky);

    }
  }

  for(i=0;i<50;i++) {
    float dr = rand() % 15;
    
    point_set2D(&(pt[i]), dr, dr+10);
      circle_set(&circ, pt[i] , 10);
      circle_drawFill(&circ, src, white);

  }



 point_set2D(&(pt[0]), 210, 340);
 point_set2D(&(pt[1]), 280, 340 );
 point_set2D(&(pt[2]), 280, 410 );
 point_set2D(&(pt[3]), 210, 410 );

 poly = polygon_createp(4, pt);
 polygon_drawFill(poly,src, red);

 color_set(&yellow, 0.8, 0.8, 0.0);
 point_set2D(&(pt[0]), 215, 345);
 point_set2D(&(pt[1]), 275, 345 );
 point_set2D(&(pt[2]), 275, 405 );
 point_set2D(&(pt[3]), 215, 405 );

  poly = polygon_createp(4, pt);
  polygon_drawFill(poly,src, yellow);

  printf("writing output\n");
  image_write(src, "minion.ppm");

  image_free(src);

  return(0);
}
コード例 #4
0
ファイル: task6_1.c プロジェクト: Erfi/CS351-ComputerGraphics
int main(int argc, char *argv[]){
	Image* src;
	int offset = 100;
	const int rows = 1000;
  	const int cols = 1000;
  	float r1, r2, r3, r4, r5, r6, r7, r8, r9;
  	int i;
	Color RED;
	Color GREEN;
	Color BLUE;
	Color WHITE;
	Color c1;
	Color c2;
	Color c3;
	Polygon* poly;
	Point points[3];
	char filename[100];
	
	Color_set(&RED, 1.0, 0.0, 0.0);
	Color_set(&GREEN, 0.0, 1.0, 0.0);
	Color_set(&BLUE, 0.0, 0.0, 1.0);
	Color_set(&WHITE, 1.0,1.0,1.0);

	for(i=0; i<offset+1; i++){
		src = image_create(rows, cols);

		//drawing the first triangle
		printf("Preparing and drawing triangle 0\n");
		point_set2D(&points[0], 300, (100 - offset + i));
		point_set2D(&points[1], 700, (100 - offset + i));
		point_set2D(&points[2], 500, (500 - offset + i));

		poly = polygon_createp(3, points);
		r1 = rand()/((double) RAND_MAX);
		r2 = rand()/((double) RAND_MAX);
		r3 = rand()/((double) RAND_MAX);
		r4 = rand()/((double) RAND_MAX);
		r5 = rand()/((double) RAND_MAX);
		r6 = rand()/((double) RAND_MAX);
		r7 = rand()/((double) RAND_MAX);
		r8 = rand()/((double) RAND_MAX);
		r9 = rand()/((double) RAND_MAX);

		Color_set(&c1, r1, r2, r3);
		Color_set(&c2, r4, r5, r6);
		Color_set(&c3, r7, r8, r9);

		polygon_drawFillB_Gradient(poly, src, c1, c2, c3);


		//drawing the second triangle
		printf("Preparing and drawing triangle 1\n");
		point_set2D(&points[0], 700+offset-i, 100-(offset-i)/2);
		point_set2D(&points[1], 900+offset-i, 500-(offset-i)/2);
		point_set2D(&points[2], 500+offset-i, 500-(offset-i)/2);
		

		poly = polygon_createp(3, points);
		r1 = rand()/((double) RAND_MAX);
		r2 = rand()/((double) RAND_MAX);
		r3 = rand()/((double) RAND_MAX);
		r4 = rand()/((double) RAND_MAX);
		r5 = rand()/((double) RAND_MAX);
		r6 = rand()/((double) RAND_MAX);
		r7 = rand()/((double) RAND_MAX);
		r8 = rand()/((double) RAND_MAX);
		r9 = rand()/((double) RAND_MAX);

		Color_set(&c1, r1, r2, r3);
		Color_set(&c2, r4, r5, r6);
		Color_set(&c3, r7, r8, r9);

		polygon_drawFillB_Gradient(poly, src, c1, c2, c3);


		//drawing the third triangle
		printf("Preparing and drawing triangle 2\n");
		point_set2D(&points[0], 900+offset-i, 500+(offset-i)/2);
		point_set2D(&points[1], 700+offset-i, 900+(offset-i)/2);
		point_set2D(&points[2], 500+offset-i, 500+(offset-i)/2);

		poly = polygon_createp(3, points);
		r1 = rand()/((double) RAND_MAX);
		r2 = rand()/((double) RAND_MAX);
		r3 = rand()/((double) RAND_MAX);
		r4 = rand()/((double) RAND_MAX);
		r5 = rand()/((double) RAND_MAX);
		r6 = rand()/((double) RAND_MAX);
		r7 = rand()/((double) RAND_MAX);
		r8 = rand()/((double) RAND_MAX);
		r9 = rand()/((double) RAND_MAX);

		Color_set(&c1, r1, r2, r3);
		Color_set(&c2, r4, r5, r6);
		Color_set(&c3, r7, r8, r9);

		polygon_drawFillB_Gradient(poly, src, c1, c2, c3);


		//drawing the forth triangle
		printf("Preparing and drawing triangle 3\n");
		point_set2D(&points[0], 300, 900 + offset - i);
		point_set2D(&points[1], 700, 900 + offset - i);
		point_set2D(&points[2], 500, 497 + offset - i);

		poly = polygon_createp(3, points);
		r1 = rand()/((double) RAND_MAX);
		r2 = rand()/((double) RAND_MAX);
		r3 = rand()/((double) RAND_MAX);
		r4 = rand()/((double) RAND_MAX);
		r5 = rand()/((double) RAND_MAX);
		r6 = rand()/((double) RAND_MAX);
		r7 = rand()/((double) RAND_MAX);
		r8 = rand()/((double) RAND_MAX);
		r9 = rand()/((double) RAND_MAX);

		Color_set(&c1, r1, r2, r3);
		Color_set(&c2, r4, r5, r6);
		Color_set(&c3, r7, r8, r9);

		polygon_drawFillB_Gradient(poly, src, c1, c2, c3);


		//drawing the fifth triangle
		printf("Preparing and drawing triangle 4\n");
		point_set2D(&points[0], 100-offset+i, 500+(offset-i)/2);
		point_set2D(&points[1], 300-offset+i, 900+(offset-i)/2);
		point_set2D(&points[2], 500-offset+i, 500+(offset-i)/2);

		poly = polygon_createp(3, points);
		r1 = rand()/((double) RAND_MAX);
		r2 = rand()/((double) RAND_MAX);
		r3 = rand()/((double) RAND_MAX);
		r4 = rand()/((double) RAND_MAX);
		r5 = rand()/((double) RAND_MAX);
		r6 = rand()/((double) RAND_MAX);
		r7 = rand()/((double) RAND_MAX);
		r8 = rand()/((double) RAND_MAX);
		r9 = rand()/((double) RAND_MAX);

		Color_set(&c1, r1, r2, r3);
		Color_set(&c2, r4, r5, r6);
		Color_set(&c3, r7, r8, r9);

		polygon_drawFillB_Gradient(poly, src, c1, c2, c3);



	//drawing the sixth triangle
		printf("Preparing and drawing triangle 5\n");
		point_set2D(&points[0], 100-offset+i, 500-(offset-i)/2);
		point_set2D(&points[1], 301-offset+i, 100-(offset-i)/2);
		point_set2D(&points[2], 503-offset+i, 500-(offset-i)/2);

		poly = polygon_createp(3, points);
		r1 = rand()/((double) RAND_MAX);
		r2 = rand()/((double) RAND_MAX);
		r3 = rand()/((double) RAND_MAX);
		r4 = rand()/((double) RAND_MAX);
		r5 = rand()/((double) RAND_MAX);
		r6 = rand()/((double) RAND_MAX);
		r7 = rand()/((double) RAND_MAX);
		r8 = rand()/((double) RAND_MAX);
		r9 = rand()/((double) RAND_MAX);

		Color_set(&c1, r1, r2, r3);
		Color_set(&c2, r4, r5, r6);
		Color_set(&c3, r7, r8, r9);

		polygon_drawFillB_Gradient(poly, src, c1, c2, c3);

		if(i%5==0){
			sprintf(filename, "../images/task6_2_%3.0d.ppm",i);
			image_write(src, filename);
		}
		image_dealloc(src);

	}	
	system("convert -delay 10 -loop 0   ../images/task6_2_*.ppm   ../images/animation.gif");
	system("rm -f ../images/task6_2*");

	//clean up

	polygon_free(poly);
  	image_free(src);


	return 0;
}
コード例 #5
0
ファイル: 3Dthing.c プロジェクト: jwalpuck/graphics
int main(int argc, char *argv[]){
  Image *src;
  Ellipse elip;
  Circle circ;
  Color color, red, pink, yellow;
  Color blue; 
  Line l;
  Point p;
  Point pt[5];
  Polygon *poly;
  int i;

  /*set the colors*/
  color_set(&color, 1.0, 1.0, 1.0);
  color_set(&red, 1.0, 0.0,0.0);
  color_set(&blue, 0.4,1.0,1.0);
  color_set(&pink, 1.0, 0.6, 0.8);
  color_set(&yellow, 1.0, 1.0, 0.4);

  /*build an image*/
  src = image_create( 700,700); 

  /*build the cupcake like I was using turtle graphics*/
  line_set2D(&l, 100,300,200,600);
  line_draw( &l, src, pink );

  line_set2D(&l, 600,300,500,600);
  line_draw( &l, src, pink );

  point_set2D( &p, 600, 350 );
  ellipse_set(&elip, p, 40, 150,0);
  ellipse_draw(&elip, src, pink);

  point_set2D( &p, 300,350 );
  ellipse_set(&elip, p, 80, 250,0);
  ellipse_draw(&elip, src, pink);

  point_set2D( &p, 275,350 );
  ellipse_set(&elip, p, 75, 225,0);
  ellipse_draw(&elip, src, blue);

  point_set2D( &p, 250,350 );
  ellipse_set(&elip, p, 50, 200,0);
  ellipse_draw(&elip, src, blue);

  point_set2D( &p, 225,350 );
  ellipse_set(&elip, p, 25, 175,0);
  ellipse_draw(&elip, src, blue);

  point_set2D( &p, 200,350 );
  ellipse_set(&elip, p, 20, 150,0);
  ellipse_draw(&elip, src, blue);

  point_set2D( &p, 175,350 );
  ellipse_set(&elip, p, 15, 125,0);
  ellipse_draw(&elip, src, blue);

  point_set2D( &p, 150,350 );
  ellipse_set(&elip, p, 5, 75,0);
  ellipse_draw(&elip, src, blue);

  point_set2D( &p, 350, 100 );
  circle_set( &circ, p, 25 );
  circle_draw( &circ, src, red);

  /*write image*/
  image_write( src, "3Dimage.ppm" );

  /*free image*/
  image_free( src );

  /*this time fill the cupcake*/

  src = image_create( 700,700); 

  color_set(&pink, 1.0, 0.6, 0.8);
  point_set2D( &p, 600, 350 );
  ellipse_set(&elip, p, 40, 150,0);
  ellipse_drawFill(&elip, src, pink);
  
  point_set2D(&(pt[0]),100 ,300);
  point_set2D(&(pt[1]),600 ,300);
  point_set2D(&(pt[2]),505 ,600);
  point_set2D(&(pt[3]),198, 600);
  
  poly = polygon_createp(4, pt);
  polygon_drawFill(poly,src, pink);

  color_set(&pink, 1.0, 0.4, 0.8);
  point_set2D( &p, 300,350 );
  ellipse_set(&elip, p, 80, 250,0);
  ellipse_drawFill(&elip, src, pink);

  color_set(&pink, 1.0, 0., 0.8);
  for(i=0; i<10; i++){
    line_set2D(&l, 100-i,300-i,200,600);
    line_draw( &l, src, pink );

    line_set2D(&l, 600-i,300-i,500,600);
    line_draw( &l, src, pink );

    line_set2D(&l, 175-i, 300-i, 225, 623);
    line_draw(&l, src, pink);

    line_set2D(&l, 275-i, 280-i, 305, 636);
    line_draw(&l, src, pink);

    line_set2D(&l, 385-i, 280-i, 385, 640);
    line_draw(&l, src, pink);

    line_set2D(&l, 510-i, 300-i, 450, 630);
    line_draw(&l, src, pink);

  }


  point_set2D( &p, 295,350 );
  ellipse_set(&elip, p, 70, 230,0);
  ellipse_drawFill(&elip, src, yellow);

  color_set(&blue, 0.0,0.8,0.8);

  point_set2D( &p, 275,350 );
  ellipse_set(&elip, p, 75, 220,0);
  ellipse_drawFill(&elip, src, blue);

  color_set(&blue, 0.0,1.0,1.0);

  point_set2D( &p, 250,350 );
  ellipse_set(&elip, p, 50, 200,0);
  ellipse_drawFill(&elip, src, blue);

  color_set(&blue, 0.4,1.0,1.0);

  point_set2D( &p, 225,350 );
  ellipse_set(&elip, p, 25, 175,0);
  ellipse_drawFill(&elip, src, blue);

  color_set(&blue, 0.6,1.0,1.0);

  point_set2D( &p, 200,350 );
  ellipse_set(&elip, p, 20, 150,0);
  ellipse_drawFill(&elip, src, blue);

  color_set(&blue, 0.7,1.0,1.0);

  point_set2D( &p, 175,350 );
  ellipse_set(&elip, p, 15, 125,0);
  ellipse_drawFill(&elip, src, blue);

  color_set(&blue, 0.8,1.0,1.0);

  point_set2D( &p, 150,350 );
  ellipse_set(&elip, p, 5, 75,0);
  ellipse_drawFill(&elip, src, blue);

  point_set2D( &p, 350, 100 );
  circle_set( &circ, p, 25 );
  circle_drawFill( &circ, src, red);

  image_write( src, "3DimageFill.ppm" );

  polygon_free(poly);
  image_free( src );

  return(0);

}
コード例 #6
0
ファイル: test4b.c プロジェクト: imtibbet/CS351
/*
  Program to test polygon functionality using barycentric coordinates
*/
int main(int argc, char *argv[]) {
  Image *src;
  const int rows = 100;
  const int cols = 100;
  Polygon *p;
  Color Red;
  Color White;
  Color Blue;
  Point pt[100];

  color_set(&Red, 0.9, 0.2, 0.1 );
  color_set(&White, 1.0, 1.0, 1.0 );
  color_set(&Blue, 0.2, 0.1, 0.95 );
  
  src = image_create(rows, cols);

  // make a simple square to test proper areas and locations
  // the square ought to be 20x20, include pixel (30,30) and exclude pixel (50, 50)
  point_set2D(&(pt[0]), 30, 30);
  point_set2D(&(pt[1]), 50, 30);
  point_set2D(&(pt[2]), 50, 50);
  point_set2D(&(pt[3]), 30, 50);
  point_set2D(&(pt[4]), 30, 30);

  p = polygon_createp(3, pt);

  printf("drawing polygon 1\n");
  polygon_drawFillB(p, src, Blue);

  polygon_set(p, 3, &(pt[2]) );

  printf("drawing polygon 2\n");
  polygon_drawFillB(p, src, Red);

  point_set2D(&(pt[5]), 60, 20);
  point_set2D(&(pt[6]), 80, 85);
  point_set2D(&(pt[7]), 50, 70);
  polygon_set(p, 3, &(pt[5]));

  printf("drawing polygon 3\n");
  polygon_drawFillB(p, src, White);

  point_set2D(&(pt[8]), 5, 5);
  point_set2D(&(pt[9]), 25, 5);
  point_set2D(&(pt[10]), 25, 25);
  point_set2D(&(pt[11]), 5, 25);
  point_set2D(&(pt[12]), 5, 5);

  polygon_set(p, 3, &(pt[10]) );

  printf("drawing polygon 4\n");
  polygon_drawFillB(p, src, Red);

  polygon_set(p, 3, &(pt[8]));

  printf("drawing polygon 5\n");
  polygon_drawFillB(p, src, Blue);


  printf("writing output\n");
  image_write(src, "test4b.ppm");

  image_free(src);

  return(0);
}
コード例 #7
0
ファイル: test4a.c プロジェクト: imtibbet/CS351
/*
  Program to test polygon functionality
*/
int main(int argc, char *argv[]) {
  Image *src;
  const int rows = 300;
  const int cols = 400;
  Polygon *p;
  Color Red;
  Color Orange;
  Color White;
  Color Blue;
  Point pt[100];
  int i;
  
  srand(42);

  color_set(&Red, 0.9, 0.2, 0.1 );
  color_set(&Orange, 0.95, 0.7, 0.3 );
  color_set(&White, 1.0, 1.0, 1.0 );
  color_set(&Blue, 0.2, 0.1, 0.95 );

  src = image_create(rows, cols);

  // make a simple square to test proper areas and locations
  // the square ought to be 20x20, include pixel (30,30) and exclude pixel (50, 50)
  point_set2D(&(pt[0]), 30, 30);
  point_set2D(&(pt[1]), 50, 30);
  point_set2D(&(pt[2]), 50, 50);
  point_set2D(&(pt[3]), 30, 50);

  p = polygon_createp(4, pt);

  printf("drawing a square\n");
  polygon_drawFill(p, src, Blue);

  // something more interesting
  for(i=0;i<50;i++) {
    float dr = rand() % 20;
    point_set2D(&(pt[i]), 
    200 + cos((float)i * M_PI * 2.0 / 50.0)*(70 + dr),
    150 + sin((float)i * M_PI * 2.0 / 50.0)*(70 + dr));
  }
  polygon_set(p, 50, pt);

  printf("drawing first big polygon\n");
  polygon_drawFill(p, src, Red);

  for(i=0;i<50;i++) {
    float dr = rand() % 15;
    point_set2D(&(pt[i]), 
    200 + cos((float)i * M_PI * 2.0 / 50.0)*(50 + dr),
    150 + sin((float)i * M_PI * 2.0 / 50.0)*(50 + dr));
  }
  polygon_set(p, 50, pt);

  printf("drawing second big polygon\n");
  polygon_drawFill(p, src, Orange);

  for(i=0;i<50;i++) {
    float dr = rand() % 10;
    point_set2D(&(pt[i]), 
    200 + cos((float)i * M_PI * 2.0 / 50.0)*(30 + dr),
    150 + sin((float)i * M_PI * 2.0 / 50.0)*(30 + dr));
  }
  polygon_set(p, 50, pt);

  printf("drawing third big polygon\n");
  polygon_drawFill(p, src, White);

  printf("writing output\n");
  image_write(src, "test4a.ppm");

  image_free(src);

  return(0);
}