Midpoint circle drawing algorithm snippet provided in this Article. If you are interested to see the algorithm ( Go here) .

## Program to draw a circle using the midpoint circle drawing algorithm

Program:

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 |
#include<graphics.h> #include<conio.h> #include<stdio.h> void main() { int x,y,x_mid,y_mid,radius,dp; int g_mode,g_driver=DETECT; clrscr(); initgraph(&g_driver,&g_mode,"C:\\TURBOC3\\BGI"); printf("*********** MID POINT Circle drawing algorithm ********\n\n"); printf("\nenter the coordinates= "); scanf("%d %d",&x_mid,&y_mid); printf("\n now enter the radius ="); scanf("%d",&radius); x=0; y=radius; dp=1-radius; do { putpixel(x_mid+x,y_mid+y,YELLOW); putpixel(x_mid+y,y_mid+x,YELLOW); putpixel(x_mid-y,y_mid+x,YELLOW); putpixel(x_mid-x,y_mid+y,YELLOW); putpixel(x_mid-x,y_mid-y,YELLOW); putpixel(x_mid-y,y_mid-x,YELLOW); putpixel(x_mid+y,y_mid-x,YELLOW); putpixel(x_mid+x,y_mid-y,YELLOW); if(dp<0) { dp+=(2*x)+1; } else{ y=y-1; dp+=(2*x)-(2*y)+1; } x=x+1; }while(y>x); getch(); } |

Output: