Package squidpony.squidmath
Class SeededNoise
java.lang.Object
squidpony.squidmath.SeededNoise
- All Implemented Interfaces:
Noise.Noise2D
,Noise.Noise3D
,Noise.Noise4D
,Noise.Noise6D
- Direct Known Subclasses:
WhirlingNoise
public class SeededNoise extends Object implements Noise.Noise2D, Noise.Noise3D, Noise.Noise4D, Noise.Noise6D
More advanced noise functions, in 2D, 3D, 4D, and 6D, with the last two as options for generating seamlessly-tiling
noise using
Noise.seamless2D(double[][], long, int, Noise.Noise4D)
and/or
Noise.seamless3D(double[][][], long, int, Noise.Noise6D)
. All functions can take a long seed that should
significantly change the pattern of noise produced. Incorporates code from Joise; the full library is available at
https://github.com/SudoPlayGames/Joise , and this class adds rather significant optimization in a few methods,
especially 6D noise. Joise is derived from the Accidental Noise Library, available in C++ at
http://accidentalnoise.sourceforge.net/index.html . Both Joise and ANL have many features that SquidLib has not (yet)
incorporated, but now that SquidLib has seamless noise, that's a nice feature that would have needed Joise before.-
Field Summary
Fields Modifier and Type Field Description protected long
defaultSeed
protected static double
F2
protected static double
F3
protected static double
F4
protected static double
F6
protected static double
G2
protected static double
G3
protected static double
G4
protected static double
G6
protected static float[]
grad3d
protected static double[]
grad4d
protected static double[]
gradient6DLUT
static SeededNoise
instance
protected static double
LIMIT4
protected static double
LIMIT6
static double[][]
phiGrad2
256 2-element gradient vectors formed from the cos and sin of increasing multiples of the inverse of phi, the golden ratio, while also adding increasing multiples of 2/3 of the reciprocal ofMath.E
.protected static int[]
SIMPLEX_4D
Used bynoise(double, double, double, double, long)
to look up the vertices of the 4D triangle analogue. -
Constructor Summary
Constructors Constructor Description SeededNoise()
SeededNoise(long seed)
-
Method Summary
Modifier and Type Method Description 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)
protected static double
gradCoord3D(long seed, int x, int y, int z, double xd, double yd, double zd)
Computes the hash for a 3D int point and its dot product with a 3D double point as one step.static double
noise(double x, double y, double z, double w, double u, double v, long seed)
static double
noise(double x, double y, double z, double w, long seed)
static double
noise(double x, double y, double z, long seed)
static double
noise(double x, double y, long seed)
-
Field Details
-
phiGrad2
256 2-element gradient vectors formed from the cos and sin of increasing multiples of the inverse of phi, the golden ratio, while also adding increasing multiples of 2/3 of the reciprocal ofMath.E
. This produces a sequence with remarkably low overlap possible from nearby angles, distributed nicely around the unit circle. For i from 1 to 256 inclusive, this gets the cosine and sine of an angle in radians of0.61803398874989484820458683436563811772 * i + (i / (1.5 * 2.7182818284590452354))
. This is expected to be accessed using an 8-bit int (depending on how you got your int, the normal way to get 8 bits would beindex & 255
), but smaller numbers should also work down to about 4 bits (typically usingindex & 15
). -
grad3d
-
grad4d
-
defaultSeed
-
instance
-
gradient6DLUT
-
SIMPLEX_4D
Used bynoise(double, double, double, double, long)
to look up the vertices of the 4D triangle analogue. -
F2
- See Also:
- Constant Field Values
-
G2
- See Also:
- Constant Field Values
-
F3
- See Also:
- Constant Field Values
-
G3
- See Also:
- Constant Field Values
-
F4
-
G4
-
LIMIT4
- See Also:
- Constant Field Values
-
F6
-
G6
-
LIMIT6
- See Also:
- Constant Field Values
-
-
Constructor Details
-
SeededNoise
public SeededNoise() -
SeededNoise
-
-
Method Details
-
gradCoord3D
protected static double gradCoord3D(long seed, int x, int y, int z, double xd, double yd, double zd)Computes the hash for a 3D int point and its dot product with a 3D double point as one step.- Parameters:
seed
-x
-y
-z
-xd
-yd
-zd
-- Returns:
- a double between -1.2571 and 1.2571, exclusive
-
getNoise
- Specified by:
getNoise
in interfaceNoise.Noise2D
-
getNoise
- Specified by:
getNoise
in interfaceNoise.Noise3D
-
getNoise
- Specified by:
getNoise
in interfaceNoise.Noise4D
-
getNoise
- Specified by:
getNoise
in interfaceNoise.Noise6D
-
getNoiseWithSeed
- Specified by:
getNoiseWithSeed
in interfaceNoise.Noise2D
-
getNoiseWithSeed
- Specified by:
getNoiseWithSeed
in interfaceNoise.Noise3D
-
getNoiseWithSeed
- Specified by:
getNoiseWithSeed
in interfaceNoise.Noise4D
-
getNoiseWithSeed
public double getNoiseWithSeed(double x, double y, double z, double w, double u, double v, long seed)- Specified by:
getNoiseWithSeed
in interfaceNoise.Noise6D
-
noise
-
noise
-
noise
-
noise
-