Bresenham Circle algorithm C++ Code
Learn here Bresenham Circle algorithm C++ Code.
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 39 40 41 42 43 44 45 46 47 48 49 |
#include <stdio.h> #include <graphics.h> void Bres_circle(double x1, double y1, double r) { double x = 0, y = r; double p = 3 - (2 * r); while(x <= y) { putpixel(x1 + x, y1 + y, WHITE); putpixel(x1 - x, y1 + y, WHITE); putpixel(x1 + x, y1 - y, WHITE); putpixel(x1 - x, y1 - y, WHITE); putpixel(x1 + y, y1 + x, WHITE); putpixel(x1 + y, y1 - x, WHITE); putpixel(x1 - y, y1 + x, WHITE); putpixel(x1 - y, y1 - x, WHITE); x=x + 1; if(p<0) p=p + 4*(x) + 6; else { p=p + 4*(x - y) + 10; y=y - 1; } delay(100); } } int main() { double x1, y1, r; int gd = DETECT, gm; initgraph(&gd, &gm, ""); printf("Enter the starting co - ordinates of a center (x, y): "); scanf("%lf %lf", &x1, &y1); printf("Enter the value of radius: "); scanf("%lf", &r); Bres_circle(x1, y1, r); getch(); closegraph(); return 0; } |
Thanks for watching this awesome C++ code.