Package squidpony.squidmath
Class Noise
java.lang.Object
squidpony.squidmath.Noise
public class Noise extends Object
A container class for various interfaces and implementing classes that affect continuous noise, such as that produced
by
Created by Tommy Ettinger on 3/17/2017.
WhirlingNoise
or SeededNoise
, as well as static utility methods used throughout noise code.
Created by Tommy Ettinger on 3/17/2017.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Noise.Basic1D
A very simple 1D noise implementation, because a full-blown Perlin or Simplex noise implementation is probably overkill for 1D noise.static class
Noise.Exponential1D
static class
Noise.Exponential2D
static class
Noise.Exponential3D
static class
Noise.Exponential4D
static class
Noise.Exponential6D
static class
Noise.InverseLayered1D
static class
Noise.InverseLayered2D
static class
Noise.InverseLayered3D
static class
Noise.InverseLayered4D
static class
Noise.InverseLayered6D
static class
Noise.Layered1D
static class
Noise.Layered2D
static class
Noise.Layered3D
static class
Noise.Layered4D
static class
Noise.Layered6D
static interface
Noise.Noise1D
static interface
Noise.Noise2D
static interface
Noise.Noise3D
static interface
Noise.Noise4D
static interface
Noise.Noise6D
static class
Noise.QuilezNoise
A hybrid between value and gradient noise that may be faster for 1D noise.static class
Noise.Ridged2D
static class
Noise.Ridged3D
static class
Noise.Ridged4D
static class
Noise.Ridged6D
static class
Noise.Scaled1D
static class
Noise.Scaled2D
static class
Noise.Scaled3D
static class
Noise.Scaled4D
static class
Noise.Scaled6D
static class
Noise.Slick2D
static class
Noise.Slick3D
static class
Noise.Slick4D
static class
Noise.Slick6D
static class
Noise.Sway1D
static class
Noise.Sway2D
static class
Noise.Turbulent2D
static class
Noise.Turbulent3D
static class
Noise.Turbulent4D
static class
Noise.Turbulent6D
static class
Noise.Viny2D
static class
Noise.Viny3D
static class
Noise.Viny4D
static class
Noise.Viny6D
-
Field Summary
Fields Modifier and Type Field Description static SeededNoise
alternate
static double
total
-
Constructor Summary
Constructors Constructor Description Noise()
-
Method Summary
Modifier and Type Method Description static double
cerp(double start, double end, double a)
Cubic-interpolates between start and end (valid doubles), with a between 0 (yields start) and 1 (yields end).static float
cerp(float start, float end, float a)
Cubic-interpolates between start and end (valid floats), with a between 0 (yields start) and 1 (yields end).static double
emphasize(double a)
Given a floata
from 0.0 to 1.0 (both inclusive), this gets a float that adjusts a to be closer to the end points of that range (if less than 0.5, it gets closer to 0.0, otherwise it gets closer to 1.0).static double
emphasizeSigned(double a)
Given a floata
from -1.0 to 1.0 (both inclusive), this gets a float that adjusts a to be closer to the end points of that range (if less than 0, it gets closer to -1.0, otherwise it gets closer to 1.0).static double
extreme(double a)
Given a doublea
from 0.0 to 1.0 (both inclusive), this gets a double that adjusts a to be much closer to the end points of that range (if less than 0.5, it gets closer to 0.0, otherwise it gets closer to 1.0).static double
extremeSigned(double a)
Given a doublea
from -1.0 to 1.0 (both inclusive), this gets a double that adjusts a to be much closer to the end points of that range (if less than 0, it gets closer to -1.0, otherwise it gets closer to 1.0).static int
fastCeil(double t)
LikeMath.ceil(double)
, but returns an int.static int
fastCeil(float t)
LikeMath.ceil(double)
, but takes a float and returns an int.static int
fastFloor(double t)
LikeMath.floor(double)
, but returns an int.static int
fastFloor(float t)
LikeMath.floor(double)
, but takes a float and returns an int.static double
lerp(double start, double end, double a)
Linear-interpolates between start and end (valid doubles), with a between 0 (yields start) and 1 (yields end).static float
lerp(float start, float end, float a)
Linear-interpolates between start and end (valid floats), with a between 0 (yields start) and 1 (yields end).static long
longFloor(double t)
LikeMath.floor(double)
, but returns a long.static long
longFloor(float t)
LikeMath.floor(double)
, but takes a float and returns a long.static double
querp(double start, double end, double a)
static float
querp(float start, float end, float a)
static double
seamless1D(Noise.Noise2D noise, double x, double sizeX, long seed)
Likeseamless2D(double[][], long, int, Noise4D)
, but this produces 1D noise that "tiles" by repeating its output everysizeX
units thatx
increases or decreases by.static double[][]
seamless2D(double[][] fill, int seed, int octaves)
Fills the given 2D array (modifying it) with noise, using values from -1.0 to 1.0, that is seamless on all boundaries.static double[][]
seamless2D(double[][] fill, long seed, int octaves, Noise.Noise4D generator)
Fills the given 2D array (modifying it) with noise, using values from -1.0 to 1.0, that is seamless on all boundaries.static double[][]
seamless2D(int width, int height, int seed, int octaves)
Produces a 2D array of noise with values from -1.0 to 1.0 that is seamless on all boundaries.static double
seamless2D(Noise.Noise4D noise, double x, double y, double sizeX, double sizeY, long seed)
Likeseamless2D(double[][], long, int, Noise4D)
, but this doesn't precalculate noise into an array, instead calculating just one 2D point so that later calls with different x or y will tile seamlessly.static double[][][]
seamless3D(double[][][] fill, long seed, int octaves)
Fills the given 3D array (modifying it) with noise, using values from -1.0 to 1.0, that is seamless on all boundaries.static double[][][]
seamless3D(double[][][] fill, long seed, int octaves, Noise.Noise6D generator)
Fills the given 3D array (modifying it) with noise, using values from -1.0 to 1.0, that is seamless on all boundaries.static float[][][]
seamless3D(float[][][] fill, long seed, int octaves)
Fills the given 3D array (modifying it) with noise, using values from -1.0 to 1.0, that is seamless on all boundaries.static double[][][]
seamless3D(int depth, int width, int height, long seed, int octaves)
Produces a 3D array of noise with values from -1.0 to 1.0 that is seamless on all boundaries.static double
seamless3D(Noise.Noise6D noise, double x, double y, double z, double sizeX, double sizeY, double sizeZ, long seed)
Likeseamless3D(double[][][], long, int, Noise6D)
, but this doesn't precalculate noise into an array, instead calculating just one 3D point so that later calls with different x, y, or z will tile seamlessly.
-
Field Details
-
Constructor Details
-
Method Details
-
longFloor
LikeMath.floor(double)
, but returns a long. Doesn't consider weird doubles like INFINITY and NaN.- Parameters:
t
- the double to find the floor for- Returns:
- the floor of t, as a long
-
longFloor
LikeMath.floor(double)
, but takes a float and returns a long. Doesn't consider weird floats like INFINITY and NaN.- Parameters:
t
- the double to find the floor for- Returns:
- the floor of t, as a long
-
fastFloor
LikeMath.floor(double)
, but returns an int. Doesn't consider weird doubles like INFINITY and NaN.- Parameters:
t
- the float to find the floor for- Returns:
- the floor of t, as an int
-
fastFloor
LikeMath.floor(double)
, but takes a float and returns an int. Doesn't consider weird floats like INFINITY and NaN.- Parameters:
t
- the float to find the floor for- Returns:
- the floor of t, as an int
-
fastCeil
LikeMath.ceil(double)
, but returns an int. Doesn't consider weird doubles like INFINITY and NaN.- Parameters:
t
- the float to find the ceiling for- Returns:
- the ceiling of t, as an int
-
fastCeil
LikeMath.ceil(double)
, but takes a float and returns an int. Doesn't consider weird floats like INFINITY and NaN.- Parameters:
t
- the float to find the ceiling for- Returns:
- the ceiling of t, as an int
-
cerp
Cubic-interpolates between start and end (valid doubles), with a between 0 (yields start) and 1 (yields end). Will smoothly transition toward start or end as a approaches 0 or 1, respectively. Somewhat faster than quintic interpolation (querp(double, double, double)
), but slower (and smoother) thanlerp(double, double, double)
.- Parameters:
start
- a valid doubleend
- a valid doublea
- a double between 0 and 1 inclusive- Returns:
- a double between start and end inclusive
-
cerp
Cubic-interpolates between start and end (valid floats), with a between 0 (yields start) and 1 (yields end). Will smoothly transition toward start or end as a approaches 0 or 1, respectively. Somewhat faster than quintic interpolation (querp(float, float, float)
), but slower (and smoother) thanlerp(float, float, float)
.- Parameters:
start
- a valid floatend
- a valid floata
- a float between 0 and 1 inclusive- Returns:
- a float between start and end inclusive
-
querp
-
querp
-
lerp
Linear-interpolates between start and end (valid doubles), with a between 0 (yields start) and 1 (yields end).- Parameters:
start
- a valid double, as in, not infinite or NaNend
- a valid double, as in, not infinite or NaNa
- a double between 0 and 1 inclusive- Returns:
- a double between x and y inclusive
-
lerp
Linear-interpolates between start and end (valid floats), with a between 0 (yields start) and 1 (yields end).- Parameters:
start
- a valid float, as in, not infinite or NaNend
- a valid float, as in, not infinite or NaNa
- a float between 0 and 1 inclusive- Returns:
- a float between x and y inclusive
-
emphasize
Given a floata
from 0.0 to 1.0 (both inclusive), this gets a float that adjusts a to be closer to the end points of that range (if less than 0.5, it gets closer to 0.0, otherwise it gets closer to 1.0).- Parameters:
a
- a float between 0.0f and 1.0f inclusive- Returns:
- a float between 0.0f and 1.0f inclusive that is more likely to be near the extremes
-
emphasizeSigned
Given a floata
from -1.0 to 1.0 (both inclusive), this gets a float that adjusts a to be closer to the end points of that range (if less than 0, it gets closer to -1.0, otherwise it gets closer to 1.0).
Used byClassicNoise
andJitterNoise
to increase the frequency of high and low results, which improves the behavior ofNoise.Ridged2D
and other Ridged noise when it uses those noise algorithms.- Parameters:
a
- a float between -1.0f and 1.0f inclusive- Returns:
- a float between -1.0f and 1.0f inclusive that is more likely to be near the extremes
-
extreme
Given a doublea
from 0.0 to 1.0 (both inclusive), this gets a double that adjusts a to be much closer to the end points of that range (if less than 0.5, it gets closer to 0.0, otherwise it gets closer to 1.0).- Parameters:
a
- a double between 0.0 and 1.0 inclusive- Returns:
- a double between 0.0 and 1.0 inclusive that is more likely to be near the extremes
-
extremeSigned
Given a doublea
from -1.0 to 1.0 (both inclusive), this gets a double that adjusts a to be much closer to the end points of that range (if less than 0, it gets closer to -1.0, otherwise it gets closer to 1.0).- Parameters:
a
- a double between -1.0 and 1.0 inclusive- Returns:
- a double between -1.0 and 1.0 inclusive that is more likely to be near the extremes
-
seamless2D
Produces a 2D array of noise with values from -1.0 to 1.0 that is seamless on all boundaries. Uses (x,y) order. Allows a seed to change the generated noise. If you need to call this very often, considerseamless2D(double[][], int, int)
, which re-uses the array.- Parameters:
width
- the width of the array to produce (the length of the outer layer of arrays)height
- the height of the array to produce (the length of the inner arrays)seed
- an int seed that affects the noise produced, with different seeds producing very different noiseoctaves
- how many runs of differently sized and weighted noise generations to apply to the same area- Returns:
- a freshly-allocated seamless-bounded array, a
double[width][height]
.
-
seamless2D
Fills the given 2D array (modifying it) with noise, using values from -1.0 to 1.0, that is seamless on all boundaries. This overload doesn't care what you use for x or y axes, it uses the exact size of fill fully. Allows a seed to change the generated noise.- Parameters:
fill
- a 2D array of double; must be rectangular, so it's a good idea to create withnew double[width][height]
or something similarseed
- an int seed that affects the noise produced, with different seeds producing very different noiseoctaves
- how many runs of differently sized and weighted noise generations to apply to the same area- Returns:
fill
, after assigning it with seamless-bounded noise
-
seamless2D
public static double[][] seamless2D(double[][] fill, long seed, int octaves, Noise.Noise4D generator)Fills the given 2D array (modifying it) with noise, using values from -1.0 to 1.0, that is seamless on all boundaries. This overload doesn't care what you use for x or y axes, it uses the exact size of fill fully. Allows a seed to change the generated noise. DOES NOT clear the values in fill, so if it already has non-zero elements, the result will be different than if it had been cleared beforehand. That does allow you to utilize this method to add multiple seamless noise values on top of each other, though that allows values to go above or below the normal minimum and maximum (-1.0 to 1.0).- Parameters:
fill
- a 2D array of double; must be rectangular, so it's a good idea to create withnew double[width][height]
or something similarseed
- an int seed that affects the noise produced, with different seeds producing very different noiseoctaves
- how many runs of differently sized and weighted noise generations to apply to the same area- Returns:
fill
, after assigning it with seamless-bounded noise
-
seamless3D
Produces a 3D array of noise with values from -1.0 to 1.0 that is seamless on all boundaries. Allows a seed to change the generated noise. Because most games that would use this would use it for maps, and maps are often top-down, the returned 3D array uses the order (z,x,y), which allows a 2D slice of x and y to be taken as an element from the top-level array. If you need to call this very often, considerseamless3D(double[][][], long, int)
, which re-uses the array instead of re-generating it.- Parameters:
width
- the width of the array to produce (the length of the middle layer of arrays)height
- the height of the array to produce (the length of the innermost arrays)depth
- the depth of the array to produce (the length of the outermost layer of arrays)seed
- an int seed that affects the noise produced, with different seeds producing very different noiseoctaves
- how many runs of differently sized and weighted noise generations to apply to the same area- Returns:
- a freshly-allocated seamless-bounded array, a
double[depth][width][height]
.
-
seamless3D
Fills the given 3D array (modifying it) with noise, using values from -1.0 to 1.0, that is seamless on all boundaries. This overload doesn't care what you use for x, y, or z axes, it uses the exact size of fill fully. Allows a seed to change the generated noise.- Parameters:
fill
- a 3D array of double; must be rectangular, so it's a good idea to create withnew double[depth][width][height]
or something similarseed
- an int seed that affects the noise produced, with different seeds producing very different noiseoctaves
- how many runs of differently sized and weighted noise generations to apply to the same area- Returns:
fill
, after assigning it with seamless-bounded noise
-
seamless3D
public static double[][][] seamless3D(double[][][] fill, long seed, int octaves, Noise.Noise6D generator)Fills the given 3D array (modifying it) with noise, using values from -1.0 to 1.0, that is seamless on all boundaries. This overload doesn't care what you use for x, y, or z axes, it uses the exact size of fill fully. Allows a seed to change the generated noise.- Parameters:
fill
- a 3D array of double; must be rectangular, so it's a good idea to create withnew double[depth][width][height]
or something similarseed
- an int seed that affects the noise produced, with different seeds producing very different noiseoctaves
- how many runs of differently sized and weighted noise generations to apply to the same area- Returns:
fill
, after assigning it with seamless-bounded noise
-
seamless3D
Fills the given 3D array (modifying it) with noise, using values from -1.0 to 1.0, that is seamless on all boundaries. This overload doesn't care what you use for x, y, or z axes, it uses the exact size of fill fully. Allows a seed to change the generated noise.- Parameters:
fill
- a 3D array of double; must be rectangular, so it's a good idea to create withnew double[depth][width][height]
or something similarseed
- an int seed that affects the noise produced, with different seeds producing very different noiseoctaves
- how many runs of differently sized and weighted noise generations to apply to the same area- Returns:
fill
, after assigning it with seamless-bounded noise
-
seamless1D
Likeseamless2D(double[][], long, int, Noise4D)
, but this produces 1D noise that "tiles" by repeating its output everysizeX
units thatx
increases or decreases by. This doesn't precalculate an array, instead calculating just one value so that later calls with different x will tile seamlessly.
Internally, this just samples out of a circle from a source of 2D noise.- Parameters:
noise
- a Noise2D implementation such as aSeededNoise
orFastNoise
x
- the x-coordinate to samplesizeX
- the range of x to generate before repeating; must be greater than 0seed
- the noise seed, as a long- Returns:
- continuous noise from -1.0 to 1.0, inclusive
-
seamless2D
public static double seamless2D(Noise.Noise4D noise, double x, double y, double sizeX, double sizeY, long seed)Likeseamless2D(double[][], long, int, Noise4D)
, but this doesn't precalculate noise into an array, instead calculating just one 2D point so that later calls with different x or y will tile seamlessly.- Parameters:
noise
- a Noise4D implementation such as aSeededNoise
orFastNoise
x
- the x-coordinate to sampley
- the y-coordinate to samplesizeX
- the range of x to generate before repeating; must be greater than 0sizeY
- the range of y to generate before repeating; must be greater than 0seed
- the noise seed, as a long- Returns:
- continuous noise from -1.0 to 1.0, inclusive
-
seamless3D
public static double seamless3D(Noise.Noise6D noise, double x, double y, double z, double sizeX, double sizeY, double sizeZ, long seed)Likeseamless3D(double[][][], long, int, Noise6D)
, but this doesn't precalculate noise into an array, instead calculating just one 3D point so that later calls with different x, y, or z will tile seamlessly.- Parameters:
noise
- a Noise6D implementation such as aSeededNoise
orFastNoise
x
- the x-coordinate to sampley
- the y-coordinate to samplez
- the z-coordinate to samplesizeX
- the range of x to generate before repeating; must be greater than 0sizeY
- the range of y to generate before repeating; must be greater than 0sizeZ
- the range of z to generate before repeating; must be greater than 0seed
- the noise seed, as a long- Returns:
- continuous noise from -1.0 to 1.0, inclusive
-