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 classNoise.Basic1DA very simple 1D noise implementation, because a full-blown Perlin or Simplex noise implementation is probably overkill for 1D noise.static classNoise.Exponential1Dstatic classNoise.Exponential2Dstatic classNoise.Exponential3Dstatic classNoise.Exponential4Dstatic classNoise.Exponential6Dstatic classNoise.InverseLayered1Dstatic classNoise.InverseLayered2Dstatic classNoise.InverseLayered3Dstatic classNoise.InverseLayered4Dstatic classNoise.InverseLayered6Dstatic classNoise.Layered1Dstatic classNoise.Layered2Dstatic classNoise.Layered3Dstatic classNoise.Layered4Dstatic classNoise.Layered6Dstatic interfaceNoise.Noise1Dstatic interfaceNoise.Noise2Dstatic interfaceNoise.Noise3Dstatic interfaceNoise.Noise4Dstatic interfaceNoise.Noise6Dstatic classNoise.QuilezNoiseA hybrid between value and gradient noise that may be faster for 1D noise.static classNoise.Ridged2Dstatic classNoise.Ridged3Dstatic classNoise.Ridged4Dstatic classNoise.Ridged6Dstatic classNoise.Scaled1Dstatic classNoise.Scaled2Dstatic classNoise.Scaled3Dstatic classNoise.Scaled4Dstatic classNoise.Scaled6Dstatic classNoise.Slick2Dstatic classNoise.Slick3Dstatic classNoise.Slick4Dstatic classNoise.Slick6Dstatic classNoise.Sway1Dstatic classNoise.Sway2Dstatic classNoise.Turbulent2Dstatic classNoise.Turbulent3Dstatic classNoise.Turbulent4Dstatic classNoise.Turbulent6Dstatic classNoise.Viny2Dstatic classNoise.Viny3Dstatic classNoise.Viny4Dstatic classNoise.Viny6D -
Field Summary
Fields Modifier and Type Field Description static SeededNoisealternatestatic doubletotal -
Constructor Summary
Constructors Constructor Description Noise() -
Method Summary
Modifier and Type Method Description static doublecerp(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 floatcerp(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 doubleemphasize(double a)Given a floatafrom 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 doubleemphasizeSigned(double a)Given a floatafrom -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 doubleextreme(double a)Given a doubleafrom 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 doubleextremeSigned(double a)Given a doubleafrom -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 intfastCeil(double t)LikeMath.ceil(double), but returns an int.static intfastCeil(float t)LikeMath.ceil(double), but takes a float and returns an int.static intfastFloor(double t)LikeMath.floor(double), but returns an int.static intfastFloor(float t)LikeMath.floor(double), but takes a float and returns an int.static doublelerp(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 floatlerp(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 longlongFloor(double t)LikeMath.floor(double), but returns a long.static longlongFloor(float t)LikeMath.floor(double), but takes a float and returns a long.static doublequerp(double start, double end, double a)static floatquerp(float start, float end, float a)static doubleseamless1D(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 everysizeXunits thatxincreases 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 doubleseamless2D(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 doubleseamless3D(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 floatafrom 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 floatafrom -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 byClassicNoiseandJitterNoiseto increase the frequency of high and low results, which improves the behavior ofNoise.Ridged2Dand 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 doubleafrom 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 doubleafrom -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 everysizeXunits thatxincreases 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 aSeededNoiseorFastNoisex- 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 aSeededNoiseorFastNoisex- 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 aSeededNoiseorFastNoisex- 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
-