draw the circle – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Sun, 21 Aug 2022 07:21:16 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://programmerbay.com/wp-content/uploads/2019/09/cropped-without-transparent-32x32.jpg draw the circle – Programmerbay https://programmerbay.com 32 32 C Program to Draw a Circle using Midpoint Circle Drawing Algorithm https://programmerbay.com/program-to-draw-a-circle-using-midpoint-circle-drawing-algorithm/ https://programmerbay.com/program-to-draw-a-circle-using-midpoint-circle-drawing-algorithm/#respond Fri, 29 Jul 2022 07:58:45 +0000 https://www.programmerbay.com/?p=2180 An algorithm that is used to find points required for plotting and converting a circle over display. Midpoint circle drawing algorithm snippet provided in this Article. If you are interested to see the algorithm ( Go here) .

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

Program:

#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:

circle drawing algorithm

]]>
https://programmerbay.com/program-to-draw-a-circle-using-midpoint-circle-drawing-algorithm/feed/ 0