#include <PerlinNoise.h>
Public Member Functions | |
PerlinNoise (int size_x, int size_y) | |
~PerlinNoise () | |
void | SetForegroundColor (float red, float green, float blue, float alpha) |
void | SetBackgroundColor (float red, float green, float blue, float alpha) |
void | SetParameters (float frequency, float persistence, int octaves, bool smooth) |
void | SetInterpolationMode (int mode) |
void | TransformXY (float(*processor)(float x, float y, float value)) |
void | TransformAB (float a, float b, float(*processor)(float a, float b, float value)) |
void | GenerateNoise () |
void | ExportRGB256 (GLubyte *data_pointer) |
void | Export (float *data_pointer) |
void | GetDimensions (int &dim_x, int &dim_y) |
void | Push () |
void | FlushToColorBuffer () |
void | CombineColorBuffers (float(*combiner)(float val_1, float val_2)) |
void | CombineColorBuffersAB (float a, float b, float(*combiner)(float a, float b, float val_1, float val_2)) |
void | SmoothBorder (int border) |
Static Public Member Functions | |
static float | RangeTransform (float a, float b, float perlin_xy) |
static float | LinearTransform (float a, float b, float perlin_xy) |
static float | MarblyTransform (float x, float y, float perlin_xy) |
static float | GrainyTransform (float x, float y, float perlin_xy) |
static float | SumCombiner (float val_1, float val_2) |
static float | ProductCombiner (float val_1, float val_2) |
static float | MaximumCombiner (float val_1, float val_2) |
static float | WeightedSumCombiner (float weight_1, float weight_2, float val_1, float val_2) |
Private Types | |
typedef PerlinNoise::StackElem | PerlinStack |
Private Member Functions | |
PerlinNoise () | |
void | Pop () |
bool | IsEmpty () |
float | GetSmoothedValue (float x, float y) |
float | GetNoiseValue (float x, float y) |
float | GetNoise2D (int x, int y) |
float | Interpolate (float value_1, float value_2, float fraction) |
float | LinearInterpolation (float value_1, float value_2, float fraction) |
float | CosineInterpolation (float value_1, float value_2, float fraction) |
float | CubicInterpolation (float value_1, float value_2, float fraction) |
Private Attributes | |
int | size_x |
int | size_y |
PerlinStack * | top |
Classes | |
struct | StackElem |
PerlinNoise is a class that can be used to generate 2 dimensional perlin noise. It contains some modified, rewritten code from the two internet sources listed below.
The whole class is stack based, which means that additional elements can be pushed onto the stack and any operation like generating the noise, transforming the noise or setting parameters is only applied to the top of the stack. Furthermore, there are some combination routines, which combine the top two elements of the stack into one single element and thereby reduce the stack size by one.
Every stack element contains two buffers, a buffer with the actual noise and a color buffer. The actual noise buffer can be filled by generating noise (with some parameters). This buffer can then be modified by applying certain transformation routines to each value of the buffer. This buffer can either be exported directly or be written into the color buffer of the stack element. This procedure will generate color values from the noise values by interpolating between the foreground and background color attributes. The color buffers of the stack elements can then either be exported to an array of color values or combined with each other by applying a certain combination routine to each of the color values.
For transforming the noise in the noise buffer or combining two color buffers of the stack, there are some basic routines implemented as static members of this class. But the transformations and combinations are in no way restriced to these routines, any routine can be used for transforming and combining the noise as long as it has the correct argument and return value types.
Sources: - http://www.animeimaging.com/asp/PerlinNoise.aspx
Definition at line 46 of file PerlinNoise.h.
|
Structure holding an element of the stack. |
|
Constructor: Brings the object into a consistent state. The dimensions of the perlin noise has to be specified when the object is created.
Definition at line 3 of file PerlinNoise.cpp. |
|
Destructor. Definition at line 14 of file PerlinNoise.cpp. |
|
Hide the default constructor. |
|
Combines the values of the color buffers of the 2 topmost elements on the stack by applying a function to all the values in the color buffer. After the two color buffers have been combined, the top element of the stack is popped from the stack. The resulting color buffer will then be on top of the stack.
Definition at line 195 of file PerlinNoise.cpp. |
|
Combines the values of the color buffers of the 2 topmost elements on the stack by applying a function that takes two additional parameters to all the values in the color buffer. After the two color buffers have been combined, the top element of the stack is popped from the stack. The resulting color buffer will then be on top of the stack
Definition at line 214 of file PerlinNoise.cpp. |
|
Use cosine interpolation between two values.
Definition at line 336 of file PerlinNoise.cpp. |
|
Use cubic interpolation between two values.
Definition at line 342 of file PerlinNoise.cpp. |
|
Exports the values of the generated perlin noise on top of the stack to an array of single precision floating point values.
Definition at line 187 of file PerlinNoise.cpp. |
|
Exports the values of the color buffer on top of the stack to an array of unsigned bytes in RGB format. This routine does not produce any meaningful result if 'FlushToColorBuffer ()' has not been called on the element currently on top of the stack.
Definition at line 172 of file PerlinNoise.cpp. |
|
Flushes the perlin noise to the color buffer by linearly interpolating the values of the perlin noise between the background and foreground color. Because the values of the perlin noise may be smaller than 0 or bigger than 1, there is no guarantee that the values written to the color buffer are between the background and foreground color. This can, however, be achieved by appying a range transform (0..1) on the perlin noise before flushing it to the color buffer. This routine does only affect the top of the stack. Definition at line 67 of file PerlinNoise.cpp. |
|
Generates a two dimensional perlin noise using the actual parameters. Transformations, direct exports and flushed to the color buffer do not produce meaningful results unless this routine has been called first. This routine does only affect the top of the stack. Definition at line 111 of file PerlinNoise.cpp. |
|
Returns the x and y dimension of the perlin noise.
Definition at line 105 of file PerlinNoise.cpp. |
|
Gets the noise at a discrete location.
Definition at line 303 of file PerlinNoise.cpp. |
|
Retrives noise at one specific point.
Definition at line 278 of file PerlinNoise.cpp. |
|
Retrieves a smoothed noise value at one specific point. This is done by evaluating the noise at (x-1,y-1), (x,y-1), (x+1,y-1), (x-1,y), (x,y), (x+1,y-1), (x-1,y+1), (x,y+1), (x+1,y+1) and weighting these values in a meaningful way.
Definition at line 265 of file PerlinNoise.cpp. |
|
Predefined transformation function that can be used with 'TransformXY (...)'. Makes the noise appear grainy.
Definition at line 367 of file PerlinNoise.cpp. |
|
Interpolates between two values using the interpolation specified by the interpolation mode.
Definition at line 315 of file PerlinNoise.cpp. |
|
Checks wheather there are elements on the stack or not. Definition at line 62 of file PerlinNoise.cpp. |
|
Interpolate linearly between two values.
Definition at line 331 of file PerlinNoise.cpp. |
|
Predefined transformation function that can be used with 'TransformAB (...)'. Transforms each point independently with new_value = old_value * a + b.
Definition at line 357 of file PerlinNoise.cpp. |
|
Predefined transformation function that can be used with 'TransformXY (...)'. Makes the noise appear marbly.
Definition at line 362 of file PerlinNoise.cpp. |
|
Predefined combiner function that can be used with 'CombineColorBuffers'. Returns the maximum of the two input values.
Definition at line 385 of file PerlinNoise.cpp. |
|
Pops the top element from the stack. Internally used after combining color buffers. Definition at line 46 of file PerlinNoise.cpp. |
|
Predefined combiner function that can be used with 'CombineColorBuffers'. Returns the product of the two input values.
Definition at line 380 of file PerlinNoise.cpp. |
|
Pushes a new element onto the stack. Definition at line 20 of file PerlinNoise.cpp. |
|
Predefined transformation function that can be used with 'TransformAB (...)'. Makes sure that the resulting value lies within a certain interval.
Definition at line 349 of file PerlinNoise.cpp. |
|
Sets the background color that will be used when the noise is transformed into color space. This routine does only affect the top of the stack.
Definition at line 76 of file PerlinNoise.cpp. |
|
Sets the foreground color that will be used when the noise is transformed into color space. This routine does only affect the top of the stack.
Definition at line 84 of file PerlinNoise.cpp. |
|
Sets the mode of interpolation used between the bare random noise values. This routine does only affect the top of the stack.
Definition at line 100 of file PerlinNoise.cpp. |
|
Sets the parameters used for the noise generation. This routine does only affect the top of the stack.
Definition at line 92 of file PerlinNoise.cpp. |
|
Smoothes the noise at the border such by linearly interpolating the values that are not farther away from the border that a certain distance. All values on the border are will be zero afterwards.
Definition at line 233 of file PerlinNoise.cpp. |
|
Predefined combiner function that can be used with 'CombineColorBuffers'. Returns the sum of the two input values.
Definition at line 375 of file PerlinNoise.cpp. |
|
Transforms the generated noise with a function that takes two parameters a and b. Each value of the noise is transformed by calling the function with both parameters on each value of the perlin noise. This routine does only affect the top of the stack.
Definition at line 164 of file PerlinNoise.cpp. |
|
Transforms the generated noise with a function that depends on the x and y coordinated of the noise. x and y, which are fed to this function, are not the dimensions of the noise. They merely depend on the frequency times coordinate values between 0 and 1 (0 at top and left/ 1 at bottom and right). This routine does only affect the top of the stack.
Definition at line 149 of file PerlinNoise.cpp. |
|
Predefined combiner function that can be used with 'CombineColorBuffersAB'. Returns the weighted sum of the two input values.
Definition at line 390 of file PerlinNoise.cpp. |
|
Size of the noise along the x dimension. Definition at line 300 of file PerlinNoise.h. |
|
Size of the noise along the y dimention. Definition at line 303 of file PerlinNoise.h. |
|
Top element of the stack. Definition at line 322 of file PerlinNoise.h. |