From 13ef16e1830007a0b0b20dc0a132bc2d5c935d5c Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 28 Aug 2015 21:09:21 +1000 Subject: [PATCH] noise-tool: expose more parameters via commandline --- tools/noise.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/tools/noise.cpp b/tools/noise.cpp index 63c59d44..5aa9db86 100644 --- a/tools/noise.cpp +++ b/tools/noise.cpp @@ -184,7 +184,11 @@ main (int argc, char **argv) fractal_t fractal = FBM; lerp_t lerp = QUINTIC; unsigned octaves = 8; - float H; + float H = std::numeric_limits::quiet_NaN (); + float lacunarity = std::numeric_limits::quiet_NaN (); + float amplitude = std::numeric_limits::quiet_NaN (); + float gain = std::numeric_limits::quiet_NaN (); + float offset = std::numeric_limits::quiet_NaN (); float scale = 1.f; float turbulence = 0.f; unsigned single = 0; @@ -201,7 +205,11 @@ main (int argc, char **argv) args.add> ('o', "octaves", "total fractal iterations", octaves); args.add> ('1', "single", "single octave", single); args.add> ('H', "hurst", "Hurst exponent", H); + args.add> ('G', "gain", "octave gain", gain); + args.add> ('A', "amplitude", "base amplitude", amplitude); + args.add> ('L', "lacunarity", "frequency multiplier", lacunarity); args.add> ('x', "scale", "frequency multiplier", scale); + args.add> ('O', "offset", "hetero offset", offset); args.add> ('t', "turbulence", "turbulence scale", turbulence); args.add> ('W', "patch-width", "patch blur width", width); @@ -230,7 +238,12 @@ main (int argc, char **argv) case FBM: f.reset>> (seed); break; case HMF: f.reset>> (seed); break; case RMF: f.reset>> (seed); break; - case HETERO: f.reset>> (seed); break; + case HETERO: { + auto &child = f.reset>> (seed); + if (!isnan (offset)) + child.offset (offset); + break; + } default: unreachable (); @@ -285,6 +298,12 @@ main (int argc, char **argv) t.seed (seed); f.octaves (octaves); f.frequency (scale / res.w); + if (!std::isnan (H)) f.H (H); + if (!std::isnan (lacunarity)) f.lacunarity (lacunarity); + if (!std::isnan (amplitude)) f.amplitude (amplitude); + if (!std::isnan (gain)) f.gain (gain); + + t.perturb[0].frequency ( scale / res.w); t.perturb[1].frequency ( scale / res.w); @@ -321,11 +340,11 @@ main (int argc, char **argv) // 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; + auto inc = *range.first; + auto div = *range.second - *range.first; std::cerr << '[' << *range.first << ',' << *range.second << "]\n"; - std::transform (img.begin (), img.end (), img.begin (), [offset,div] (auto i) { return (i - offset) / div; }); + std::transform (img.begin (), img.end (), img.begin (), [inc,div] (auto i) { return (i - inc) / div; }); // write the images to disk util::pgm::write (img.cast (), std::cout);