-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFractal_Iterator.cpp
75 lines (62 loc) · 1.96 KB
/
Fractal_Iterator.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
#include "Fractal_Iterator.h"
#include "config.h"
#include "constants.h"
Fractal_Iterator::Fractal_Iterator()
{
m_levels.push_back(Fractal_Element(&m_statics));
m_currentLevel = 0;
};
Fractal_Iterator::~Fractal_Iterator() {
}
void Fractal_Iterator::Draw(sf::RenderTarget& target, bool drawPrevious) {
m_levels[m_currentLevel].Draw(target, Line::dt_simple);
if(drawPrevious && m_currentLevel > 0) {
m_levels[m_currentLevel-1].Draw(target, Line::dt_overlay);
}
}
void Fractal_Iterator::SetBase(Fractal_Template newBase) {
m_levels.clear();
m_statics.clear();
m_base = newBase;
Fractal_Element element(&m_statics);
Line newBaseline = m_base.GetBase();
newBaseline.SetColor(sf::Color::Black);
newBaseline.SetType(Line::line_type::lt_topRight);
element.AddLine(newBaseline);
element.SetBase(newBaseline.GetStart(), newBaseline.GetFinish());
m_levels.push_back(element);
SetLevel(0);
}
void Fractal_Iterator::SetLevel(size_t level) {
if(level > ITERATOR_LEVELS) {
m_currentLevel = ITERATOR_LEVELS + 1;
IterateToInfinity();
} else {
m_currentLevel = level;
IterateTo(level);
}
}
void Fractal_Iterator::IterateTo(size_t level) {
if(level < m_levels.size())
return;
for(size_t iii = m_levels.size(); iii <= level; iii++) {
Fractal_Element nextFE = m_levels[iii - 1].ReplaceAll(m_base);
m_levels.push_back(nextFE);
}
}
void Fractal_Iterator::IterateToInfinity() {
// If we already iterated to infinity once before
if (m_levels.size() > ITERATOR_LEVELS + 1)
return;
IterateTo(ITERATOR_LEVELS);
Fractal_Element nextFe = m_levels[ITERATOR_LEVELS];
if (nextFe.GetMaxLength() < nextFe.BaseLength()) {
while (nextFe.GetMaxLength() > config::infinity_stop_size) {
nextFe = nextFe.ReplaceAll(m_base);
}
}
else {
nextFe = nextFe.ReplaceAll(m_base);
}
m_levels.push_back(nextFe);
}