noise: add image generator
This commit is contained in:
parent
76405ce9c0
commit
c0859e3160
18
noise.cpp
18
noise.cpp
@ -11,7 +11,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* 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 <iostream>
|
||||||
#include <limits>
|
#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
|
void
|
||||||
util::noise::image2d (uint8_t *restrict pixels,
|
util::noise::image2d (uint8_t *restrict pixels,
|
||||||
size_t width,
|
size_t width,
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* Copyright 2011 Danny Robson <danny@nerdcruft.net>
|
* Copyright 2011-2015 Danny Robson <danny@nerdcruft.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __UTIL_PERLIN_HPP
|
#ifndef __UTIL_PERLIN_HPP
|
||||||
@ -23,8 +23,12 @@
|
|||||||
#include "noise/basis.hpp"
|
#include "noise/basis.hpp"
|
||||||
#include "noise/fractal.hpp"
|
#include "noise/fractal.hpp"
|
||||||
|
|
||||||
|
#include "image.hpp"
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
namespace noise {
|
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&);
|
void image2d (uint8_t *restrict pixels, size_t width, size_t height, const util::noise::fractal&);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ namespace util {
|
|||||||
double frequency;
|
double frequency;
|
||||||
double lacunarity;
|
double lacunarity;
|
||||||
|
|
||||||
|
virtual double operator() (double x, double y) const { return eval (x, y); };
|
||||||
virtual double eval (double x, double y) const = 0;
|
virtual double eval (double x, double y) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user