From c0859e316008b722753376c9bbbfe9ae45ebed7a Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 18 May 2015 14:10:34 +1000 Subject: [PATCH] noise: add image generator --- noise.cpp | 18 +++++++++++++++++- noise.hpp | 6 +++++- noise/fractal.hpp | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/noise.cpp b/noise.cpp index 1df999fd..2260dcf7 100644 --- a/noise.cpp +++ b/noise.cpp @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Copyright 2011 Danny Robson + * Copyright 2011-2015 Danny Robson */ @@ -22,6 +22,22 @@ #include #include + +//----------------------------------------------------------------------------- +void +util::noise::fill (image::buffer &pixels, + const util::noise::fractal &gen) +{ + size_t h = pixels.h, s = pixels.s, w = pixels.w; + float *data = pixels.data (); + + for (size_t y = 0; y < h; ++y) + for (size_t x = 0; x < w; ++x) + data[y * s + x] = gen (double(x), double(y)); +} + + +//----------------------------------------------------------------------------- void util::noise::image2d (uint8_t *restrict pixels, size_t width, diff --git a/noise.hpp b/noise.hpp index f7ee9586..d74e2c51 100644 --- a/noise.hpp +++ b/noise.hpp @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Copyright 2011 Danny Robson + * Copyright 2011-2015 Danny Robson */ #ifndef __UTIL_PERLIN_HPP @@ -23,8 +23,12 @@ #include "noise/basis.hpp" #include "noise/fractal.hpp" +#include "image.hpp" + namespace util { namespace noise { + void fill (image::buffer&, const util::noise::fractal&); + void image2d (uint8_t *restrict pixels, size_t width, size_t height, const util::noise::fractal&); } } diff --git a/noise/fractal.hpp b/noise/fractal.hpp index 2117412d..0fa72cb5 100644 --- a/noise/fractal.hpp +++ b/noise/fractal.hpp @@ -32,6 +32,7 @@ namespace util { double frequency; double lacunarity; + virtual double operator() (double x, double y) const { return eval (x, y); }; virtual double eval (double x, double y) const = 0; };