-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.cpp
More file actions
110 lines (85 loc) · 1.91 KB
/
2.cpp
File metadata and controls
110 lines (85 loc) · 1.91 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//Write C++/Java program to draw circle using Bresenham‘s algorithm. Inherit pixel class.
#include<graphics.h>
#include<iostream>
using namespace std;
class pixel //Base Class
{
protected: int x1,y1;//center of circle
public:
pixel() //constructor
{
x1=0;y1=0;
}
void setoff(int xx,int yy) //set co-ordinates
{
x1=xx;
y1=yy;
}
};
class dcircle: public pixel // Derived Class
{
private: int r; //radius of circle
public:
dcircle():pixel() //constructor
{
r=0;
}
void setrad(int z) //set radious
{
r=z;
}
void drawbc() //Bresenham's Circle
{
int i,x,y;
float d;
x=0, y=r;
d = 3 - 2*r; //decision variable
do
{
putpixel(x1+x, y1+y,15);
putpixel(x1+y, y1+x,15);
putpixel(x1+y, y1-x,15);
putpixel(x1+x, y1-y,15);
putpixel(x1-x, y1-y,15);
putpixel(x1-y, y1-x,15);
putpixel(x1-y, y1+x,15);
putpixel(x1-x, y1+y,15);
if(d<=0)
{
x = x + 1;
d = d + (4*x) + 6;
}
else
{
x = x + 1;
y = y - 1;
d = d + (4*x-4*y) + 10;
}
}while(x<=y);
}//Function Closed
};
int main()
{
int gd=DETECT,gm;
int i, x, y, r,ch, xmax,ymax,xmid,ymid;
float a,b;
char ans;
dcircle c1;
initgraph(&gd, &gm, NULL);
xmax = getmaxx();
ymax = getmaxy();
xmid = xmax /2;
ymid = ymax /2;
line(xmid,0,xmid,ymax); //Y co-ordinate
line(0,ymid,xmax,ymid); //X co-ordinate
cout<<"\n Enter x: "; cin>>x;
cout<<"\n Enter y: "; cin>>y;
cout<<"\n Enter radius: "; cin>>r;
c1.setoff(xmid+x, ymid-y);
c1.setrad(r);
c1.drawbc();
delay(3000);
getch();
closegraph();
return 0;
}