-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShape.h
171 lines (110 loc) · 3.74 KB
/
Shape.h
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
166
167
168
169
170
171
//
// Created by Wangdawei on 2018/12/5.
//
#ifndef MANUAL_PROJECT3_INTERSTELLAR_SHAPE_H
#define MANUAL_PROJECT3_INTERSTELLAR_SHAPE_H
static const double pi = 3.1415926535897932;
//#include "Figure.h"
#include "vector.h"
class Figure {
public:
virtual void draw() const = 0;
};
class Color {
public:
void set(double r, double g, double b);
explicit Color(double r = 255, double g = 255, double b = 255);
double getR() const;
double getB() const;
double getG() const;
private:
double r, g, b;
};
class Shape : public Figure {
public:
void setColor(double r, double g, double b);
void draw() const override = 0;
virtual void move(Vec v) = 0;
virtual void zoom(Point center, double coefficient) = 0;
virtual void rotate(Point center, double angle) = 0;
virtual ~Shape() = 0;
protected:
explicit Shape(double r = 0, double g = 0, double b = 0);
Color color;
};
class Quadrilateral : public Shape {
public:
void draw() const override;
void move(Vec v) override;
void rotate(Point center, double angle) override;
void zoom(Point center, double coefficient) override;
explicit Quadrilateral(double r = 0, double g = 0, double b = 0, Point p1 = Vec(0, 0), Point p2 = Vec(0, 1),
Point p3 = Vec(1, 0), Point p4 = Vec(1, 1));
~Quadrilateral() override;
protected:
Point point1, point2, point3, point4;//counterclockwise
};
class IsoTrapezoid : public Quadrilateral {
public:
explicit IsoTrapezoid(double r = 255, double g = 255, double b = 255, Point center = Vec(0, 0),
double upLength = 0.1,
double downLength = 0.2, double height = 0.3, double angle = pi / 2);
void rotate(Point center, double angle) override;
void zoom(Point center, double coefficient) override;
~IsoTrapezoid() override;
private:
Point center;
double rotationAngle;
double upLength, downLength, height;
};
class Rect : public Quadrilateral {
public:
explicit Rect(double r = 255, double g = 255, double b = 255, Point center = Vec(0, 0),
double length = 0.5, double width = 0.25, double angle = pi / 2);
void rotate(Point center, double angle) override;
void zoom(Point center, double coefficient) override;
~Rect() override;
private:
Point center;
double length, width;
double rotationAngle;
};
class Triangle : public Shape {
public:
void draw() const override;
void move(Vec v) override;
void rotate(Point center, double angle) override;
explicit Triangle(Point p1 = Vec(0, 0), Point p2 = Vec(1, 0), Point p3 = Vec(0.5, 0.866), double r = 0,
double g = 0, double b = 0);
void zoom(Point center, double coefficient) override;
~Triangle() override;
private:
Point point1, point2, point3;
};
class Circle : public Shape {
public:
void draw() const override;
void move(Vec v) override;
void rotate(Point center, double angle) override;
explicit Circle(Point p1 = Vec(0, 0), double radius = 1, double r = 255, double g = 255, double b = 255);
void zoom(Point center, double coefficient) override;
~Circle() override;
private:
Point center;
double radius;
};
class SemiCircle : public Shape {
public:
explicit SemiCircle(double r = 255, double g = 255, double b = 255, Point center = Vec(0, 0), double radius = 0.5,
double angle = 0);
void rotate(Point center, double angle) override;
void zoom(Point center, double coefficient) override;
void move(Vec v) override;
void draw() const override;
~SemiCircle() override;
private:
double radius;
double rotationAngle;
Point center;
};
#endif //MANUAL_PROJECT3_INTERSTELLAR_SHAPE_H