-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
176 lines (150 loc) · 6.22 KB
/
mainwindow.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
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
172
173
174
175
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
setPalette(Qt::white);
scene = new QGraphicsScene(ui->graphicsView);
ui->graphicsView->setScene(scene);
ui->graphicsView->scale(.125,.125);
// scene->addLine(-250,-250,1000,1000)->setOpacity(0);
drawTriangleHexagonPattern();
showFullScreen();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::drawTriangleHexagonPattern()
{
string = "FR015FR015FR015FR015FFFFR015FR015FR015FR015FFFFR015FR015FR015FR015FFFFR015FR015FR015FR015FFFFR015FR015FR015FR015FFFFR015FR015FR015FR015FFFBBBR240FR015FR015FR015FR015FFFFR015FR015FR015FR015FFFFR015FR015FR015FR015FFFFR015FR015FR015FR015FFFFR015FR015FR015FR015FFFFR015FR015FR015FR015FFFBBBR240FR015FR015FR015FR015FFFFR015FR015FR015FR015FFFFR015FR015FR015FR015FFFFR015FR015FR015FR015FFFFR015FR015FR015FR015FFFFR015FR015FR015FR015FFFBBBR240";
rules.push_back(std::make_pair(string,string+"FFFFFFFFFFFFR240FFFFFFFFFFFF"+string+"FFFFFFFFFFFFR240FFFFFFFFFFFF"+string+"FFFFFFFFFFFFR240FFFFFFFFFFFF"));
applyRules();
cursors.push_back(QPointF(0,0));
thetas.push_back(PI/2);
makeLines();
drawFast();
}
void MainWindow::drawTree()
{
string = "SSSSS";
rules.push_back(std::make_pair("S","SS"));
rules.push_back(std::make_pair("SSSSSSSS","FSSSSSSSS"));
applyRules();
cursors.push_back(QPointF(0,0));
thetas.push_back(PI/2);
makeLines();
draw();
}
void MainWindow::makeRing()
{
string = "FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020";
rules.push_back(std::make_pair("FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020","FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FFFFR020R020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020FR020"));
applyRules(); applyRules(); applyRules(); applyRules(); applyRules();
applyRules(); applyRules(); applyRules(); applyRules(); applyRules();
applyRules(); applyRules(); applyRules(); applyRules(); applyRules();
applyRules(); applyRules(); applyRules(); applyRules(); applyRules();
// Apply Rules More
cursors.push_back(QPointF(0,100));
thetas.push_back(PI/2);
makeLines();
draw();
}
void MainWindow::applyRules()
{
for(auto it = rules.cbegin(); it != rules.cend(); ++it)
string.replace(it->first, it->second);
}
constexpr double len = 350;
constexpr double split_rotation = PI/10;
void MainWindow::makeLines()
{
std::vector<QPointF> newCursors;
std::vector<double> newThetas;
for(auto symbol = string.cbegin(); symbol != string.cend(); ++symbol) {
auto theta = thetas.cbegin();
// std::cerr << "symbol = " << symbol->toLatin1() << std::endl;
for(auto cursor = cursors.cbegin(); cursor != cursors.cend() && theta != thetas.cend(); ++cursor, ++theta) {
// std::cerr << "cursor = (" << cursor->x() << ", " << cursor->y() << ")" << std::endl;
// std::cerr << "theta = " << std::to_string(*theta) << std::endl;
switch(symbol->toLatin1()) {
case 'F':
{
line *line0 = new line(nullptr, *cursor, QPointF(cursor->x()+len*cos(*theta), cursor->y()+len*qSin(*theta)));
newCursors.push_back(QPointF(cursor->x()+len*qCos(*theta), cursor->y()+len*qSin(*theta)));
newThetas.push_back(std::fmod(*theta, 2*PI));
lineBank.push_back(line0);
}
break;
case 'B':
{
line *line0 = new line(nullptr, *cursor, QPointF(cursor->x()-len*qCos(*theta), cursor->y()-len*qSin(*theta)));
newCursors.push_back(QPointF(cursor->x()-len*qCos(*theta), cursor->y()-len*qSin(*theta)));
newThetas.push_back(std::fmod(*theta, 2*PI));
lineBank.push_back(line0);
}
break;
case 'S':
{
line *line0 = new line(nullptr, *cursor, QPointF(cursor->x()+len*qCos(*theta+split_rotation), cursor->y()+len*qSin(*theta+split_rotation)));
newCursors.push_back(QPointF(cursor->x()+len*qCos(*theta+split_rotation), cursor->y()+len*qSin(*theta+split_rotation)));
newThetas.push_back(std::fmod(*theta+split_rotation, 2*PI));
lineBank.push_back(line0);
line *line1 = new line(nullptr, *cursor, QPointF(cursor->x()+len*qCos(*theta-split_rotation), cursor->y()+len*qSin(*theta-split_rotation)));;
newCursors.push_back(QPointF(cursor->x()+len*qCos(*theta-split_rotation), cursor->y()+len*qSin(*theta-split_rotation)));
newThetas.push_back(std::fmod(*theta-split_rotation, 2*PI));
lineBank.push_back(line1);
}
break;
case 'R':
{
std::string arg;
for(int i = 0; i < 3; ++i) {
++symbol;
arg.push_back(symbol->toLatin1());
}
newThetas.push_back(std::fmod(*theta+2*PI*std::stod(arg)/360, 2*PI));
newCursors.push_back(*cursor);
}
break;
}
}
cursors = newCursors;
thetas = newThetas;
newThetas.clear();
newCursors.clear();
}
lineCursor = lineBank.cbegin();
}
void MainWindow::draw()
{
animation->setStartValue(0);
animation->setEndValue(100000);
animation->setDuration(10000000);
animation->setEasingCurve(QEasingCurve::Linear);
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
void MainWindow::drawFast()
{
for(; lineCursor != lineBank.cend(); ++lineCursor) {
scene->addItem(*lineCursor);
(*lineCursor)->startAnimation();
}
}
void MainWindow::setFrame(int frame)
{
std::cerr << "frame = " << frame_m << std::endl;
frame_m = frame;
if(lastFrameDrawn == frame) return;
if(lineCursor == lineBank.cend())
{
animation->stop();
return;
}
scene->addItem(*lineCursor);
(*lineCursor)->startAnimation();
++lineCursor;
lastFrameDrawn = frame;
}