Posts

Showing posts with the label circle

Bresenhams Circle Drawing algo

Bresenhams Circle Drawing algo # include<stdio.h> # include<conio.h> # include<graphics.h> # include<math.h> # include<dos.h> void main() { int gd=DETECT,gm; int r,x,y,p,xc,yc; initgraph(&gd,&gm,"C:TCBGI"); cleardevice(); printf("Enter the radius "); scanf("%d",&r); printf(" Enter the centre of circle"); scanf("%d%d",&xc,&yc); line(320,0,320,480); line(0,240,640,240); x=0; y=r; putpixel(xc+x,yc-y,1); p=3-(2*r); for(x=0;x<=y;x++) { if (p<0) { y=y; p=(p+(4*x)+6); } else { y=y-1; p=p+((4*(x-y)+10)); } putpixel(320+xc+x,240-yc-y,1); putpixel(320+xc-x,240-yc-y,2); putpixel(320+xc+x,240-yc+y,3); putpixel(320+xc-x,240-yc+y,4); putpixel(320+xc+y,240-yc-x,5); putpixel(320+xc-y,240-yc-x,6); putpixel(320+xc+y,240-yc+x,7); putpixel(320+xc-y,240-yc+x,8); sleep(1); } getch(); closegraph(); }