0% found this document useful (0 votes)
49 views

Midpoint Circle Algorithm in C

The document contains the source code for drawing a circle using the midpoint circle algorithm in C. It includes functions for drawing the circle that uses pointers to plot pixels on a graph and incrementally updates the x and y coordinates and error to trace out the circle. The main function gets user input for the radius and center coordinates and calls the drawcircle function to display the circle on the graph.

Uploaded by

Chess Blogs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Midpoint Circle Algorithm in C

The document contains the source code for drawing a circle using the midpoint circle algorithm in C. It includes functions for drawing the circle that uses pointers to plot pixels on a graph and incrementally updates the x and y coordinates and error to trace out the circle. The main function gets user input for the radius and center coordinates and calls the drawcircle function to display the circle on the graph.

Uploaded by

Chess Blogs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Source Code of Midpoint Circle Algorithm in C

#include<stdio.h>
#include<graphics.h>
void drawcircle(int x0, int y0, int radius)
{
int x = radius;
int y = 0;
int err = 0;

while (x >= y)
{
putpixel(x0 + x, y0 + y, 7);
putpixel(x0 + y, y0 + x, 7);
putpixel(x0 - y, y0 + x, 7);
putpixel(x0 - x, y0 + y, 7);
putpixel(x0 - x, y0 - y, 7);
putpixel(x0 - y, y0 - x, 7);
putpixel(x0 + y, y0 - x, 7);
putpixel(x0 + x, y0 - y, 7);
if (err <= 0)
{
y += 1;
err += 2*y + 1;
}
if (err > 0)
{
x -= 1;
err -= 2*x + 1;
}
}
}
int main()
{
int gdriver=DETECT, gmode, error, x, y, r;
initgraph(&gdriver, &gmode, "..\\BGI");
printf("This code is coded by Dipesh Giri \n");
printf("Enter radius of circle: ");
scanf("%d", &r);
printf("Enter co-ordinates of center(x and y): ");
scanf("%d%d", &x, &y);
drawcircle(x, y, r);
getch();
return 0;
}

Output:

Result:- Thus, Midpoint Circle Algorithm in C was implemented.

You might also like