-
Notifications
You must be signed in to change notification settings - Fork 0
/
fractalsequence.cpp
81 lines (69 loc) · 1.94 KB
/
fractalsequence.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
#include "fractalsequence.h"
FractalSequence::FractalSequence() : iteration(0)
{
// initialize the first 2 points, or, iteration 0
mSequence.push_back(point(0,0));
mSequence.push_back(point(1,0));
}
/**
* Implemented by : Nancy
* @brief Function to populate mSequence with new members generated by iteration
*/
void FractalSequence::Rotate()
{
//X,Y are the coordinates of the point
//x_last and y_last are the coordinates of the rotate point
//x_rotate and y_rotate are the coordinates after rotating
int X = 0,Y = 0;
int last = mSequence.size();
int x_turning = mSequence[last-1].x,y_turning = mSequence[last-1].y;
int x_rotating = 0,y_rotating = 0;
for (int i=last-2;i>=0;i--) {
//get the point
X = mSequence[i].x;
Y = mSequence[i].y;
//change to the new system
X = X - x_turning;
Y = Y - y_turning;
y_rotating = -X;
x_rotating = Y;
//change back to the original system
y_rotating = y_rotating+y_turning;
x_rotating = x_rotating+x_turning;
//put the value into vector
mSequence.push_back(sf::Vector2f(x_rotating,y_rotating));
}
iteration++;
}
/**
* @brief Reset the sets, and internal data
*/
void FractalSequence::Reset()
{
mSequence.clear(); iteration = 0;
mSequence.push_back(point(0,0));
mSequence.push_back(point(1,0));
}
/**
* @brief Function to calculate the number of points for given iteration
* @param iteration points
* @return number of points
*/
size_t FractalSequence::getSizeAt(size_t atIteration)
{
// tested, working
// series expansion 2 + 2*i_prev - 1, i_prev is defined recursively
if(atIteration == 0) return 2;
else return 2*getSizeAt(atIteration - 1) - 1;
}
/**
* @brief Needed to rotate about last point
*/
sf::Vector2f FractalSequence::getLastPoint()
{
return *(mSequence.end());
}
FractalSequence::~FractalSequence()
{
mSequence.clear();
}