21 const std::string& filename,
25 const std::function<
float(
float,
float)>& noiseFunc)
27 std::ofstream out(filename, std::ios::binary);
30 out <<
"P6\n" << width <<
" " << height <<
"\n255\n";
32 for (
int y = 0; y < height; ++y) {
33 for (
int x = 0; x < width; ++x) {
34 float nx = (x - width / 2.0f) / scale;
35 float ny = (y - height / 2.0f) / scale;
36 float n = noiseFunc(nx, ny);
39 unsigned char v =
static_cast<unsigned char>(
40 std::clamp((n * 0.5f + 0.5f) * 255.0f, 0.0f, 255.0f)
43 out.put(v).put(v).put(v);
50inline void visualizer2D(
const std::string& filename,
const std::vector<std::vector<float>>& map) {
51 int H = map.size(), W = map[0].size();
52 std::ofstream out(filename, std::ios::binary);
53 out <<
"P6\n" << W <<
" " << H <<
"\n255\n";
54 for (
int y = 0; y < H; ++y)
55 for (
int x = 0; x < W; ++x) {
56 unsigned char c =
static_cast<unsigned char>(
57 std::clamp(map[y][x] * 255.0f, 0.0f, 255.0f)
60 out.put(c).put(c).put(c);
void visualizer2D(const std::string &filename, int width, int height, float scale, const std::function< float(float, float)> &noiseFunc)
Definition Visualizer.hpp:20