void circle(const Point& center, int radius, const Color& color, bool filled) { if (filled) gdImageFilledEllipse(im_, SCALEX(center.x), SCALEY(center.y), SCALER(radius*2), SCALER(radius*2), color2gd(color)); else gdImageArc(im_, SCALEX(center.x), SCALEY(center.y), SCALER(radius*2), SCALER(radius*2), 0, 360, color2gd(color)); }
void circle(const Point& center, int radius, const Color& color, bool filled) { if (filled) gdImageFilledEllipse(im_, center.x, center.y, radius*2, radius*2, color2gd(color)); else gdImageArc(im_, center.x, center.y, radius*2, radius*2, 0, 360, color2gd(color)); }
static void gd_ellipse(point p, int rx, int ry, int filled) { pointf mp; int i; int style[40]; /* need 2* size for arcs, I don't know why */ int pen, width; gdImagePtr brush = NULL; if (cstk[SP].pen != P_NONE) { if (cstk[SP].pen == P_DASHED) { for (i = 0; i < 20; i++) style[i] = cstk[SP].pencolor; for (; i < 40; i++) style[i] = gdTransparent; gdImageSetStyle(im, style, 40); pen = gdStyled; } else if (cstk[SP].pen == P_DOTTED) { for (i = 0; i < 2; i++) style[i] = cstk[SP].pencolor; for (; i < 24; i++) style[i] = gdTransparent; gdImageSetStyle(im, style, 24); pen = gdStyled; } else { pen = cstk[SP].pencolor; } #if 1 /* use brush instead of Thickness to improve outline appearance */ gdImageSetThickness(im, WIDTH_NORMAL); if (cstk[SP].penwidth != WIDTH_NORMAL) { width = cstk[SP].penwidth; brush = gdImageCreate(width,width); gdImagePaletteCopy(brush, im); gdImageFilledRectangle(brush, 0,0,width-1, width-1, cstk[SP].pencolor); gdImageSetBrush(im, brush); if (pen == gdStyled) pen = gdStyledBrushed; else pen = gdBrushed; } #else width = cstk[SP].penwidth; gdImageSetThickness(im, width); #endif if (Rot) {int t; t = rx; rx = ry; ry = t;} mp.x = p.x; mp.y = p.y; mp = gdpt(mp); if (filled) { gdImageFilledEllipse(im, ROUND(mp.x), ROUND(mp.y), ROUND(Zoom*(rx + rx)), ROUND(Zoom*(ry + ry)), cstk[SP].fillcolor); } gdImageArc(im, ROUND(mp.x), ROUND(mp.y), ROUND(Zoom*(rx + rx)), ROUND(Zoom*(ry + ry)), 0, 360, pen); if (brush) gdImageDestroy(brush); } }
result_t Image::filledEllipse(int32_t x, int32_t y, int32_t width, int32_t height, int32_t color) { if (width <= 0 || height <= 0) return CHECK_ERROR(CALL_E_INVALIDARG); if (!m_image) return CHECK_ERROR(CALL_E_INVALID_CALL); gdImageFilledEllipse(m_image, x, y, width, height, color); return 0; }
void doFilledEllipse(FILE *stream) { float cx, cy, w, h; int c; cx = getFloat(stream); cy = getFloat(stream); w = getFloat(stream); h = getFloat(stream); c = getColor(getNumber(stream)); gdImageFilledEllipse(image, viewx(cx), viewy(cy), scalex(w), scaley(h), c); }
int renderEllipseSymbolGD(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style) { /* check for trivial cases - 1x1 and 2x2, GD does not do these well */ gdImagePtr ip; int w,h,fc,oc; if(!(ip = MS_IMAGE_GET_GDIMAGEPTR(img))) return MS_FAILURE; SETPEN(ip, style->color); SETPEN(ip, style->outlinecolor); fc = style->color ? style->color->pen : -1; oc = style->outlinecolor ? style->outlinecolor->pen : -1; if(oc==-1 && fc ==-1) { return MS_SUCCESS; } w = symbol->sizex * style->scale; h = symbol->sizey * style->scale; if(w==1 && h==1) { if(fc >= 0) gdImageSetPixel(ip, x, y, fc); else gdImageSetPixel(ip, x, y, oc); return MS_SUCCESS; } if(w==2 && h==2) { if(oc >= 0) { gdImageSetPixel(ip, x, y, oc); gdImageSetPixel(ip, x, y+1, oc); gdImageSetPixel(ip, x+1, y, oc); gdImageSetPixel(ip, x+1, y+1, oc); } else { gdImageSetPixel(ip, x, y, fc); gdImageSetPixel(ip, x, y+1, fc); gdImageSetPixel(ip, x+1, y, fc); gdImageSetPixel(ip, x+1, y+1, fc); } return MS_SUCCESS; } if(symbol->filled) { if(fc >= 0) gdImageFilledEllipse(ip, x, y, w, h, fc); if(oc >= 0) gdImageArc(ip, x, y, w, h, 0, 360, oc); } else { if(fc < 0) fc = oc; /* try the outline color */ gdImageArc(ip, x, y, w, h, 0, 360, fc); } return MS_SUCCESS; }
int main() { gdImagePtr im, im2; int error = 0; im = gdImageCreateTrueColor(width, width); gdImageFilledRectangle(im, 0,0, width, width, 0xFF0000); gdImageColorTransparent(im, 0xFF0000); gdImageFilledEllipse(im, width/2, width/2, width - 20, width - 10, 0x50FFFFFF); im2 = gdImageCreateTrueColor(width, width); gdImageCopyRotated(im2, im, width / 2, width / 2, 0,0, width, width, 60); if (!gdAssertImageEqualsToFile("gdimagecopyrotated/bug00020_exp.png", im2)) { error = 1; } gdImageDestroy(im2); gdImageDestroy(im); return error; }
int renderLineGD(imageObj *img, shapeObj *p, strokeStyleObj *stroke) { gdImagePtr ip; int c; gdImagePtr brush=NULL; if(!img || !p || !stroke) return MS_FAILURE; if(!(ip = MS_IMAGE_GET_GDIMAGEPTR(img))) return MS_FAILURE; SETPEN(ip, stroke->color); c = stroke->color->pen; if(stroke->patternlength > 0) { int *style; int i, j, k=0; int sc; for(i=0; i<stroke->patternlength; i++) k += MS_NINT(stroke->pattern[i]); style = (int *) malloc (k * sizeof(int)); MS_CHECK_ALLOC(style, k * sizeof(int), MS_FAILURE); sc = c; /* start with the color */ k=0; for(i=0; i<stroke->patternlength; i++) { for(j=0; j<MS_NINT(stroke->pattern[i]); j++, k++) { style[k] = sc; } sc = ((sc==c)?gdTransparent:c); } gdImageSetStyle(ip, style, k); free(style); c = gdStyled; } if(stroke->width > 1) { int brush_fc; brush = gdImageCreate(ceil(stroke->width), ceil(stroke->width)); gdImageColorAllocate(brush, gdImageRed(ip,0), gdImageGreen(ip, 0), gdImageBlue(ip, 0)); gdImageColorTransparent(brush,0); brush_fc = gdImageColorAllocate(brush, gdImageRed(ip,stroke->color->pen), gdImageGreen(ip,stroke->color->pen), gdImageBlue(ip,stroke->color->pen)); gdImageFilledEllipse(brush,MS_NINT(brush->sx/2),MS_NINT(brush->sy/2), MS_NINT(stroke->width),MS_NINT(stroke->width), brush_fc); gdImageSetBrush(ip, brush); if(stroke->patternlength > 0) { c = gdStyledBrushed; } else { c = gdBrushed; } } /* finally draw something */ imagePolyline(ip, p, c); /* clean up */ if(stroke->width>1) { gdImageDestroy(brush); } return MS_SUCCESS; }
static void vrml_ellipse(GVJ_t * job, pointf * A, int filled) { FILE *out = job->output_file; obj_state_t *obj = job->obj; node_t *n; edge_t *e; double z = obj->z; double rx, ry; int dx, dy; pointf npf, nqf; point np; int pen; gdImagePtr brush = NULL; rx = A[1].x - A[0].x; ry = A[1].y - A[0].y; switch (obj->type) { case ROOTGRAPH_OBJTYPE: case CLUSTER_OBJTYPE: break; case NODE_OBJTYPE: n = obj->u.n; if (shapeOf(n) == SH_POINT) { doSphere (job, n, A[0], z, rx, ry); return; } pen = set_penstyle(job, im, brush); npf = vrml_node_point(job, n, A[0]); nqf = vrml_node_point(job, n, A[1]); dx = ROUND(2 * (nqf.x - npf.x)); dy = ROUND(2 * (nqf.y - npf.y)); PF2P(npf, np); if (filled) gdImageFilledEllipse(im, np.x, np.y, dx, dy, color_index(im, obj->fillcolor)); gdImageArc(im, np.x, np.y, dx, dy, 0, 360, pen); if (brush) gdImageDestroy(brush); fprintf(out, "Transform {\n"); fprintf(out, " translation %.3f %.3f %.3f\n", A[0].x, A[0].y, z); fprintf(out, " scale %.3f %.3f 1\n", rx, ry); fprintf(out, " children [\n"); fprintf(out, " Transform {\n"); fprintf(out, " rotation 1 0 0 1.57\n"); fprintf(out, " children [\n"); fprintf(out, " Shape {\n"); fprintf(out, " geometry Cylinder { side FALSE }\n"); fprintf(out, " appearance Appearance {\n"); fprintf(out, " material Material {\n"); fprintf(out, " ambientIntensity 0.33\n"); fprintf(out, " diffuseColor 1 1 1\n"); fprintf(out, " }\n"); fprintf(out, " texture ImageTexture { url \"node%d.png\" }\n", n->id); fprintf(out, " }\n"); fprintf(out, " }\n"); fprintf(out, " ]\n"); fprintf(out, " }\n"); fprintf(out, " ]\n"); fprintf(out, "}\n"); break; case EDGE_OBJTYPE: e = obj->u.e; /* this is gruesome, but how else can we get z coord */ if (DIST2(A[0], ND_coord_i(e->tail)) < DIST2(A[0], ND_coord_i(e->head))) z = obj->tail_z; else z = obj->head_z; fprintf(out, "Transform {\n"); fprintf(out, " translation %.3f %.3f %.3f\n", A[0].x, A[0].y, z); fprintf(out, " children [\n"); fprintf(out, " Shape {\n"); fprintf(out, " geometry Sphere {radius %.3f }\n", (double) rx); fprintf(out, " appearance USE E%d\n", e->id); fprintf(out, " }\n"); fprintf(out, " ]\n"); fprintf(out, "}\n"); } }
int main(int argc, char* argv[]) { if(argc<3) { fprintf(stderr,"Blad wywolania. TODO opis bledu\n"); return 1; }; FILE* plik; plik=fopen(argv[1],"r"); if(!plik) { fprintf(stderr,"Can't open file %s\n",argv[1]); return 2; }; int size; fscanf(plik,"%d",&size); if(!(size>0)) { fprintf(stderr,"Data error. Wrong number of blocks\n"); return 3; }; tab=(klocek*)malloc(size*sizeof(klocek)); memset(tab,0,sizeof(klocek)*size); int i; for(i=0;i<size;i++) { int nr; float w,h; fscanf(plik,"%d %f %f",&nr,&w,&h); tab[nr].itsW=w; tab[nr].itsH=h; // printf("Mam klocka z parametrow: %f %f %d %f\n",tab[nr].itsW,tab[nr].itsH,tab[nr].itsObrot,tab[nr].itsX); }; fclose(plik); plik=fopen(argv[2],"r"); wejscie* data=(wejscie*)malloc(size*sizeof(wejscie)); for(i=0;i<size;i++) { fscanf(plik,"%d %d %f",&data[i].itsNr,&data[i].itsObr,&data[i].itsX); }; fclose(plik); float posX=50; float posY=size*20; int j=0; int color[4]; gdImagePtr im; for(j=1;j<size;j++) { for(i=j;i>0;i--) { float posX=50; float posY=0; float srodek=0; float srodek_suma=0; im=gdImageCreate(100,j*10+100); int white=gdImageColorAllocate(im,255,255,255); color[0]=gdImageColorAllocate(im,255,0,0); color[1]=gdImageColorAllocate(im,0,255,0); color[2]=gdImageColorAllocate(im,0,0,255); color[3]=gdImageColorAllocate(im,255,0,255); int num=0; int k; for(k=j,num=0;k>=i;k--,num++) { float w=data[k].itsObr?tab[data[k].itsNr].itsH:tab[data[k].itsNr].itsW; float h=data[k].itsObr?tab[data[k].itsNr].itsW:tab[data[k].itsNr].itsH; h=10; gdImageFilledRectangle(im,posX,posY,posX+w,posY+h,color[k%3]); srodek_suma+=posX+w/2.0; posX-=data[k].itsX; posY+=h; }; srodek=srodek_suma/(float)(num); float w=data[k].itsObr?tab[data[k].itsNr].itsH:tab[data[k].itsNr].itsW; float h=data[k].itsObr?tab[data[k].itsNr].itsW:tab[data[k].itsNr].itsH; gdImageFilledRectangle(im,posX,posY,posX+w,posY+h,color[k%3]); gdImageFilledEllipse(im,srodek,posY+2.5,2,2,color[3]); char nazwa[255]; sprintf(nazwa,"details/rys_%03d_%03d.png",j,k); printf("Nazwa: %s\n",nazwa); plik=fopen(nazwa,"w"); if(!plik) { printf("problem otwarci pliku\n"); }; gdImagePng(im,plik); fclose(plik); gdImageDestroy(im); }; }; im=gdImageCreate(100,size*20); int white=gdImageColorAllocate(im,255,255,255); color[0]=gdImageColorAllocate(im,255,0,0); color[1]=gdImageColorAllocate(im,0,255,0); color[2]=gdImageColorAllocate(im,0,0,255); color[3]=gdImageColorAllocate(im,0,255,255); plik=fopen(argv[2],"r"); for(i=0;i<size;i++) { int nr; int obr; float dx; fscanf(plik,"%d %d %f",&nr,&obr,&dx); float w=obr?tab[nr].itsH:tab[nr].itsW; float h=obr?tab[nr].itsW:tab[nr].itsH; posX+=dx; posY-=h; gdImageFilledRectangle(im,posX,posY,posX+w,posY+h,color[i%3]); }; fclose(plik); plik=fopen("rys.png","w"); gdImagePng(im,plik); fclose(plik); gdImageDestroy(im); };