-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnonrandom.cpp
More file actions
79 lines (70 loc) · 2.61 KB
/
nonrandom.cpp
File metadata and controls
79 lines (70 loc) · 2.61 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "matrix.h"
#include "snowflake.h"
#include "draw.h"
#include "constants.h"
#include <vector>
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace lapiday;
using namespace std;
int main() {
vector<snowflake::line> lines;
vector<snowflake::line>::size_type linecount;
//Setup six "spokes"
for(int i = 0; i < 6; i++) {
lines.push_back(snowflake::line(snowflake::rotate(PI / 3 * i) * snowflake::scale(BASE_LENGTH)));
}
//Iterate
vector<snowflake::line> newlines;
for(unsigned int i = 0; i < ITERATION_COUNT; i++) {
linecount = lines.size();
for(vector<snowflake::line>::size_type j = 0; j < linecount; j++) {
newlines.push_back(snowflake::line(lines[j].transformation * snowflake::scale(THIRD)));
newlines.push_back(snowflake::line(lines[j].transformation * snowflake::translate(0, THIRD) * snowflake::scale(THIRD)));
newlines.push_back(snowflake::line(lines[j].transformation * snowflake::translate(0, 2 * THIRD) * snowflake::scale(THIRD)));
newlines.push_back(snowflake::line(lines[j].transformation * snowflake::translate(0, THIRD) * snowflake::rotate(PI / 3) * snowflake::scale(THIRD)));
newlines.push_back(snowflake::line(lines[j].transformation * snowflake::translate(0, THIRD) * snowflake::rotate(-PI / 3) * snowflake::scale(THIRD)));
newlines.push_back(snowflake::line(lines[j].transformation * snowflake::translate(0, 2 * THIRD) * snowflake::rotate(PI / 3) * snowflake::scale(THIRD)));
newlines.push_back(lines[j].transformation * snowflake::translate(0, 2 * THIRD) * snowflake::rotate(-PI / 3) * snowflake::scale(THIRD));
}
lines = newlines;
newlines.clear();
}
//Translate all points
linecount = lines.size();
for(vector<snowflake::line>::size_type i = 0; i < linecount; i++) {
lines[i].transformation = snowflake::translate(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2) * lines[i].transformation;
}
//Draw
#ifndef LAPIDAY_RENDER_TO_FILE
sf::RenderWindow target;
target.create(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Snowflake Test");
#else
sf::RenderTexture target;
if(!target.create(WINDOW_WIDTH, WINDOW_HEIGHT)) {
cout << "Could not create texture!" << endl;
return 1;
}
target.setSmooth(true);
#endif
target.clear(BACKGROUND_COLOR);
linecount = lines.size();
for(vector<snowflake::line>::size_type i = 0; i < linecount; i++) {
draw_line(target, lines[i], WINDOW_HEIGHT);
}
target.display();
#ifndef LAPIDAY_RENDER_TO_FILE
//Keep open
while(target.isOpen()) {
sf::Event e;
while(target.pollEvent(e)) {
if(e.type == sf::Event::Closed) {
target.close();
}
}
}
#else
target.getTexture().copyToImage().saveToFile("snowflake.png");
#endif
return 0;
}