-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlineandcircle.cpp
82 lines (79 loc) · 1.48 KB
/
lineandcircle.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
#include <graphics.h>
#include<iostream>
#include <math.h>
using namespace std;
void circlebres(float x1,float y1,float r)
{
float x,y,p;
x=0;
y=r;
p=3-(2*r); // initial decision parameter
while(x<=y)
{
putpixel(x1+x,y1+y,WHITE); /* drawing pixel in each octant*/
putpixel(x1-x,y1+y,WHITE);
putpixel(x1+x,y1-y,WHITE);
putpixel(x1-x,y1-y,WHITE);
putpixel(x1+y,y1+x,WHITE);
putpixel(x1+y,y1-x,WHITE);
putpixel(x1-y,y1+x,WHITE);
putpixel(x1-y,y1-x,WHITE);
x=x+1;
if(p<0)
{
p=p+4*(x)+6;
}
else
{
p=p+4*(x-y)+10;
y=y-1;
}
delay(40);
}
}
void drawline(int x1,int y1,int x2,int y2)
{
int dx,dy,m,s;
float xi,yi,x,y;
dx = x2 - x1;
dy = y2 - y1;
if (abs(dx) > abs(dy))
s = abs(dx);
else
s = abs(dy);
xi = dx / (float) s;
yi = dy / (float) s;
x = x1;
y = y1;
putpixel(x1, y1, WHITE);
for (m = 0; m < s; m++)
{
putpixel(x, y, WHITE);
x += xi;
y += yi;
}
delay(500);
}
int main()
{
int xc,yc,r;
cout<<" enter center coordinates : ";
cin>>xc>>yc;
cout<<"enter redius : ";
cin>>r;
int gd=DETECT,gm=DETECT,x1,y1,x2,y2;
initgraph(&gd,&gm,NULL);
circlebres(xc,yc,r); //inside circle
double height,side;
//side=r/0.577;
//height=1.73*side;
side=1.73*r;
height=1.73*side;
drawline(xc-side,yc+r,xc+side,yc+r); //base line
delay(300);
drawline(xc-side,yc+r,xc,yc+r-height);// left line
drawline(xc,yc+r-height,xc+side,yc+r); // right line
circlebres(xc,yc,height-r);//outer circle
delay(3000);
closegraph();
}