-
Notifications
You must be signed in to change notification settings - Fork 0
/
Midpoint_Circle_Drawing.cpp
79 lines (73 loc) · 1.8 KB
/
Midpoint_Circle_Drawing.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
// Write a Program to implement a Midpoint Circle Drawing Algorithm.
#include <graphics.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <conio.h>
#include <iostream>
using namespace std;
class bresen
{
float x, y,a, b, r, p;
public:
void get();
void cal();
};
int main (void)
{
bresen b;
b.get ();
b.cal ();
getch ();
}
void bresen::get()
{
cout<<"Enter Center And Radius:" <<endl;
cout<< "Enter (a, b):";
cin>>a>>b;
cout<<"Enter R:";
cin>>r;
}
void bresen::cal()
{
/* request auto detection */
int gdriver = DETECT,gmode, errorcode;
int midx, midy, i;
/* initialize graphics and local variables */
initgraph (&gdriver, &gmode, " ");
/* read result of initialization */
errorcode = graphresult ();
if (errorcode != grOk) /*an error occurred */
{
printf("Graphics error: %s \n", grapherrormsg (errorcode));
printf ("Press any key to halt:");
getch ();
exit (1); /* terminate with an error code */
}
x=0;
y=r;
putpixel (a, b+r, RED);
putpixel (a, b-r, RED);
putpixel (a-r, b, RED);
putpixel (a+r, b, RED);
p=(5/4)-r;
while(x<=y)
{
if (p<0)
p+= (4*x)+6;
else
{
p+=(2*(x-y))+5;
y--;
}
x++;
putpixel (a+x, b+y, RED);
putpixel (a-x, b+y, RED);
putpixel (a+x, b-y, RED);
putpixel (a+x, b-y, RED);
putpixel (a+x, b+y, RED);
putpixel (a+x, b-y, RED);
putpixel (a-x, b+y, RED);
putpixel (a-x, b-y, RED);
}
}