Skip to content

Commit 0de90e1

Browse files
Circle using Bresenham‘s algorithm
Write C++/Java program to draw circle using Bresenham‘s algorithm. Inherit pixel class.
1 parent 8b80b42 commit 0de90e1

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

Diff for: CG2.cpp

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*Write C++/Java program to draw circle using Bresenham‘s algorithm. Inherit pixel class.*/
2+
#include<iostream>
3+
#include<graphics.h>
4+
#include<cstdlib>
5+
#include<math.h>
6+
#include<stdio.h>
7+
using namespace std;
8+
class Pixel
9+
{
10+
protected:
11+
int xc,yc,r;
12+
public:
13+
Pixel()
14+
{
15+
xc=0;
16+
yc=0;
17+
r=0;
18+
};
19+
};
20+
class Circle: public Pixel
21+
{
22+
public:
23+
void drawCircle()
24+
{
25+
int x,y,pk;
26+
printf("*** Bresenham's Circle Drawing Algorithm in C++ ***\n");
27+
cout<<"Enter the value of center_x\t";
28+
cin>>xc;
29+
cout<<"Enter the value of yc\t";
30+
cin>>yc;
31+
cout<<"Enter the Radius of circle\t";
32+
cin>>r;
33+
x=0;
34+
y=r;
35+
//putpixel(center_x+x,yc-y,1);
36+
pk=3-(2*r);
37+
for(x=0;x<=y;x++)
38+
{
39+
if (pk<0)
40+
{
41+
y=y;
42+
pk=(pk+(4*x)+6);
43+
}
44+
else
45+
{
46+
y=y-1;
47+
pk=pk+((4*(x-y)+10));
48+
}
49+
putpixel(xc+x,yc-y,7);
50+
putpixel(xc-x,yc-y,7);
51+
putpixel(xc+x,yc+y,7);
52+
putpixel(xc-x,yc+y,7);
53+
putpixel(xc+y,yc-x,7);
54+
putpixel(xc-y,yc-x,7);
55+
putpixel(xc+y,yc+x,7);
56+
putpixel(xc-y,yc+x,7);
57+
delay(100);
58+
}
59+
};
60+
};
61+
int main()
62+
{
63+
Circle c;
64+
int gd=DETECT,gm;
65+
initgraph(&gd,&gm,NULL);
66+
c.drawCircle();
67+
std::system("gnome-screenshot -f breCircle.jpg");
68+
delay(2000);
69+
return 0;
70+
}

0 commit comments

Comments
 (0)