-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mid_point_cricle_drawing_algorithm.cpp
86 lines (84 loc) · 1.99 KB
/
Mid_point_cricle_drawing_algorithm.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
Parmar Fenil Milankumar
Information & Technology
Vishwakarma Goverment Engineering College
*/
#include<iostream>
#include<graphics.h>
using namespace std;
int main()
{
int r;
cout<<"Enter Radius:";
cin>>r;
int xc,yc;
cout<<"Enter Center Point: ";
cin>>xc>>yc;
int po=1-r;
int x=0,y=r;
if(r<=0 || (xc+r)>=800 ||(yc+r)>=800 ||(yc-r)<=0 || (xc-r)<=0)
{
cout<<"Error:Enter Right Value For Radius Or Center Points.\n(1)May be you entered negative or zero value for radius! \n(2)May be your combination of center points and radius leads circle outside of our window!\n";
main();
}
else
{
initwindow(800,800);
putpixel(xc,yc,15);
putpixel(xc+x,yc+y,15);
putpixel(xc+x,yc-y,15);
putpixel(xc+y,yc+x,15);
putpixel(xc-y,yc+x,15);
while(x<y)
{
if(po<0)
{
x=x+1;
po=po+(2*x)+1;
cout<<"Dicision Parameter:"<<po<<"x="<<x<<" y="<<y<<endl;
}
else
{
x=x+1;
y=y-1;
po=po+(2*x)+1-(2*y);
cout<<"Dicision Parameter:"<<po<<"x="<<x<<" y="<<y<<endl;
}
/*We only have to find for one octant then there are all similar , so we just have to put pixels of other 7 octants.*/
putpixel(xc+x,yc+y,15);
putpixel(xc+y,yc+x,15);
putpixel((xc-x),(yc-y),15);
putpixel((xc-y),(yc-x),15);
putpixel(xc+x,(yc-y),15);
putpixel((xc-x),yc+y,15);
putpixel(xc+y,(yc-x),15);
putpixel((xc-y),yc+x,15);
}
// while(y>=0)
// {
// if(po<0)
// {
// y=y-1;
// po=po+(2*y)+1;
// cout<<"Dicision Parameter:"<<po<<"x="<<x<<" y="<<y<<endl;
// putpixel(xc+x,yc+y,15);
// putpixel((xc-x),(yc-y),15);
// putpixel(xc+x,(yc-y),15);
// putpixel((xc-x),yc+y,15);
// }
// else
// {
// y=y-1;
// x=x+1;
// po=po+(2*y)+1-(2*x);
// cout<<"Dicision Parameter:"<<po<<"x="<<x<<" y="<<y<<endl;
// putpixel(xc+x,yc+y,15);
// putpixel((xc-x),(yc-y),15);
// putpixel(xc+x,(yc-y),15);
// putpixel((xc-x),yc+y,15);
// }
// }
}
getch();
return 0;
}