2023-11-30 00:18:46 +05:30
|
|
|
/*
|
|
|
|
Digital Differential Analyzer (DDA) algorithm for drawing a circle.
|
|
|
|
Code from Computer Graphics (SPPU - Second Year - Computer Engineering - Content) repository on KSKA Git: https://git.kska.io/sppu-se-comp-codes/CG
|
|
|
|
*/
|
|
|
|
|
|
|
|
// BEGINNING OF CODE
|
2023-09-29 23:42:20 +05:30
|
|
|
#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;
|
|
|
|
}
|
2023-11-30 00:18:46 +05:30
|
|
|
// END OF CODE
|