-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhello_tint.cpp
More file actions
100 lines (83 loc) · 3.12 KB
/
Copy pathhello_tint.cpp
File metadata and controls
100 lines (83 loc) · 3.12 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <numbers>
#include <nothofagus.h>
#include <glm/gtc/type_ptr.hpp>
int main()
{
Nothofagus::Canvas canvas({150, 100}, "Hello Tint", {0.7, 0.7, 0.7}, 6);
Nothofagus::ColorPallete palleteGreen{
{0.0, 0.0, 0.0, 0.0},
{0.0, 0.4, 0.0, 1.0},
{0.2, 0.8, 0.2, 1.0},
{0.5, 1.0, 0.5, 1.0},
};
Nothofagus::ColorPallete palleteRed{
{0.0, 0.0, 0.0, 0.0},
{0.4, 0.0, 0.0, 1.0},
{0.8, 0.2, 0.2, 1.0},
{1.0, 0.5, 0.5, 1.0},
};
Nothofagus::ColorPallete palleteBlue{
{0.0, 0.0, 0.0, 0.0},
{0.0, 0.0, 0.4, 1.0},
{0.2, 0.2, 0.8, 1.0},
{0.5, 0.5, 1.0, 1.0},
};
Nothofagus::IndirectTexture textureGreen({8, 8}, {0.5, 0.5, 0.5, 1.0});
textureGreen.setPallete(palleteGreen)
.setPixels(
{
2,1,3,0,0,3,2,1,
2,1,1,0,0,0,2,1,
2,1,1,1,0,0,2,1,
2,1,2,1,1,0,2,1,
2,1,0,2,1,1,2,1,
2,1,0,0,2,1,2,1,
2,1,0,0,0,2,2,1,
2,1,3,0,0,3,2,1,
}
);
Nothofagus::IndirectTexture textureRed = textureGreen;
textureRed.setPallete(palleteRed);
Nothofagus::IndirectTexture textureBlue = textureGreen;
textureBlue.setPallete(palleteBlue);
Nothofagus::TextureId textureIdGreen = canvas.addTexture(textureGreen);
Nothofagus::TextureId textureIdRed = canvas.addTexture(textureRed);
Nothofagus::TextureId textureIdBlue = canvas.addTexture(textureBlue);
Nothofagus::BellotaId bellotaIdGreen = canvas.addBellota({ {{100.0f, 50.0f}}, textureIdGreen });
Nothofagus::BellotaId bellotaIdRed = canvas.addBellota({ {{100.0f, 50.0f}}, textureIdRed });
Nothofagus::BellotaId bellotaIdBlue = canvas.addBellota({ {{100.0f, 50.0f}}, textureIdBlue });
float time = 0.0f;
bool rotate = true;
float intensity = 0.0f;
float tintColor[3] = { 1.0f, 1.0f, 1.0f };
auto update = [&](float dt)
{
time += dt;
Nothofagus::Bellota& bellotaRed = canvas.bellota(bellotaIdRed);
Nothofagus::Bellota& bellotaGreen = canvas.bellota(bellotaIdGreen);
bellotaGreen.transform().location() = glm::vec2(100.0f, 50.0f)
+ 20.0f * glm::vec2(
std::cos(0.001f * time),
std::sin(0.001f * time)
);
Nothofagus::Bellota& bellotaBlue = canvas.bellota(bellotaIdBlue);
bellotaBlue.transform().location() = glm::vec2(100.0f, 50.0f)
+ 20.0f * glm::vec2(
std::cos(0.001f * time + std::numbers::pi/4),
std::sin(0.001f * time + std::numbers::pi/4)
);
ImGui::SetNextWindowSize(ImVec2(0.0f, 0.0f), ImGuiCond_Once);
ImGui::Begin("Green Tint");
ImGui::SliderFloat("Intensity", &intensity, 0.0f, 1.0f);
ImGui::ColorPicker3("Color", tintColor);
ImGui::End();
canvas.setTint(bellotaIdGreen, { intensity, glm::make_vec3(tintColor) });
canvas.setTint(bellotaIdRed, { std::abs(std::sin(0.005f * time)), {1.0, 1.0, 1.0} });
};
canvas.run(update);
return 0;
}