-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03.mid point circle drawing.cpp
57 lines (57 loc) · 1.05 KB
/
03.mid point 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
#include<graphics.h>
#include<iostream.h>
#include<conio.h>
void drawcircle(int x,int y, int xc, int yc)
{
putpixel(y+xc,x+yc,15);
putpixel(y+xc,-x+yc,15);
putpixel(-y+xc,x+yc,15);
putpixel(-y+xc,-x+yc,15);
putpixel(x+xc,-y+yc,15);
putpixel(-x+xc,y+yc,15);
putpixel(-x+xc,-y+yc,15);
}
void mid_point_circle(int r, int xc, int yc)
{
int P,x,y;
x = 0;
y = r;
P = 1 - r;
putpixel(x+xc,y+yc,15);
while(x<=y)
{
if(P<0)
{
P = P + (2*x) + 3;
x = x + 1;
y = y;
putpixel(x+xc,y+yc,15);
drawcircle(x,y,xc,yc);
}
else
{
P = P + (2*x) - (2*y) + 5;
x = x + 1;
y = y - 1;
putpixel(x+xc,y+yc,15);
drawcircle(x,y,xc,yc);
}
}
}
void main()
{
clrscr();
int gdriver = DETECT;
int gmode;
initgraph(&gdriver,&gmode,"c:\\turboc3\\bgi");
cout<<"\t\t Mid Point Circle Drawing Algorithm \t\t"<<endl;
int r,xc,yc;
cout<<"Enter the radius of the circle"<<endl;
cin>>r;
cout<<"Enter the centre co-ordinates of the circle"<<endl;
cin>>xc>>yc;
putpixel(xc,yc,15);
outtextxy(xc,yc,"(xc,yc)");
mid_point_circle(r,xc,yc);
getch();
}