Midpoint Ellipse Generation using C
This is only the code and output explanation will follow soon! stay tuned!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include<conio.h> #include<stdio.h> #include<graphics.h> float r,d; int xc,x,yc,y; void main() { int gd=DETECT,gm; initgraph(&gd,&gm,"C:\\TURBOC3\\BGI"); printf("Enter radius: "); scanf("%f",&r); printf("Enter coords of center:"); scanf("%d%d",&xc,&yc); x=0; y=r; putpixel(xc+x,yc+y,2); d = 1.25 - r; do { if(d<0) { x++; d = d+2*x+1; } else { x++; y--; d = d+2*x-2*y+1; } printf("%f %d %d\n",d,x,y); putpixel(xc+x,yc+y,2); putpixel(xc-x,yc+y,3); putpixel(xc+x,yc-y,4); putpixel(xc-x,yc-y,5); putpixel(xc+y,yc+x,6); putpixel(xc-y,yc+x,7); putpixel(xc+y,yc-x,8); putpixel(xc-y,yc-x,9); delay(1000); }while(x<y); getch(); } |
OUTPUT |
Comments
Post a Comment