Midpoint Circle Algorithm C++ Code
Learn here Midpoint 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 50 |
#include<bits/stdc++.h> #include<graphics.h> using namespace std; void cal(double a, double b, double r) { double x=0, y=r, p; putpixel (a, b+r, WHITE); putpixel (a, b-r, WHITE); putpixel (a-r, b, WHITE); putpixel (a+r, b, WHITE); p=(5/4)-r; while (x<=y) { if(p<0) p+= (2*x)+3; else { p+=(2*(x-y))+5; y--; } x++; putpixel (a+x, b+y, WHITE); putpixel (a-x, b+y, WHITE); putpixel (a+x, b-y, WHITE); putpixel (a-x, b-y, WHITE); putpixel (a+y, b+x, WHITE); putpixel (a+y, b-x, WHITE); putpixel (a-y, b+x, WHITE); putpixel (a-y, b-x, WHITE); delay(100); } } int main() { float x, y,a, b, r, p; int gd = DETECT, gm; initgraph(&gd, &gm, ""); cout<<"ENTER CENTER AND RADIUS "; cout<< "ENTER (a, b) "; cin>>a>>b; cout<<"ENTER r "; cin>>r; cal(a, b, r); getch(); closegraph(); } |
Thanks for practice this code.