-
Notifications
You must be signed in to change notification settings - Fork 0
/
shapeformation.hpp
97 lines (86 loc) · 1.72 KB
/
shapeformation.hpp
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
#include <iostream>
#include <cmath>
/*
* GENERAL INFORMATION:
* Shapes.h is a C++ Library for drawing shapes, like rectangles and
* circles directly in your terminal.
*
* Apache License 2.0
*/
// Rectangle
namespace sf {
struct Rect {
int x;
int y;
int sizeX;
int sizeY;
char charInside = ' ';
Rect(int x, int y, int sizeX, int sizeY)
{
this->x = x;
this->y = y;
this->sizeX = sizeX;
this->sizeY = sizeY;
}
// Main draw function
void draw() const
{
for (int y = 0; y<sizeY; y++) {
for (int x = 0; x<sizeX; x++) {
// If in corner
if (y==0 && x==0 || y==0 && x==sizeX-1 || y==sizeY-1 && x==0 ||
y==sizeY-1 && x==sizeX-1) {
std::cout << '+';
}
else if (y==0 || y==sizeY-1) {
std::cout << '-';
}
else if (x==0 || x==sizeX-1) {
std::cout << '|';
}
else {
std::cout << charInside;
}
}
std::cout << '\n';
}
}
};
struct Circle {
int x, y = 0;
int radius = 20;
Circle(int x, int y, int radius = 20)
{
this->x = x;
this->y = y;
this->radius = radius;
}
Circle(int radius)
{
this->radius = radius;
}
double getArea() const
{
return M_PI*radius*radius;
}
double getPerimeter() const
{
return M_PI * 2 * radius * 2;
}
void draw()
{
/*
* This function works by using the sin() and cos() functions.
* With this, you round the x and y position on which you draw a star
* sign ('*')
* The midpoint of the circle is the variable x and y plus the radius,
* or in other words the offset + the radius, giving you the midpoint.
*/
// The midpoint
int midpointX = x + radius;
int midpointY = y + radius;
int cursorX = x;
int cursorY = y;
}
};
}