-
Notifications
You must be signed in to change notification settings - Fork 342
/
CG2.cpp
70 lines (70 loc) · 1.19 KB
/
CG2.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*Write C++/Java program to draw circle using Bresenham‘s algorithm. Inherit pixel class.*/
#include<iostream>
#include<graphics.h>
#include<cstdlib>
#include<math.h>
#include<stdio.h>
using namespace std;
class Pixel
{
protected:
int xc,yc,r;
public:
Pixel()
{
xc=0;
yc=0;
r=0;
};
};
class Circle: public Pixel
{
public:
void drawCircle()
{
int x,y,pk;
printf("*** Bresenham's Circle Drawing Algorithm in C++ ***\n");
cout<<"Enter the value of center_x\t";
cin>>xc;
cout<<"Enter the value of yc\t";
cin>>yc;
cout<<"Enter the Radius of circle\t";
cin>>r;
x=0;
y=r;
//putpixel(center_x+x,yc-y,1);
pk=3-(2*r);
for(x=0;x<=y;x++)
{
if (pk<0)
{
y=y;
pk=(pk+(4*x)+6);
}
else
{
y=y-1;
pk=pk+((4*(x-y)+10));
}
putpixel(xc+x,yc-y,7);
putpixel(xc-x,yc-y,7);
putpixel(xc+x,yc+y,7);
putpixel(xc-x,yc+y,7);
putpixel(xc+y,yc-x,7);
putpixel(xc-y,yc-x,7);
putpixel(xc+y,yc+x,7);
putpixel(xc-y,yc+x,7);
delay(100);
}
};
};
int main()
{
Circle c;
int gd=DETECT,gm;
initgraph(&gd,&gm,NULL);
c.drawCircle();
std::system("gnome-screenshot -f breCircle.jpg");
delay(2000);
return 0;
}