void main() { int cx, cy, rx, ry; printf("Enter the center "); scanf("%d%d", &cx, &cy); printf("x radius : "); scanf("%d", &rx); printf("y radius : "); scanf("%d", &ry); long rx2 = (long) rx * rx; long ry2 = (long) ry * ry; long trx2 = 2 * rx2; long try2 = 2 * ry2; long p, x = 0, y = ry; long px = 0; long py = trx2 * y; p = (long) ((ry2 - (rx2 * ry) + (0.25 * rx2)) + 0.5); int gd = DETECT, gm = DETECT; initgraph(&gd, &gm, ""); cleardevice(); putpixel(cx, cy, 15); while (px < py) { plotpoints(cx, cy, x, y); x++; px += try2; if (p < 0) p += ry2 + px; else { y--; py -= trx2; p += ry2 + px - py; } } py = trx2 * y; px = try2 * x; p = (long) ((ry2 * (x + 0.5) * (x + 0.5) + rx2 * (y - 1) * (y - 1) - rx2 * ry2) + 0.5); while (y >= 0) { plotpoints(cx, cy, x, y); y--; py -= trx2; if (p > 0) p += rx2 - py; else { x++; px += try2; p += rx2 - py + px; } } getch(); }
void bellipse(int xc, int yc, float r1,float r2) { float p, slope=0, sqr; int x, y, lasty; if (r1!=0) sqr=(r2*r2)/(r1*r1); else return; p = 2*sqr-2*r2+1; x = 0; y = r2; while(y && slope>-1) { plotpoints(xc,yc,x,y); if (p<0) p+=4*sqr*x+6*sqr; else { p+=4*sqr*x-4*y+6*sqr+4; y--; } x++; if(y==0 || sqr==0) return; slope=(float) x/y*sqr*(-1); } lasty=y, y=0, x=r1; if (r2!=0) sqr=(r1*r1)/(r2*r2); else return; slope=-2; p=2*sqr-2*r1+1; while(x && y<=lasty) { plotpoints(xc,yc,x,y); if (p<0) p+=4*sqr*y+6*sqr; else { p+=4*sqr*y-4*x+6*sqr+4; x--; } y++; } }