-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrawFunctions.cc
executable file
·98 lines (76 loc) · 3.38 KB
/
drawFunctions.cc
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
#include "drawFunctions.h"
#include "ccc_win.h"
#include <cmath>
#include <string>
#include <sstream>
std::string intToString(int i) {
ostringstream strm;
strm << i;
return strm.str();
}
void drawRectangle(double given_width, double given_height, Point llcorner, std::string color) {
double startingXPos = llcorner.get_x();
double endingXPos = startingXPos + given_width;
double bottomYPos = llcorner.get_y();
double topYPos = llcorner.get_y() + given_height;
Point ulcorner(startingXPos, topYPos);
Line ll_to_ul(llcorner, ulcorner, color);
cwin << ll_to_ul;
Point lrcorner(endingXPos, bottomYPos);
Line ll_to_lr(llcorner, lrcorner, color);
cwin << ll_to_lr;
Point urcorner(endingXPos, topYPos);
Line lr_to_ur(lrcorner, urcorner, color);
cwin << lr_to_ur;
Line ul_to_ur(ulcorner, urcorner, color);
cwin << ul_to_ur;
}
Line drawRadialSegment(double inner_radius, double outer_radius, double angle, Point center, std::string color) {
double xOffset = center.get_x();
double yOffset = center.get_y();
double xPosSegInner = inner_radius * sin(angle);
double yPosSegInner = inner_radius * cos(angle);
Point segmentPosInner(xPosSegInner + xOffset, yPosSegInner + yOffset);
double xPosSegOuter = outer_radius * sin(angle);
double yPosSegOuter = outer_radius * cos(angle);
Point segmentPosOuter(xPosSegOuter + xOffset, yPosSegOuter + yOffset);
Line segment(segmentPosInner, segmentPosOuter, color);
return segment;
}
void drawSector(double given_radius, double startingAngle, double endingAngle, Point center, double angleIncrement, std::string color) {
Point outerEdge(given_radius * cos(startingAngle), given_radius * sin(startingAngle));
for (double angle = startingAngle; angle <= endingAngle; angle += angleIncrement) {
cwin << drawRadialSegment(0, given_radius, angle, center, color);
}
}
void drawSolidCircle(double given_radius, Point center, double radiusIncrement, std::string color) {
for (double radius = 0.0; radius <= given_radius; radius += radiusIncrement) {
cwin << Circle(center, radius, color);
}
}
void drawSolidRectangle(double givenWidth, double givenHeight, Point llcorner, double widthIncrement, std::string color) {
Point rectPos(llcorner.get_x(), llcorner.get_y());
for (double width = 0; width < givenWidth / 2; width += widthIncrement) {
rectPos.move(widthIncrement,0);
drawRectangle(width, givenHeight, rectPos, color);
}
}
int max(int a, int b) {
if (a >= b) {
return a;
} else {
return b;
}
}
void drawMapTower(double squareSize, Point llcorner, std::string primaryColor, std::string secondaryColor) {
llcorner = Point (llcorner.get_x(), llcorner.get_y());
Point llcornerAdj(llcorner.get_x() + 0.01, llcorner.get_y() + 0.01);
drawSolidRectangle(squareSize, squareSize, llcorner, WIDTH_INCREMENT, primaryColor);
drawSolidRectangle(squareSize / 4, squareSize / 4, llcornerAdj, WIDTH_INCREMENT, secondaryColor);
Point ulsquare(llcornerAdj.get_x(),llcornerAdj.get_y() + squareSize * 0.75);
drawSolidRectangle(squareSize / 4, squareSize / 4, ulsquare, WIDTH_INCREMENT, secondaryColor);
Point ursquare(llcornerAdj.get_x() + squareSize * 0.75,llcornerAdj.get_y() + squareSize * 0.75);
drawSolidRectangle(squareSize / 4, squareSize / 4, ursquare, WIDTH_INCREMENT, secondaryColor);
Point lrsquare(llcornerAdj.get_x() + squareSize * 0.75,llcornerAdj.get_y());
drawSolidRectangle(squareSize / 4, squareSize / 4, lrsquare, WIDTH_INCREMENT, secondaryColor);
}