12float g_Thickness = 0.8f;
13float* g_Color =
new float[3] { 0.0f, 0.0f, 0.0f };
15Vector<Vector<double>> val1, val2, val3, val4;
17int a[256] = { 151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225,
18 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148,
19 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32,
20 57, 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175,
21 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122,
22 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54,
23 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169,
24 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64,
25 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212,
26 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, 213,
27 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9,
28 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104,
29 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241,
30 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157,
31 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93,
32 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180 };
38 return t * t * t * (t * (t * 6 - 15) + 10);
41double lerp(
double t,
double a,
double b)
43 return a + t * (b - a);
46double grad(
int hash,
double x,
double y,
double z)
49 double u = h < 8 ? x : y,
50 v = h < 4 ? y : h == 12 || h == 14 ? x
52 return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
55void noise(
double x,
double y,
double z,
double& value)
57 int X = (int)floor(x) & 255,
58 Y = (int)floor(y) & 255,
59 Z = (int)floor(z) & 255;
66 int A = p[X] + Y, AA = p[A] + Z, AB = p[A + 1] + Z,
67 B = p[X + 1] + Y, BA = p[B] + Z, BB = p[B + 1] + Z;
69 double val = lerp(w, lerp(v, lerp(u, grad(p[AA], x, y, z), grad(p[BA], x - 1, y, z)), lerp(u, grad(p[AB], x, y - 1, z), grad(p[BB], x - 1, y - 1, z))),
70 lerp(v, lerp(u, grad(p[AA + 1], x, y, z - 1), grad(p[BA + 1], x - 1, y, z - 1)),
71 lerp(u, grad(p[AB + 1], x, y - 1, z - 1),
72 grad(p[BB + 1], x - 1, y - 1, z - 1))));
73 value = val * 0.5 + 0.5;
76void GetNoiseVec(
int x,
int y,
double time, Vector<Vector<double>>& vec)
78 for (
int i = -1000 / g_Dim; i <= 1000 / g_Dim; i++)
81 temp.reserve(1000 / g_Dim * 2 + 1);
82 for (
int j = -1000 / g_Dim; j <= 1000 / g_Dim; j++)
85 noise((i + x) * g_DimPerlin, (j + y) * g_DimPerlin, time, std::ref(v));
87 temp.push_back(std::move(v));
90 vec.emplace_back(std::move(temp));
94int GetState(
const double& a,
const double& b,
const double& c,
const double& d)
96 int a1 = std::round(a);
97 int b1 = std::round(b);
98 int c1 = std::round(c);
99 int d1 = std::round(d);
101 return a1 * 8 + b1 * 4 + c1 * 2 + d1 * 1;
112 for (
int i = 0; i < 256; i++)
119 g_DimPerlin = g_Dim * 0.020735;
123 val1.reserve((1000 / g_Dim * 1000 / g_Dim) + 1000);
124 val2.reserve((1000 / g_Dim * 1000 / g_Dim) + 1000);
125 val3.reserve((1000 / g_Dim * 1000 / g_Dim) + 1000);
126 val4.reserve((1000 / g_Dim * 1000 / g_Dim) + 1000);
140 std::thread t1(GetNoiseVec, 0, 0, Time, std::ref(val1));
141 std::thread t2(GetNoiseVec, 1, 0, Time, std::ref(val2));
142 std::thread t3(GetNoiseVec, 1, 1, Time, std::ref(val3));
143 std::thread t4(GetNoiseVec, 0, 1, Time, std::ref(val4));
150 for (
int i = -1000 / g_Dim; i <= 1000 / g_Dim; i++)
152 for (
int j = -1000 / g_Dim; j <= 1000 / g_Dim; j++)
154 double v1, v2, v3, v4;
155 v1 = val1[i + 1000 / g_Dim][j + 1000 / g_Dim];
156 v2 = val2[i + 1000 / g_Dim][j + 1000 / g_Dim];
157 v3 = val3[i + 1000 / g_Dim][j + 1000 / g_Dim];
158 v4 = val4[i + 1000 / g_Dim][j + 1000 / g_Dim];
179 float thickness = g_Thickness;
180 switch (GetState(v1, v2, v3, v4))
241 ImGui::Begin(
"Settings");
245 ImGui::Text(
"Application average %.3f ms/frame (%.1f FPS)",
246 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
248 ImGui::SliderFloat(
"Thickness", &g_Thickness, 0.0f, 10.0f);
249 ImGui::SliderInt(
"Dimension", &g_Dim, 2.0f, 10.0f);
250 ImGui::SliderFloat(
"Perlin Dimension", &g_DimPerlin, 0.0f, 1.0f);
251 ImGui::Checkbox(
"RenderQuad", &g_RenderQuad);
252 ImGui::ColorPicker3(
"Color", g_Color);
259 Application* app = Application::GetInstance(1920, 1080,
"Marching Squares");
260 Maths::Vec3 pos = Maths::Vec3(0, 0, 0);
265 app->SetCamera(camera);
272 return Vivid::main(0,
nullptr);
A class that represents the camera.
void Setup() override
Setup function.
void ImGuiRender() override
ImGuiRender function.
void Draw() override
Draw function.
A class for the OrthoCamera's.
RenderingInterface class.
static void BeginScene()
Begins the scene.
static void Init(int reserveVertices=10000)
Initializes the Renderer2D.
static void EndScene()
Ends the scene.
static void DrawLine(Maths::Vec2 start, Maths::Vec2 end, float thickness, Maths::Vec3 color)
Draws a line.
static void DrawQuad(float x, float y, float width, float height, const Maths::Vec3 &color)
Draws a quad.