-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathperlin.cpp
67 lines (58 loc) · 2.01 KB
/
perlin.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
// Demo: perlin.cpp
// Author: Evan Pezent (evanpezent.com)
// Date: 7/25/2021
#define APP_USE_DGPU
#include "App.h"
#define STB_PERLIN_IMPLEMENTATION
#include <stb/stb_perlin.h>
#include <vector>
#include <iostream>
struct ImPerlin : App {
using App::App;
void Start() override {
generate_noise();
ImPlot::GetStyle().Colormap = ImPlotColormap_Spectral;
}
void Update() override {
ImGui::SetNextWindowPos(ImVec2(0,0), ImGuiCond_Always);
ImGui::SetNextWindowSize(GetWindowSize(), ImGuiCond_Always);
ImGui::Begin("Perlin", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize);
ImGui::Text("FPS: %.2f", ImGui::GetIO().Framerate);
// ImPlot::ShowColormapSelector("Colormap");
if (ImGui::DragInt2("Size",&rows,10,0,10000))
generate_noise();
if (ImGui::DragFloat("Scale",&scale,0.001f,0,10))
generate_noise();
if (ImGui::DragFloat("Scrub",&z,0.1f,0,10))
generate_noise();
static float mn = 0, mx = 1;
ImGui::DragFloatRange2("Range",&mn,&mx,0.1f,-10,10);
if (ImPlot::BeginPlot("##Perlin",ImVec2(-1,-1),ImPlotFlags_CanvasOnly)) {
ImPlot::SetupAxes(NULL,NULL,ImPlotAxisFlags_NoDecorations,ImPlotAxisFlags_NoDecorations);
ImPlot::PlotHeatmap("##T",perlin_data.data(),rows,cols,mn,mx,NULL);
ImPlot::EndPlot();
}
ImGui::End();
}
void generate_noise() {
perlin_data.clear();
perlin_data.reserve(rows*cols);
for (int r = 0; r < rows; ++r) {
for (int c = 0; c < cols; ++c) {
float v = stb_perlin_noise3_seed(r*scale, c*scale, z, 0, 0, 0, 42);
perlin_data.push_back(v);
}
}
}
float scale = 0.005f;
float z = 0;
int rows = 1000;
int cols = 1000;
std::vector<float> perlin_data;
};
int main(int argc, char const *argv[])
{
ImPerlin demo("ImPerlin",640,480,argc,argv);
demo.Run();
return 0;
}