-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshape.cpp
165 lines (120 loc) · 3.23 KB
/
shape.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "shape.h"
#include <iostream>
using namespace std;
/********************* Color Struct ********************/
color::color() : red(0.0), green(0.0), blue(0.0), alpha(1.0) {
}
color::color(double r, double g, double b, double a) : red(r), green(g), blue(b), alpha(a) {
}
color::color(double r, double g, double b) : red(r), green(g), blue(b), alpha(1.0) {
}
ostream& operator << (ostream& outs, const color &c) {
outs << "(" << c.red << ", " << c.green << ", " << c.blue << ")";
return outs;
}
/********************* Point Struct ********************/
point2D::point2D() : x(0), y(0) {}
point2D::point2D(double x, double y) : x(x), y(y) {}
ostream& operator << (ostream& outs, const point2D &p) {
outs << "(" << p.x << ", " << p.y << ")";
return outs;
}
/********************* Shape Class *********************/
Shape::Shape() : fill({0.0, 0.0, 0.0}), center({0, 0}) {
}
Shape::Shape(color fill) : fill(fill), center({0, 0}) {
}
Shape::Shape(point2D center) : fill({0, 0, 0}), center(center) {
}
Shape::Shape(color fill, point2D center) : fill(fill), center(center) {
}
Shape::Shape(double red, double green, double blue, double alpha) : fill({red, green, blue, alpha}), center({0, 0}) {
}
Shape::Shape(double x, double y) : fill({0, 0, 0}), center({x, y}) {
}
Shape::Shape(double red, double green, double blue, double alpha, double x, double y) : fill({red, green, blue, alpha}), center({x, y}) {
}
Shape::Shape(color fill, double x, double y) : fill(fill), center({x, y}) {
}
Shape::Shape(double red, double green, double blue, double alpha, point2D center) : fill({red, green, blue, alpha}), center(center) {
}
color Shape::getColor() const {
return fill;
}
double Shape::getRed() const {
return fill.red;
}
double Shape::getGreen() const {
return fill.green;
}
double Shape::getBlue() const {
return fill.blue;
}
double Shape::getOpacity() const {
return fill.alpha;
}
point2D Shape::getCenter() const {
return center;
}
double Shape::getCenterX() const {
return center.x;
}
double Shape::getCenterY() const {
return center.y;
}
double Shape::getXVelocity() const {
return xVelocity;
}
double Shape::getYVelocity() const {
return yVelocity;
}
void Shape::setColor(color c) {
fill = c;
}
void Shape::setColor(double r, double g, double b, double a) {
fill = {r, g, b, a};
}
void Shape::setRed(double r) {
fill.red = r;
}
void Shape::setGreen(double g) {
fill.green = g;
}
void Shape::setBlue(double b) {
fill.blue = b;
}
void Shape::setOpacity(double a) {
fill.alpha = a;
}
void Shape::setCenter(point2D center) {
this->center = center;
}
void Shape::setCenter(double x, double y) {
center = {x, y};
}
void Shape::setCenterX(double x) {
center.x = x;
}
void Shape::setCenterY(double y) {
center.y = y;
}
void Shape::move(double deltaX, double deltaY) {
center.x += deltaX;
center.y += deltaY;
}
void Shape::moveX(double deltaX) {
center.x += deltaX;
}
void Shape::moveY(double deltaY) {
center.y += deltaY;
}
void Shape::setXVelocity(double xVel) {
xVelocity = xVel;
}
void Shape::setYVelocity(double yVel) {
yVelocity = yVel;
}
void Shape::setVelocity(double xVel, double yVel) {
xVelocity = xVel;
yVelocity = yVel;
}