noise: add image generator

This commit is contained in:
Danny Robson 2015-05-18 14:10:34 +10:00
parent 76405ce9c0
commit c0859e3160
3 changed files with 23 additions and 2 deletions

View File

@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2011 Danny Robson <danny@nerdcruft.net>
* Copyright 2011-2015 Danny Robson <danny@nerdcruft.net>
*/
@ -22,6 +22,22 @@
#include <iostream>
#include <limits>
//-----------------------------------------------------------------------------
void
util::noise::fill (image::buffer<float> &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,

View File

@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2011 Danny Robson <danny@nerdcruft.net>
* Copyright 2011-2015 Danny Robson <danny@nerdcruft.net>
*/
#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<float>&, const util::noise::fractal&);
void image2d (uint8_t *restrict pixels, size_t width, size_t height, const util::noise::fractal&);
}
}

View File

@ -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;
};