-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLine.cpp
More file actions
68 lines (55 loc) · 1.33 KB
/
Line.cpp
File metadata and controls
68 lines (55 loc) · 1.33 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
#include "Line.h"
#include "Geometricobjects.h"
//
void Line::draw()
{
std::cout << " This is a child class Line" << std::endl;
//drawLine(start_x_, start_y_, end_x_, end_y_, 0.0f, 1.0f, 0.0f);
// drawing outer circle from base class
Geometricobjects::draw_red_circle(100, 360, 50, 2);
for (int i = 0; i<4; i++) // drawing thick line
drawLine(75 - 1, 325 + i, 125 - i, 375, 0.0f, 0.0f, 1.0f);
//drawLine(74, 326, 124, 375, 0.0f, 0.0f, 1.0f);
//GeometricObjects::drawonepixel(1,2,2,1.0f,0.0f);
}
//
void Line::drawLine(const int& i0, const int& j0, const int& i1, const int& j1, const float& red, const float& green, const float& blue)
{
if (i0 < i1)
{
for (int i = i0; i <= i1; i++)
{
const int j = (j1 - j0)*(i - i0) / (i1 - i0) + j0;
Geometricobjects::drawonepixel(i, j, red, green, blue);
}
}
else if (i0 > i1)
{
for (int i = i1; i <= i0; i++)
{
const int j = (j1 - j0)*(i - i0) / (i1 - i0) + j0;
Geometricobjects::drawonepixel(i, j, red, green, blue);
}
}
else
{
if (j0 < j1)
{
for (int j = j0; j < j1; j++)
{
Geometricobjects::drawonepixel(i0, j, red, green, blue);
}
}
else if (j0 > j1)
{
for (int j = j1; j < j0; j++)
{
Geometricobjects::drawonepixel(i0, j, red, green, blue);
}
}
else
{
Geometricobjects::drawonepixel(i0, j0, red, green, blue);
}
}
}