2015-05-18 14:11:08 +10:00
|
|
|
#include "image.hpp"
|
|
|
|
#include "noise.hpp"
|
2015-05-18 14:42:28 +10:00
|
|
|
#include "noise/lerp.hpp"
|
2015-05-28 10:56:06 +10:00
|
|
|
#include "noise/basis/value.hpp"
|
|
|
|
#include "noise/basis/perlin.hpp"
|
|
|
|
#include "noise/basis/worley.hpp"
|
2015-05-26 16:37:41 +10:00
|
|
|
#include "extent.hpp"
|
2015-05-18 14:11:08 +10:00
|
|
|
|
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
2015-05-26 16:37:41 +10:00
|
|
|
// setup the output buffer
|
|
|
|
util::extent2u size (1920, 1080);
|
|
|
|
util::image::buffer<float> img (size);
|
2015-05-18 14:11:08 +10:00
|
|
|
|
2015-05-26 16:37:41 +10:00
|
|
|
// setup the noise generator
|
2015-05-28 10:56:06 +10:00
|
|
|
//util::noise::fbm<float, util::noise::basis::worley<float>> b;
|
|
|
|
//util::noise::rmf<float, util::noise::basis::worley<float>> b;
|
|
|
|
//util::noise::hmf<float, util::noise::basis::perlin<float,util::lerp::quintic>> b;
|
|
|
|
util::noise::hetero<float, util::noise::basis::perlin<float,util::lerp::quintic>> b;
|
2015-05-28 10:17:19 +10:00
|
|
|
//b.octaves = 3;
|
2015-05-26 16:37:41 +10:00
|
|
|
b.frequency = 10.f / size.w;
|
2015-05-28 10:17:19 +10:00
|
|
|
b.lacunarity = 2;
|
2015-05-26 16:37:41 +10:00
|
|
|
b.basis.seed = time (NULL);
|
2015-05-18 14:11:08 +10:00
|
|
|
|
2015-05-26 16:37:41 +10:00
|
|
|
// generate the values. offset positions slightly to avoid simple axis issues with perlin basis
|
|
|
|
for (size_t y = 0; y < size.h; ++y)
|
|
|
|
for (size_t x = 0; x < size.w; ++x) {
|
2015-05-28 10:17:19 +10:00
|
|
|
auto v = b ({float(x + 20), float(y + 20)});
|
2015-05-26 16:37:41 +10:00
|
|
|
img.data ()[y * size.w + x] = v;
|
|
|
|
}
|
2015-05-18 14:11:08 +10:00
|
|
|
|
2015-05-26 16:37:41 +10:00
|
|
|
// rescale into the range [0, 1]
|
|
|
|
auto range = std::minmax_element (img.begin (), img.end ());
|
|
|
|
auto offset = *range.first;
|
|
|
|
auto div = *range.second - *range.first;
|
|
|
|
std::cerr << "range: [" << *range.first << ", " << *range.second << "]\n";
|
|
|
|
|
|
|
|
std::transform (img.begin (), img.end (), img.begin (), [offset,div] (auto i) { return (i - offset) / div; });
|
2015-05-18 14:11:08 +10:00
|
|
|
|
2015-05-26 16:37:41 +10:00
|
|
|
// write the image to disk
|
2015-05-18 14:11:08 +10:00
|
|
|
auto grey = img.clone<uint8_t> ();
|
|
|
|
util::pgm::write (grey, "noise.ppm");
|
|
|
|
}
|