CG/DDA-circle.cpp

51 lines
955 B
C++

#include <iostream>
#include <graphics.h>
using namespace std;
int main() {
// Taking input for X, Y coordinate and radius of the circle
int cordx, cordy, rad;
cout<<"Enter X coordinate for the circle:\t";
cin>>cordx;
cout<<"Enter Y coordinate for the circle:\t";
cin>>cordy;
cout<<"Enter radius for the circle:\t";
cin>>rad;
// Logic for octent
int gd=DETECT,gm;
initgraph(&gd, &gm, NULL);
int x,y,p;
x=0;
y=rad;
p=3-(2*rad);
do {
putpixel(cordx+x, cordy-y, WHITE);
putpixel(cordx-x, cordy-y, GREEN);
putpixel(cordx+x, cordy+y, YELLOW);
putpixel(cordx-x, cordy+y, RED);
putpixel(cordx+y, cordy+x, WHITE);
putpixel(cordx+y, cordy-x, GREEN);
putpixel(cordx-y, cordy+x, YELLOW);
putpixel(cordx-y, cordy-x, RED);
if (p<0) {
p=p+(4*x)+6;
}
else {
p=p+(4*(x-y))+10;
y=y-1;
}
x=x+1;
} while(x<y);
outtext("Designed and Engineered by KSHITIJ");
delay(50000);
closegraph();
return 0;
}