-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
81 lines (66 loc) · 2.64 KB
/
main.cpp
File metadata and controls
81 lines (66 loc) · 2.64 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
80
81
#include <cmath>
#include <fstream>
#include <iostream>
#include <vector>
#include <nlohmann/json.hpp>
#include "src/UI/UIRenderer.hpp"
#include "src/fractals/AlgebraicFractal.hpp"
#include "src/fractals/GeometricFractal.hpp"
#include "src/fractals/StochasticFractal.hpp"
#include "src/graphics/Texture.hpp"
int main() {
std::vector<vec4<uint8_t>> palette(1024);
for (size_t i = 0; i < palette.size(); i++) {
float t = (float)i / (float)palette.size();
palette[i].x = static_cast<uint8_t>(9 * (1 - t) * t * t * t * 255);
palette[i].y = static_cast<uint8_t>(15 * (1 - t) * (1 - t) * t * t * 255);
palette[i].z = static_cast<uint8_t>(8.5 * (1 - t) * (1 - t) * (1 - t) * t * 255);
palette[i].w = 255;
}
std::ifstream ifs("ifs.json", std::ios::in);
if (ifs.bad()) {
std::cerr << "ifs.json not found" << std::endl;
exit(1);
}
json j;
ifs >> j;
auto ifs_list = j.get<std::map<std::string, std::vector<StochasticFractal::ifs>>>();
try {
UIRenderer ui(1280, 720, "Fractal Studio");
Texture fractalTexture(800, 600);
std::unique_ptr<IFractal> fractal = std::make_unique<AlgebraicFractal>(800, 600, palette);
while (!ui.ShouldClose()) {
ui.StartFrame();
auto [vs, newFractalType] = ui.DrawUI((ImTextureID)(intptr_t)fractalTexture.GetID(), *fractal);
if (newFractalType != fractal->GetType()) {
switch (newFractalType) {
case FractalType::Algebraic:
fractal = std::make_unique<AlgebraicFractal>(800, 600, palette);
break;
case FractalType::Geometric:
fractal = std::make_unique<GeometricFractal>(800, 600);
break;
case FractalType::Stochastic:
fractal = std::make_unique<StochasticFractal>(800, 600, ifs_list);
break;
default:
break;
}
}
int nW = static_cast<int>(vs.x);
int nH = static_cast<int>(vs.y);
if (nW > 0 && nH > 0 && (nW != fractalTexture.GetWidth() || nH != fractalTexture.GetHeight())) {
fractalTexture.Resize(nW, nH);
fractal->OnResize(nW, nH);
}
fractal->Update();
fractal->Render(fractalTexture);
ui.EndFrame();
}
}
catch (const std::exception& e) {
std::cerr << "Fatal Error: " << e.what() << std::endl;
return -1;
}
return 0;
}