-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMidPointCircle.CPP
56 lines (50 loc) · 1.42 KB
/
MidPointCircle.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
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
int main(){
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TC\\BGI");
float X, Y, radius, y_cord;
float decisionParameter;
float x = 0;
float *octCord ;
octCord = new float(radius);
octCord[0] = radius;
cout<<"Enter Center : ";
cin>>X;
cin>>Y;
cout<<"Enter radius : ";
cin>>radius;
decisionParameter = 5/4-radius;
y_cord = radius;
while(x!=y_cord && x<radius){
if(decisionParameter < 0){
octCord[x+1] = y_cord;
decisionParameter += 2*(x)+1;
}else{
octCord[x+1] = y_cord-1;
y_cord = y_cord-1;
decisionParameter += (2*x+1)-2*y_cord;
}
x += 1;
}
octCord[x+1] = y_cord;
putpixel(X,Y+radius, WHITE);
putpixel(X,Y-radius, WHITE);
putpixel(X-radius, Y, WHITE);
putpixel(X+radius,Y,WHITE);
// Time to render the pixel.
for(int i = 0; i<=y_cord ; i++){
putpixel(i+X,octCord[i]+Y, WHITE);
putpixel(octCord[i]+Y, i+X, WHITE);
putpixel(i+X,Y- octCord[i], WHITE);
putpixel(Y-octCord[i],i+X, WHITE);
putpixel(X-i, (octCord[i]+Y), WHITE);
putpixel(octCord[i]+Y,(X-i), WHITE);
putpixel(X-i,Y- octCord[i], WHITE);
putpixel(Y-octCord[i] , X-i , WHITE);
}
getch();
closegraph();
return 0;
}