/* draw the polyline using color c */ void polyline_draw(Polyline *p, Image *src, Color colr){ Line l; int i; for (i=0; i< p->numVertex-1; i++){ line_set2D(&l,p->vertex[i].val[0], p->vertex[i].val[1], p->vertex[i+1].val[0], p->vertex[i+1].val[1]); line_draw(&l, src, colr); } }
int main() { int gd=DETECT,gm,min=0,maximum=0,c, location,loc, pp, o,m,counter=0,ix,iy,BC,IC,FC; int p[100]; int color=2; double t,m1; DWORD dwWidth = GetSystemMetrics(SM_CXSCREEN); DWORD dwHeight = GetSystemMetrics(SM_CYSCREEN); initwindow(dwWidth,dwHeight); int x0=dwWidth/2; int y0=dwHeight/2; int i,j,x[50],y[50]; double xc[50],yc[50]; for(i=0; i<dwHeight; i++) putpixel(x0,i,RED); for(j=0; j<dwWidth; j++) putpixel(j,y0,RED); int n; printf("Enter the number of coordinates or vertices \n"); scanf("%d",&n); for(i=0;i<n;i++) { printf("Enter the %dth coordinate\n",i+1); scanf("%d",&x[i]); scanf("%d",&y[i]); } for(i=0;i<n;i++) printf("%d\t%d\n",x[i],y[i]); while(z!=(n-1)) { line_draw(x[z],y[z],x[z+1],y[z+1],x0,y0,color); z++; } //Here printf("Enter interior cordinates ix and iy and fill colour \n"); scanf("%d%d%d",&ix,&iy,&IC); boundaryfill4(x0+ix,y0-iy,IC); delay(40000); cleardevice(); closegraph(); }
//----------------------------------------------------------------------------- void mglCanvasGL::Finish() { #if MGL_USE_DOUBLE #define MGL_GL_TYPE GL_DOUBLE #else #define MGL_GL_TYPE GL_FLOAT #endif if(Prm.size()>0) { PreparePrim(0); /* glVertexPointer(3, MGL_GL_TYPE, sizeof(mglPnt), &(Pnt[0].x)); // something wrong with arrays glNormalPointer(MGL_GL_TYPE, sizeof(mglPnt), &(Pnt[0].u)); glColorPointer(4, MGL_GL_TYPE, sizeof(mglPnt), &(Pnt[0].r)); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_COLOR_ARRAY);*/ int pdef=PDef; mreal ss=pPos, ww=PenWidth; mglPrim p; for(size_t i=0;i<Prm.size();i++) { p=GetPrm(i); PDef=p.n3; pPos=p.s; PenWidth=p.w; register long n1=p.n1, n2=p.n2, n3=p.n3, n4=p.n4; switch(p.type) { /* case 0: mark_draw(Pnt[n1],n4,p.s,0); break; case 1: line_draw(n1,n2); break; case 2: trig_draw(n1,n2,n3); break; case 3: quad_draw(n1,n2,n3,n4); break;*/ case 0: mark_draw(Pnt[n1],n4,p.s,0); break; case 1: line_draw(Pnt[n1],Pnt[n2],0); break; case 2: trig_draw(Pnt[n1],Pnt[n2],Pnt[n3],true,0); break; case 3: quad_draw(Pnt[n1],Pnt[n2],Pnt[n3],Pnt[n4],0); break; case 4: glyph_draw(p,0); break; } } PDef=pdef; pPos=ss; PenWidth=ww; } glFinish(); // glBegin(GL_LINES); glColor3f(0,0,1); glVertex2f(0.1,0.1); glVertex2f(0.9,0.9); glEnd(); }
void ellipse_draw(Ellipse *e, Image *src, Color p){ /* draw an ellipse into src using color p*/ double x, y, px, py, pz; double xCenter, yCenter; double Rx, Ry; /*set center values */ xCenter = e->c.val[0]; yCenter = e->c.val[1]; /*Major axis: Rx*/ Rx = e->ra; /*Minor axis: Ry*/ Ry = e->rb; /*when you are not trying to rotate the ellipse you will be using Bresenhan's Algorithm. It considers the cartesian equation for an ellipse and uses an updated error term to decide on which pixel to draw up or to the side. We will start drawing in the third quadrant to help account for pixel error*/ /*This algorithm, for when a = 0 comes from: ellipseMidpoint, Chapter 3, pg 109-110*/ if(e->a == 0){ /*set initial x and y values*/ x= -1; y= -Ry; /*initial starting error terms!*/ px = 2*Rx*Ry; py = 2*Rx*Rx*-y; printf("x: %f y: %f \n", x,y); printf("px: %f py: %f\n", px, py); printf("Major Axis: %f Minor Axis: %f\n", Rx, Ry); /*set up p, this is necessray because we have to draw an entire quadrant of the ellipse. The symmetry here is not as nice as in a circle*/ pz = (Ry*Ry-(Rx*Rx*Ry)+(Rx*Rx*0.25)+Ry*Ry+py); /*this sets the color of the initial points*/ image_setColor(src, xCenter+x, yCenter+y, p); image_setColor(src, xCenter-x-1, yCenter-y-1, p); image_setColor(src, xCenter+x, yCenter+y, p); image_setColor(src, xCenter-x-1, yCenter+y, p); image_setColor(src, xCenter+x, yCenter-y-1, p); image_setColor(src, xCenter-x-1, yCenter-y-1, p); image_setColor(src, xCenter+x, yCenter+y, p); image_setColor(src, xCenter-x-1, yCenter+y, p); image_setColor(src, xCenter+x, yCenter-y-1, p); image_setColor(src, xCenter-x-1, yCenter-y-1, p); /*wile the points are still below the tangent line with a -1 slope value decrement over x*/ printf("Starting the first half of the ellipse\n"); while (px<py){ x--; // decrement x px = px+ 2*Ry*Ry; if (pz<0){ pz += Ry*Ry+px; }else{ y++;// increment y py = py- 2*Rx*Rx; pz += Ry*Ry +px-py; } /*set the pixel color in the 4 quadrants*/ image_setColor(src, xCenter+x, yCenter+y, p); image_setColor(src, xCenter-x-1, yCenter+y, p); image_setColor(src, xCenter+x, yCenter-y-1, p); image_setColor(src, xCenter-x-1, yCenter-y-1, p); } /* when the points pass the tangent line with slope of -1 now incrementing over y*/ pz = Ry*Ry *(x*x +x) +Rx*Rx* (y*y-2*y +1) -Rx*Rx *Ry*Ry +Rx*Rx -py; printf("Starting the second half of the ellipse\n"); while (y<0){ y++;//increment y py = py - 2*Rx*Rx; if (pz>0){ pz += Rx*Rx-py; }else{ x--;//decrement x px += 2*Ry *Ry; pz += Rx*Rx-py+px; } /*set the pixel color in the 4 quadrants*/ image_setColor(src, xCenter+x, yCenter+y, p); image_setColor(src, xCenter-x-1, yCenter+y, p); image_setColor(src, xCenter+x, yCenter-y-1, p); image_setColor(src, xCenter-x-1, yCenter-y-1, p); } printf("YAY you have drawn an ellipse at angle 0\n"); }else{ printf("You are rotating the ellipse\n"); /*We are going to use a different method to rotate the ellipse*/ /*First: we will build a list of points on the boundary of the ellipse where at the further regions there are more points and we will ultimately connect the lines together to make an ellipse.*/ Point *holdPoints; Point pt; double rmax, numPoints, stepSize; double x1, y1, x2, y2; double xR1, yR1, xR2, yR2, step; double angle; Line l1; int k, m; /*pick which is bigger the Major axis or the Minor axis*/ if (Rx >Ry){ rmax = Rx; }else{ rmax = Ry; } /*convert the angle to polar coordinates*/ angle = (e->a)*(PI/180); printf("angle: %f\n", angle); /*determine the step size based on the fact that we will have Rmax number of points*/ stepSize = 1/(rmax); numPoints = rmax*0.5; /*malloc space for an array of Points*/ holdPoints = malloc(sizeof(Point)*(numPoints)); printf("number of points %f\n", numPoints); printf("size of a step %f\n:", stepSize); /*get the initial point*/ x1 = Rx*cos(0); y1 = Ry*sin(0); point_set2D(&pt, x1,y1); /*add that point to the list*/ holdPoints[0] = pt; printf("x1: %f y1: %f\n", x1, y1); /*loop through the number of points and deterine the point value for the incremented step size*/ for(k = 1; k<numPoints; k++){ step = stepSize*(double)k; x2 = (holdPoints[k-1].val[0] * cos(step))-((Rx/Ry)*holdPoints[k-1].val[1]*sin(step)); y2 = ((Ry/Rx)*holdPoints[k-1].val[0]*sin(step))+(holdPoints[k-1].val[1]*cos(step)); point_set2D(&pt, x2, y2); holdPoints[k]=pt; } /*breaking down matrix math into two equations apply a rotation and translation to the list of points and draw the points at there new location connecting the lines between them*/ for(m=0; m+1<numPoints; m++){ xR1 = holdPoints[m].val[0]*cos(angle)+holdPoints[m].val[1]*sin(angle)*-1 +xCenter; yR1 = holdPoints[m].val[0]*sin(angle)+holdPoints[m].val[1]*cos(angle)+yCenter; xR2 = holdPoints[m+1].val[0]*cos(angle)+holdPoints[m+1].val[1]*sin(angle)*-1 +xCenter; yR2 = holdPoints[m+1].val[0]*sin(angle)+holdPoints[m+1].val[1]*cos(angle)+yCenter; line_set2D(&l1, xR1, yR1, xR2, yR2); line_draw(&l1, src, p); } /*free malloced space for the holdPoints array*/ free(holdPoints); } }
//----------------------------------------------------------------------------- void mglCanvasGL::mark_draw(const mglPnt &q, char type, mreal size, mglDrawReg *d) { mglPnt p0=q,p1=q,p2=q,p3=q; mreal ss=fabs(size); if(type=='.' || ss==0) { if(d) d->PenWidth = ss?ss:sqrt(font_factor/400); pnt_draw(q,d); } else { if(d) { d->PDef = MGL_SOLID_MASK; d->angle = 0; d->PenWidth*=fabs(50*size); if(d->PenWidth<1) d->PenWidth=1; } if(!strchr("xsSoO",type)) ss *= 1.1; switch(type) { case 'P': p0.x = q.x-ss; p0.y = q.y-ss; p1.x = q.x+ss; p1.y = q.y-ss; p2.x = q.x+ss; p2.y = q.y+ss; p3.x = q.x-ss; p3.y = q.y+ss; line_draw(p0,p1,d); line_draw(p1,p2,d); line_draw(p2,p3,d); line_draw(p3,p0,d); case '+': p0.x = q.x-ss; p0.y = q.y; p1.x = q.x+ss; p1.y = q.y; line_draw(p0,p1,d); p2.x = q.x; p2.y = q.y-ss; p3.x = q.x; p3.y = q.y+ss; line_draw(p2,p3,d); break; case 'X': p0.x = q.x-ss; p0.y = q.y-ss; p1.x = q.x+ss; p1.y = q.y-ss; p2.x = q.x+ss; p2.y = q.y+ss; p3.x = q.x-ss; p3.y = q.y+ss; line_draw(p0,p1,d); line_draw(p1,p2,d); line_draw(p2,p3,d); line_draw(p3,p0,d); case 'x': p0.x = q.x-ss; p0.y = q.y-ss; p1.x = q.x+ss; p1.y = q.y+ss; line_draw(p0,p1,d); p2.x = q.x+ss; p2.y = q.y-ss; p3.x = q.x-ss; p3.y = q.y+ss; line_draw(p2,p3,d); break; case 'S': p0.x = q.x-ss; p0.y = q.y-ss; p1.x = q.x-ss; p1.y = q.y+ss; p2.x= q.x+ss; p2.y= q.y+ss; p3.x = q.x+ss; p3.y = q.y-ss; quad_draw(p0,p1,p3,p2,d); case 's': p0.x = q.x-ss; p0.y = q.y-ss; p1.x = q.x+ss; p1.y = q.y-ss; p2.x = q.x+ss; p2.y = q.y+ss; p3.x = q.x-ss; p3.y = q.y+ss; line_draw(p0,p1,d); line_draw(p1,p2,d); line_draw(p2,p3,d); line_draw(p3,p0,d); break; case 'D': p0.x = q.x; p0.y = q.y-ss; p1.x = q.x+ss; p1.y = q.y; p2.x= q.x; p2.y= q.y+ss; p3.x = q.x-ss; p3.y = q.y; quad_draw(p0,p1,p3,p2,d); case 'd': p0.x = q.x; p0.y = q.y-ss; p1.x = q.x+ss; p1.y = q.y; p2.x = q.x; p2.y = q.y+ss; p3.x = q.x-ss; p3.y = q.y; line_draw(p0,p1,d); line_draw(p1,p2,d); line_draw(p2,p3,d); line_draw(p3,p0,d); break; case 'Y': p1.x = q.x; p1.y = q.y-ss; line_draw(q,p1,d); p2.x = q.x-0.8*ss; p2.y = q.y+0.6*ss; line_draw(q,p2,d); p3.x = q.x+0.8*ss; p3.y = q.y+0.6*ss; line_draw(q,p3,d); break; case '*': p0.x = q.x-ss; p0.y = q.y; p1.x = q.x+ss; p1.y = q.y; line_draw(p0,p1,d); p0.x = q.x-0.6*ss; p0.y = q.y-0.8*ss; p1.x = q.x+0.6*ss; p1.y = q.y+0.8*ss; line_draw(p0,p1,d); p0.x = q.x-0.6*ss; p0.y = q.y+0.8*ss; p1.x = q.x+0.6*ss; p1.y = q.y-0.8*ss; line_draw(p0,p1,d); break; case 'T': p0.x = q.x-ss; p0.y = q.y-ss/2; p1.x = q.x+ss; p1.y = q.y-ss/2; p2.x= q.x; p2.y= q.y+ss; trig_draw(p0,p1,p2,false,d); case '^': p0.x = q.x-ss; p0.y = q.y-ss/2; p1.x = q.x+ss; p1.y = q.y-ss/2; p2.x= q.x; p2.y= q.y+ss; line_draw(p0,p1,d); line_draw(p1,p2,d); line_draw(p2,p0,d); break; case 'V': p0.x = q.x-ss; p0.y = q.y+ss/2; p1.x = q.x+ss; p1.y = q.y+ss/2; p2.x= q.x; p2.y= q.y-ss; trig_draw(p0,p1,p2,false,d); case 'v': p0.x = q.x-ss; p0.y = q.y+ss/2; p1.x = q.x+ss; p1.y = q.y+ss/2; p2.x= q.x; p2.y= q.y-ss; line_draw(p0,p1,d); line_draw(p1,p2,d); line_draw(p2,p0,d); break; case 'L': p0.x = q.x+ss/2; p0.y = q.y+ss; p1.x = q.x+ss/2; p1.y = q.y-ss; p2.x= q.x-ss; p2.y= q.y; trig_draw(p0,p1,p2,false,d); case '<': p0.x = q.x+ss/2; p0.y = q.y+ss; p1.x = q.x+ss/2; p1.y = q.y-ss; p2.x= q.x-ss; p2.y= q.y; line_draw(p0,p1,d); line_draw(p1,p2,d); line_draw(p2,p0,d); break; case 'R': p0.x = q.x-ss/2; p0.y = q.y+ss; p1.x = q.x-ss/2; p1.y = q.y-ss; p2.x= q.x+ss; p2.y= q.y; trig_draw(p0,p1,p2,false,d); case '>': p0.x = q.x-ss/2; p0.y = q.y+ss; p1.x = q.x-ss/2; p1.y = q.y-ss; p2.x= q.x+ss; p2.y= q.y; line_draw(p0,p1,d); line_draw(p1,p2,d); line_draw(p2,p0,d); break; case 'O': /* for(long j=long(-ss);j<=long(ss);j++) for(long i=long(-ss);i<=long(ss);i++) { register long x=long(q.x)+i, y=long(q.y)+j; if(i*i+j*j>=ss*ss || !d || x<d->x1 || x>d->x2 || y<d->y1 || y>d->y2) continue; pnt_plot(x,y,q.z+1,cs,d->ObjId); }*/ case 'o': for(long i=0;i<=20;i++) // TODO copy from mark_pix()?! { p0 = p1; p1.x = q.x+ss*cos(i*M_PI/10); p1.y = q.y+ss*sin(i*M_PI/10); if(i>0) line_draw(p0,p1,d); } break; case 'C': pnt_draw(q,d); for(long i=0;i<=20;i++) { p0 = p1; p1.x = q.x+ss*cos(i*M_PI/10); p1.y = q.y+ss*sin(i*M_PI/10); if(i>0) line_draw(p0,p1,d); } break; } } }
int main(int argc, char *argv[]) { Point start[NUMLINES], end[NUMLINES]; Color color[NUMLINES]; Image *src; Line line; long i,j; Color white; double tstart, tend; long numLines; double sum, dx, dy; struct timeb tp; color_set( &white, 1.0, 1.0, 1.0); // allocate an image ROWS by COLS src = image_create(ROWS, COLS); if(!src) { fprintf(stderr, "unable to allocate memory\n"); exit(0); } // Initialize the image to all white for(i=0;i<src->rows;i++) { for(j=0;j<src->cols;j++) { image_setColor(src, i, j, white ); } } // Pre-calculate the line endpoints and colors so we don't have to // call the random() function inside the main drawing loop. sum = 0.0; for(i=0;i<NUMLINES;i++) { int tsx, tsy, tex, tey; tsx = (int)(drand48() * COLS); tsy = (int)(drand48() * ROWS); tex = (int)(drand48() * COLS); tey = (int)(drand48() * ROWS); point_set2D(&(start[i]), tsx, tsy ); point_set2D(&(end[i]), tex, tey ); color[i].c[0] = drand48(); color[i].c[1] = drand48(); color[i].c[2] = drand48(); dx = tsx - tex; dy = tsy - tey; sum += sqrt(dx * dx + dy * dy); } sum /= NUMLINES; printf("Average line length = %.1lf\n", sum); // Start drawing lines ftime( &tp ); tstart = tp.time + tp.millitm / 1000.0; for(i=0,numLines=0; numLines < 5000000;numLines++, i++) { i = i % NUMLINES; line_set(&line, start[i], end[i]); line_draw(&line, src, color[i]); } ftime( &tp ); tend = tp.time + tp.millitm / 1000.0; // print out the result printf("%.2lf lines per second\n", numLines / (tend - tstart) ); // write out the image image_write(src, "lines.ppm"); // free the image data image_free(src); return(0); }
/* * Draw the module into the image using the given view transformation matrix [VTM], * Lighting and DrawState by traversing the list of Elements. * (For now, Lighting can be an empty structure.) */ void module_draw(Module *md, Matrix *VTM, Matrix *GTM, DrawState *ds, Lighting *lighting, Image *src){ /* for antialiasing Module *thickLineMod = module_create(); Element *thickLineE; float dx, dy, dz, lineLength; Vector u, v, w;*/ // all locally needed variables Matrix LTM, tempGTM; Line tempLine; DrawState *tempds = drawstate_create(); Point tempPointLTM, tempPointGTM, tempPointVTM; Polyline *tempPolyline = polyline_create(); Polygon *tempPolygon = polygon_create(); Element *e = md->head; matrix_identity(<M); // loop until the end of the linked list is reached while(e){ //printf("Handling type %d\n", e->type); // draw based on type switch(e->type){ case ObjNone: break; case ObjPoint: //printf("drawing point "); // copy, xform, normalize, draw matrix_xformPoint(<M, &(e->obj.point), &tempPointLTM); matrix_xformPoint(GTM, &tempPointLTM, &tempPointGTM); matrix_xformPoint(VTM, &tempPointGTM, &tempPointVTM); point_normalize(&(tempPointVTM)); //point_print(&tempPointVTM, stdout); point_draw(&tempPointVTM, src, ds->color); break; case ObjLine: line_copy(&tempLine, &(e->obj.line)); //printf("drawing line "); // copy, xform, normalize, draw matrix_xformLine(<M, &tempLine); matrix_xformLine(GTM, &tempLine); matrix_xformLine(VTM, &tempLine); line_normalize(&tempLine); line_draw(&tempLine, src, ds->color); //line_print(&tempLine, stdout); /*if(antialias){ dx = tempLine.b.val[0]-tempLine.a.val[0]; dy = tempLine.b.val[1]-tempLine.a.val[1]; dz = tempLine.b.val[2]-tempLine.a.val[2]; lineLength = sqrt(dx*dx+dy*dy+dz*dz); module_scale( thickLineMod, 1, lineLength, 1 ); vector_set(&v, dx, dy, dz); vector_normalize(&v); vector_set(&u, -dz, dx, dy); vector_cross(&u, &v, &w); vector_cross(&v, &w, &u); vector_normalize(&u); vector_normalize(&w); module_rotateXYZ( thickLineMod, &u, &v, &w ); module_translate( thickLineMod, tempLine.a.val[0], tempLine.a.val[1], tempLine.a.val[2] ); module_cylinder( thickLineMod, 4, 1, 1, 0, 0, 0 ); thickLineE = element_init(ObjModule, thickLineMod); thickLineE->next = e->next; e->next = thickLineE; }*/ break; case ObjPolyline: //printf("drawing polyline "); // copy, xform, normalize, draw polyline_copy(tempPolyline, &(e->obj.polyline)); matrix_xformPolyline(<M, tempPolyline); matrix_xformPolyline(GTM, tempPolyline); matrix_xformPolyline(VTM, tempPolyline); polyline_normalize(tempPolyline); //polyline_print(tempPolyline, stdout); polyline_draw(tempPolyline, src, ds->color); break; case ObjPolygon: //printf("drawing polygon "); // copy, xform, normalize, draw polygon_copy(tempPolygon, &(e->obj.polygon)); matrix_xformPolygon(<M, tempPolygon); matrix_xformPolygon(GTM, tempPolygon); matrix_xformPolygon(VTM, tempPolygon); polygon_normalize(tempPolygon); //polygon_print(tempPolygon, stdout); polygon_draw(tempPolygon, src, ds); break; case ObjColor: drawstate_setColor(ds, e->obj.color); break; case ObjBodyColor: break; case ObjSurfaceColor: break; case ObjSurfaceCoeff: break; case ObjLight: break; case ObjIdentity: matrix_identity(<M); break; case ObjMatrix: matrix_multiply(&(e->obj.matrix), <M, <M); break; case ObjModule: matrix_multiply(GTM, <M, &tempGTM); drawstate_copy(tempds, ds); module_draw(e->obj.module, VTM, &tempGTM, tempds, lighting, src); break; default: printf("ObjectType %d is not handled in module_draw\n",e->type); } // advance traversal e = e->next; } // clean up polygon_free(tempPolygon); polyline_free(tempPolyline); free(tempds); }
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); }