Mid Point Circle Drawing Program (C++)
#include<conio.h>
#include<Graphics.h>
#include<stdio.h>
void main() {
int gd = DETECT, gm;
initgraph (&gd, &gm, "C:\\TC\\BGI");
int xc, yc, x, y, r, D;
printf ("Enter Radius of Circle: ");
scanf ("%d", &r);
printf ("Enter coordinates of centre of Circle: ");
scanf ("%d%d", &xc, &yc);
x=0; y=r;
D=5/4-r;
//Initial Decision parameter
while (x<=y) {
putpixel (y+xc, x+yc, 15 ); //……octet-1
putpixel (x+xc, y+yc, 15 ); //……octet-2
putpixel (-x+xc, y+yc, 15 ); //……octet-3
putpixel (-y+xc, x+yc, 15 ); //……octet-4
putpixel (-y+xc, -x+yc, 15 ); //……octet-5
putpixel (-x+xc, -y+yc, 15 ); //……octet-6
putpixel (x+xc, -y+yc, 15 ); //……octet-7
putpixel (y+xc, -x+yc, 15 ); //……octet-8
if (D<0) {
D= D+(2*x)+1; //Next Decision Parameter
x++;
}
else {
D= D+(2*x)-(2*y)+1; //Next Decision Parameter
x++;
y--;
}
}
getch ();
closegraph ();
Program of Bresenhams circle drawing programBresenham Line drawing derivation
The Midpoint Circle Drawing program in C++ is a great way to understand graphics algorithms! It’s fascinating to see how such techniques are implemented. Tools like rancherdesktop can further enhance the graphics programming experience. Thanks for the informative post!
ReplyDeleteNice explanation here! I’ve been experimenting with this algorithm using yuzu ea just to test pixel rendering speed. It’s wild how something so old still works perfectly for simple graphics.
ReplyDelete