Package squidpony.squidmath
Class WhiteNoise
java.lang.Object
squidpony.squidmath.WhiteNoise
- All Implemented Interfaces:
Noise.Noise1D
,Noise.Noise2D
,Noise.Noise3D
,Noise.Noise4D
,Noise.Noise6D
public class WhiteNoise extends Object implements Noise.Noise1D, Noise.Noise2D, Noise.Noise3D, Noise.Noise4D, Noise.Noise6D
Performance-oriented white noise generator for 1D, 2D, 3D, 4D, and 6D. Produces noise values from -1.0 inclusive
to 1.0 exclusive. Should produce a completely different double even for extremely-nearby points, so this is not a
kind of continuous noise like
Meant for cases where you want to use a different number for every pixel, tile, or other unit of noise generated, often coupled with another kind of noise but with the result of the WhiteNoise made less significant to add a "fuzzy" effect to the appearance.
Implementation is based on
This can also be used as a sort of hashing function that produces a double, if you find a need for such a thing, with
SeededNoise
. It is not actually random, and the value is always determined by
the exact double positions (and possibly a long seed) given to it. Even a slight change should drastically alter the
returned value, though below some very small epsilon the results might not be different between two very close points
in space. The output should look like "TV static" if rendered as grayscale pixels.
Meant for cases where you want to use a different number for every pixel, tile, or other unit of noise generated, often coupled with another kind of noise but with the result of the WhiteNoise made less significant to add a "fuzzy" effect to the appearance.
Implementation is based on
CrossHash.Wisp.hash64(double[])
, treating doubles as ints
by using NumberTools.doubleToMixedIntBits(double)
, which XORs the bottom and top halves of the long bits of
each double. Finishes by passing the top 52 bits as a significand to NumberTools.longBitsToDouble(long)
,
using an exponent that allows this to produce numbers between -1.0 and 1.0. Has special treatment for the seed when
present (since it is a long).
This can also be used as a sort of hashing function that produces a double, if you find a need for such a thing, with
hash(double...)
.-
Field Summary
Fields Modifier and Type Field Description static WhiteNoise
instance
-
Constructor Summary
Constructors Constructor Description WhiteNoise()
-
Method Summary
Modifier and Type Method Description double
getNoise(double x)
double
getNoise(double x, double y)
double
getNoise(double x, double y, double z)
double
getNoise(double x, double y, double z, double w)
double
getNoise(double x, double y, double z, double w, double u, double v)
double
getNoiseWithSeed(double x, double y, double z, double w, double u, double v, long seed)
double
getNoiseWithSeed(double x, double y, double z, double w, long seed)
double
getNoiseWithSeed(double x, double y, double z, long seed)
double
getNoiseWithSeed(double x, double y, long seed)
double
getNoiseWithSeed(double x, long seed)
static double
hash(double... data)
Hashes the input double array or vararg and produces a double with unpredictable value, between -1.0 inclusive and 1.0 exclusive.
-
Field Details
-
Constructor Details
-
WhiteNoise
public WhiteNoise()
-
-
Method Details
-
getNoise
- Specified by:
getNoise
in interfaceNoise.Noise1D
-
getNoiseWithSeed
- Specified by:
getNoiseWithSeed
in interfaceNoise.Noise1D
-
getNoise
- Specified by:
getNoise
in interfaceNoise.Noise2D
-
getNoiseWithSeed
- Specified by:
getNoiseWithSeed
in interfaceNoise.Noise2D
-
getNoise
- Specified by:
getNoise
in interfaceNoise.Noise3D
-
getNoiseWithSeed
- Specified by:
getNoiseWithSeed
in interfaceNoise.Noise3D
-
getNoise
- Specified by:
getNoise
in interfaceNoise.Noise4D
-
getNoiseWithSeed
- Specified by:
getNoiseWithSeed
in interfaceNoise.Noise4D
-
getNoise
- Specified by:
getNoise
in interfaceNoise.Noise6D
-
getNoiseWithSeed
public double getNoiseWithSeed(double x, double y, double z, double w, double u, double v, long seed)- Specified by:
getNoiseWithSeed
in interfaceNoise.Noise6D
-
hash
Hashes the input double array or vararg and produces a double with unpredictable value, between -1.0 inclusive and 1.0 exclusive.- Parameters:
data
- an array or vararg of double items; should not include NaN or infinite values but has no other limits- Returns:
- an unpredictable double between -1.0 inclusive and 1.0 exclusive
-