-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspirograph.cpp
More file actions
66 lines (46 loc) · 1.15 KB
/
Copy pathspirograph.cpp
File metadata and controls
66 lines (46 loc) · 1.15 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
#include "spirograph.hpp"
Spirograph::Spirograph() {
}
Spirograph::Spirograph(sf::Vector2f position, float length, float speed) {
add_arm(Arm{position, length, speed});
}
void Spirograph::add_arm(Arm arm) {
mArms.push_back(arm);
if(mArms.size() > 1)
{
mArms.back().attachTo(mArms.at(mArms.size() - 2));
} else {
//Center the first arm
mArms.front().setPosition(sf::Vector2f(WIN_WIDTH/2.0f,WIN_HEIGHT/2.0f));
}
mTip.attachTo(mArms.back());
}
void Spirograph::update() {
int i = 0;
for(Arm &arm : mArms) {
arm.rotate(arm.getSpeed());
if(i > 0) {
arm.attachTo(mArms.at(i-1));
}
i++;
}
mTip.attachTo(mArms.back());
write();
}
void Spirograph::draw(sf::RenderWindow &window) {
for(Arm &arm : mArms) {
arm.draw(window);
}
mTip.draw(window);
for(Tip &point : mDrawing) {
point.draw(window);
}
}
void Spirograph::write() {
mDrawing.push_back(Tip {mTip.getSize()});
mDrawing.back().setPosition(mTip.getPosition());
if(Tip::getCount() > DRAWING_FADE)
{
mDrawing.pop_front();
}
}