-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path4_RectangleDiamongRectangle.cpp
More file actions
138 lines (106 loc) · 2.73 KB
/
Copy path4_RectangleDiamongRectangle.cpp
File metadata and controls
138 lines (106 loc) · 2.73 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//
// Created by piyush on 2/25/19.
//
#include <bits/stdc++.h>
#include<graphics.h>
using namespace std;
#define callInitgraph int gd=DETECT,gm; initgraph(&gd,&gm,NULL);
//line drawing algorithm (DDALine)
class LineDrawingAlgorithms
{
public:
float a, b, c, d; //vertices of rectangle
void getVerticesOfRectangle();
void drawRectangleDiamongRectangle();
void DDALine(float x1, float y1, float x2, float y2);
};
void LineDrawingAlgorithms::DDALine(float x1, float y1, float x2, float y2)
{
float x,y,xin,yin,dx,dy,step;
dx = x2 - x1;
dy = y2 - y1;
if(abs(dx) > abs(dy) || abs(dx) == abs(dy))
step = dx;
else
step = dy;
xin = dx / step;
yin = dy / step;
x = x1;
y = y1;
putpixel(x,y,WHITE);
for(int i = 0; i < step; i++)
{
x=x+xin;
y=y+yin;
round(x);
round(y);
delay(10);
putpixel(x,y,WHITE);
}
}
void LineDrawingAlgorithms::getVerticesOfRectangle()
{
//accepting two co-ordinates from user
cout<<"\nEnter the coordinates of upper left vertex of rectangle (xu,yu) :";
cin>>a>>b;
cout<<"\nEnter the coordinates of lower right vertex of rectangle (xl,yl) :";
cin>>c>>d;
}
void LineDrawingAlgorithms::drawRectangleDiamongRectangle()
{
float l1,l2,p,q,r,s;
//calculating middle point of lenth side and breadth side for diamaond shape inside outer-rectangle
l1=(b+d)/2;
l2=(a+c)/2;
//calculating middle point of each half calculated in above for inner-rectangle
p=(a+l2)/2;
q=(b+l1)/2;
r=(l2+c)/2;
s=(l1+d)/2;
callInitgraph;
//creates the outer rectangle
DDALine(a, b, c, b);
DDALine(c, b, c, d);
DDALine(a, b, a, d);
DDALine(a, d, c, d);
//creates inner diamond
DDALine(a, l1, l2, b);
DDALine(l2, b, c, l1);
DDALine(a, l1, l2, d);
DDALine(l2, d, c, l1);
//drawing the inner inner rectangle
DDALine(p, q, r, q);
DDALine(r, q, r, s);
DDALine(p, q, p, s);
DDALine(p, s, r, s);
delay(10000);
}
int main()
{
cout<<"\n******FIGURE DRAWING********\n";
//line drawing dda class object
LineDrawingAlgorithms r1;
int dw, sw;
do {
dw = 1;
cout << "\n(1). To get rectangle coordinates ";
cout << "\n(2). To draw rectangle-diamond-rectangle ";
cout << "\n(3). To Exit ";
cin >> sw;
switch(sw)
{
case 1:
r1.getVerticesOfRectangle();
break;
case 2:
r1.drawRectangleDiamongRectangle();
break;
case 3:
dw = 0;
break;
default:
cout << "\nInvalid Input";
}
}while (dw);
return 0;
}