Package com.github.tommyettinger.random
Class LineWobble
java.lang.Object
com.github.tommyettinger.random.LineWobble
Provides 1D noise methods that can be queried at any point on a line to get a continuous random value.
These each use some form of low-quality, high-speed unary hash on the floor and ceiling of a float or double value,
then interpolate between the hash results. Some of these work on angles (so they wrap like a line around a circle)
instead of normal lines.
Some methods here were named... hastily, but the names stuck.
Some methods here were named... hastily, but the names stuck.
wobble(int, float)
is straightforward; it uses a hermite spline to interpolate two points.bicubicWobble(int, float)
uses bicubic interpolation on 4 points, and tends to be smooth.quobble(int, float)
uses an unusual method that requires less randomization, but returns to 0 predictably.quobbleOctave2(int, float)
is the above quobble() called twice at different frequencies and weights.splobble(int, float)
can be much more sharp or smooth, varying randomly over its length.hobble(long, long, float)
is like splobble(), but allows specifying the random bits manually.trobble(int, float)
is a trigonometric wobble, using the sine table to smoothly transition.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
bicubicWobble
(int seed, double t) Sway smoothly using bicubic interpolation between 4 points (the two integers before t and the two after).static float
bicubicWobble
(int seed, float t) Sway smoothly using bicubic interpolation between 4 points (the two integers before t and the two after).static double
bicubicWobble
(long seed, double t) Sway smoothly using bicubic interpolation between 4 points (the two integers before t and the two after).static float
bicubicWobble
(long seed, float t) Sway smoothly using bicubic interpolation between 4 points (the two integers before t and the two after).static float[]
generateLookupTable
(int seed, int size, int points, int octaves) Creates a wrapping lookup table ofsize
float items for a wobbling line, using a specific count of points where the wobble can reach a peak or valley, a number of octaves to refine the wobble, and a seed.static float[]
generateSplineLookupTable
(int seed, int size, int points, int octaves, float shape, float turning) Creates a wrapping lookup table ofsize
float items for a wobbling line, using a specific count of points where the wobble can reach a peak or valley, a number of octaves to refine the wobble, and a seed.static double
hobble
(long startBits, long endBits, double value) A variant onsplobble(long, double)
that takes some kind of hash-generatedlong
s for thestartBits
andendBits
.static float
hobble
(long startBits, long endBits, float value) A variant onsplobble(long, float)
that takes some kind of hash-generatedlong
s for thestartBits
andendBits
.static double
quobble
(int seed, double value) Quilez' 1D noise, with some changes to work on the CPU.static float
quobble
(int seed, float value) Quilez' 1D noise, with some changes to work on the CPU.static double
quobble
(long seed, double value) Quilez' 1D noise, with some changes to work on the CPU.static float
quobble
(long seed, float value) Quilez' 1D noise, with some changes to work on the CPU.static double
quobbleOctave2
(int seed, double x) Just gets two octaves ofquobble(int, double)
; still has a range of -1 to 1.static float
quobbleOctave2
(int seed, float x) Just gets two octaves ofquobble(int, float)
; still has a range of -1 to 1.static double
quobbleOctave2
(long seed, double x) Just gets two octaves ofquobble(long, double)
; still has a range of -1 to 1.static float
quobbleOctave2
(long seed, float x) Just gets two octaves ofquobble(long, float)
; still has a range of -1 to 1.static double
smoothWobble
(int seed, double t) Sway very smoothly using bicubic interpolation between 4 points (the two integers before t and the two after), and additional processing at the last step to push results closer to the min and max valid values.static float
smoothWobble
(int seed, float t) Sway very smoothly using bicubic interpolation between 4 points (the two integers before t and the two after), and additional processing at the last step to push results closer to the min and max valid values.static double
smoothWobble
(long seed, double t) Sway very smoothly using bicubic interpolation between 4 points (the two integers before t and the two after), and additional processing at the last step to push results closer to the min and max valid values.static float
smoothWobble
(long seed, float t) Sway very smoothly using bicubic interpolation between 4 points (the two integers before t and the two after), and additional processing at the last step to push results closer to the min and max valid values.static double
splobble
(int seed, double value) A variant onwobble(int, double)
that usesMathTools.barronSpline(double, double, double)
to interpolate between peaks/valleys, with the shape and turning point determined like the other values.static float
splobble
(int seed, float value) A variant onwobble(int, float)
that usesMathTools.barronSpline(float, float, float)
to interpolate between peaks/valleys, with the shape and turning point determined like the other values.static double
splobble
(long seed, double value) A variant onwobble(long, double)
that usesMathTools.barronSpline(double, double, double)
to interpolate between peaks/valleys, with the shape and turning point determined like the other values.static float
splobble
(long seed, float value) A variant onwobble(long, float)
that usesMathTools.barronSpline(float, float, float)
to interpolate between peaks/valleys, with the shape and turning point determined like the other values.static float
splobbleAngle
(int seed, float value) Likesplobble(int, float)
, this is a 1D wobble that can become more sharp or more gradual at different points on its length, but this produces a (wrapping) angle measured in radians.static float
splobbleAngle
(long seed, float value) Likesplobble(long, float)
, this is a 1D wobble that can become more sharp or more gradual at different points on its length, but this produces a (wrapping) angle measured in radians.static float
splobbleAngleDeg
(int seed, float value) Likesplobble(int, float)
, this is a 1D wobble that can become more sharp or more gradual at different points on its length, but this produces a (wrapping) angle measured in degrees.static float
splobbleAngleDeg
(long seed, float value) Likesplobble(long, float)
, this is a 1D wobble that can become more sharp or more gradual at different points on its length, but this produces a (wrapping) angle measured in degrees.static float
splobbleAngleTurns
(int seed, float value) Likesplobble(int, float)
, this is a 1D wobble that can become more sharp or more gradual at different points on its length, but this produces a (wrapping) angle measured in turns.static float
splobbleAngleTurns
(long seed, float value) Likesplobble(long, float)
, this is a 1D wobble that can become more sharp or more gradual at different points on its length, but this produces a (wrapping) angle measured in turns.static double
trobble
(int seed, double value) Trigonometric wobble.static float
trobble
(int seed, float value) Trigonometric wobble.static double
trobble
(long seed, double value) Trigonometric wobble.static float
trobble
(long seed, float value) Trigonometric wobble.static double
wobble
(int seed, double value) A variant onwobble(long, double)
that takes an int seed instead of a long, and is optimized for usage on GWT.static float
wobble
(int seed, float value) A variant onwobble(long, float)
that takes an int seed instead of a long, and is optimized for usage on GWT.static double
wobble
(long seed, double value) A mix of the smooth transitions of a sine wave with (seeded) random peaks and valleys between -1.0 and 1.0 (both exclusive).static float
wobble
(long seed, float value) A mix of the smooth transitions of a sine wave with (seeded) random peaks and valleys between -1f and 1f (both exclusive).static float
wobbleAngle
(int seed, float value) A 1D "noise" method that produces smooth transitions like a sine wave, but also wrapping around at pi * 2 so this can be used to get smoothly-changing random angles.static float
wobbleAngle
(long seed, float value) A 1D "noise" method that produces smooth transitions like a sine wave, but also wrapping around at pi * 2 so this can be used to get smoothly-changing random angles.static float
wobbleAngleDeg
(int seed, float value) A 1D "noise" method that produces smooth transitions like a sine wave, but also wrapping around at 360.0 so this can be used to get smoothly-changing random angles.static float
wobbleAngleDeg
(long seed, float value) A 1D "noise" method that produces smooth transitions like a sine wave, but also wrapping around at 360.0 so this can be used to get smoothly-changing random angles.static float
wobbleAngleTurns
(int seed, float value) A 1D "noise" method that produces smooth transitions like a sine wave, but also wrapping around at 1.0 so this can be used to get smoothly-changing random angles in turns.static float
wobbleAngleTurns
(long seed, float value) A 1D "noise" method that produces smooth transitions like a sine wave, but also wrapping around at 1.0 so this can be used to get smoothly-changing random angles in turns.static float
wobbleWrapped
(int seed, float value, int modulus) Very similar towobble(int, float)
, but only tolerates non-negativevalue
and wraps value when it gets too close tomodulus
.static float
wobbleWrapped
(long seed, float value, int modulus) Very similar towobble(long, float)
, but only tolerates non-negativevalue
and wraps value when it gets too close tomodulus
.static float
wobbleWrappedTight
(int seed, float value, int modulus) Very similar towobble(int, float)
, but only tolerates non-negativevalue
and wraps value when it gets too close tomodulus
.static float
wobbleWrappedTight
(long seed, float value, int modulus) Very similar towobble(long, float)
, but only tolerates non-negativevalue
and wraps value when it gets too close tomodulus
.
-
Constructor Details
-
LineWobble
public LineWobble()
-
-
Method Details
-
wobble
public static double wobble(long seed, double value) A mix of the smooth transitions of a sine wave with (seeded) random peaks and valleys between -1.0 and 1.0 (both exclusive). The pattern this will produce will be completely different if the seed changes, and it is suitable for 1D noise. Uses a simple method of cubic interpolation between random values, where a random value is used without modification when given an integer forvalue
. Note that this uses a different type of interpolation than a sine wave would, and the shape here uses cubic interpolation.- Parameters:
seed
- a long seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a double that typically changes slowly, by less than 1.0, with direction changes at integer inputs- Returns:
- a pseudo-random double between -1.0 and 1.0 (both exclusive), smoothly changing with value
-
wobble
public static float wobble(long seed, float value) A mix of the smooth transitions of a sine wave with (seeded) random peaks and valleys between -1f and 1f (both exclusive). The pattern this will produce will be completely different if the seed changes, and it is suitable for 1D noise. Uses a simple method of cubic interpolation between random values, where a random value is used without modification when given an integer forvalue
. Note that this uses a different type of interpolation than a sine wave would, and the shape here uses cubic interpolation.- Parameters:
seed
- a long seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 2.0, with direction changes at integer inputs- Returns:
- a pseudo-random float between -1f and 1f (both exclusive), smoothly changing with value
-
wobble
public static double wobble(int seed, double value) A variant onwobble(long, double)
that takes an int seed instead of a long, and is optimized for usage on GWT. Like the version with a long seed, this uses cubic interpolation between random peak or valley points; only the method of generating those random peaks and valleys has changed.- Parameters:
seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a double that typically changes slowly, by less than 2.0, with direction changes at integer inputs- Returns:
- a pseudo-random double between -1.0 and 1.0 (both exclusive), smoothly changing with value
-
wobble
public static float wobble(int seed, float value) A variant onwobble(long, float)
that takes an int seed instead of a long, and is optimized for usage on GWT. Like the version with a long seed, this uses cubic interpolation between random peak or valley points; only the method of generating those random peaks and valleys has changed.- Parameters:
seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 2.0, with direction changes at integer inputs- Returns:
- a pseudo-random float between -1f and 1f (both exclusive), smoothly changing with value
-
bicubicWobble
public static float bicubicWobble(int seed, float t) Sway smoothly using bicubic interpolation between 4 points (the two integers before t and the two after). This pretty much never produces steep changes between peaks and valleys; this may make it more useful for things like generating terrain that can be walked across in a side-scrolling game.- Parameters:
seed
- any intt
- a distance traveled; should change by less than 1 between calls, and should be less than about 10000- Returns:
- a smoothly-interpolated swaying value between -1 and 1, both exclusive
-
bicubicWobble
public static double bicubicWobble(int seed, double t) Sway smoothly using bicubic interpolation between 4 points (the two integers before t and the two after). This pretty much never produces steep changes between peaks and valleys; this may make it more useful for things like generating terrain that can be walked across in a side-scrolling game.- Parameters:
seed
- any intt
- a distance traveled; should change by less than 1 between calls- Returns:
- a smoothly-interpolated swaying value between -1 and 1, both exclusive
-
bicubicWobble
public static float bicubicWobble(long seed, float t) Sway smoothly using bicubic interpolation between 4 points (the two integers before t and the two after). This pretty much never produces steep changes between peaks and valleys; this may make it more useful for things like generating terrain that can be walked across in a side-scrolling game.- Parameters:
seed
- any longt
- a distance traveled; should change by less than 1 between calls- Returns:
- a smoothly-interpolated swaying value between -1 and 1, both exclusive
-
bicubicWobble
public static double bicubicWobble(long seed, double t) Sway smoothly using bicubic interpolation between 4 points (the two integers before t and the two after). This pretty much never produces steep changes between peaks and valleys; this may make it more useful for things like generating terrain that can be walked across in a side-scrolling game.- Parameters:
seed
- any longt
- a distance traveled; should change by less than 1 between calls- Returns:
- a smoothly-interpolated swaying value between -1 and 1, both exclusive
-
splobble
public static float splobble(int seed, float value) A variant onwobble(int, float)
that usesMathTools.barronSpline(float, float, float)
to interpolate between peaks/valleys, with the shape and turning point determined like the other values. This can be useful when you want a curve to seem more "natural," without the similarity between every peak or every valley inwobble(int, float)
. This can produce both fairly sharp turns and very gradual curves.- Parameters:
seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 2.0, with direction changes at integer inputs- Returns:
- a pseudo-random float between -1f and 1f (both exclusive), smoothly changing with value
-
splobble
public static double splobble(int seed, double value) A variant onwobble(int, double)
that usesMathTools.barronSpline(double, double, double)
to interpolate between peaks/valleys, with the shape and turning point determined like the other values. This can be useful when you want a curve to seem more "natural," without the similarity between every peak or every valley inwobble(int, double)
. This can produce both fairly sharp turns and very gradual curves.- Parameters:
seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a double that typically changes slowly, by less than 2.0, with direction changes at integer inputs- Returns:
- a pseudo-random double between -1.0 and 1.0 (both exclusive), smoothly changing with value
-
splobble
public static float splobble(long seed, float value) A variant onwobble(long, float)
that usesMathTools.barronSpline(float, float, float)
to interpolate between peaks/valleys, with the shape and turning point determined like the other values. This can be useful when you want a curve to seem more "natural," without the similarity between every peak or every valley inwobble(long, float)
. This can produce both fairly sharp turns and very gradual curves.- Parameters:
seed
- a long seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 2.0, with direction changes at integer inputs- Returns:
- a pseudo-random float between -1f and 1f (both exclusive), smoothly changing with value
-
splobble
public static double splobble(long seed, double value) A variant onwobble(long, double)
that usesMathTools.barronSpline(double, double, double)
to interpolate between peaks/valleys, with the shape and turning point determined like the other values. This can be useful when you want a curve to seem more "natural," without the similarity between every peak or every valley inwobble(long, double)
. This can produce both fairly sharp turns and very gradual curves.- Parameters:
seed
- a long seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a double that typically changes slowly, by less than 2.0, with direction changes at integer inputs- Returns:
- a pseudo-random double between -1.0 and 1.0 (both exclusive), smoothly changing with value
-
hobble
public static float hobble(long startBits, long endBits, float value) A variant onsplobble(long, float)
that takes some kind of hash-generatedlong
s for thestartBits
andendBits
. This makes this usable as a building-block for noise with more than one dimension. Unlike the other wobbling-line methods here,value
must be between 0 and 1 (inclusive). The name comes from "hash wobble." This can be useful when you want a curve to seem more "natural," without the similarity between every peak or every valley inwobble(long, float)
. This can produce both fairly sharp turns and very gradual curves.- Parameters:
startBits
- any long; determines the result exactly whenvalue
is 0, and later affects it lessendBits
- any long; determines the result exactly whenvalue
is 1, and earlier affects it lessvalue
- a float between 0f and 1f, representing how much the result is affected by the start and end bits- Returns:
- a pseudo-random float between -1f and 1f (both exclusive), smoothly changing with value
-
hobble
public static double hobble(long startBits, long endBits, double value) A variant onsplobble(long, double)
that takes some kind of hash-generatedlong
s for thestartBits
andendBits
. This makes this usable as a building-block for noise with more than one dimension. Unlike the other wobbling-line methods here,value
must be between 0 and 1 (inclusive). The name comes from "hash wobble." This can be useful when you want a curve to seem more "natural," without the similarity between every peak or every valley inwobble(long, double)
. This can produce both fairly sharp turns and very gradual curves.- Parameters:
startBits
- any long; determines the result exactly whenvalue
is 0, and later affects it lessendBits
- any long; determines the result exactly whenvalue
is 1, and earlier affects it lessvalue
- a double between 0.0 and 1.0, representing how much the result is affected by the start and end bits- Returns:
- a pseudo-random double between -1.0 and 1.0 (both exclusive), smoothly changing with value
-
quobble
public static float quobble(int seed, float value) Quilez' 1D noise, with some changes to work on the CPU. Takes a distance value and any int seed, and produces a smoothly-changing result as value goes up or down and seed stays the same. Uses a quartic curve. The quartic curve means that at specific positions, each separated by an integer from each other, the noise will reliably be 0. This does not typically happen on integers forvalue
, but it can ifseed
is 0 or some very high numbers.
The distance (value
) should be between -16384 and 1073733631 for this to return correct results. Because floats incur precision loss earlier than 1073733631, the actual upper bound is lower. The limit of -8192 comes from how this usesMathTools.fastFloor(float)
internally onvalue + value
.- Parameters:
value
- should go up and/or down steadily and by small amounts (less than 1.0, certainly)seed
- should stay the same for a given curve- Returns:
- a noise value between -1.0 and 1.0
-
quobbleOctave2
public static float quobbleOctave2(int seed, float x) Just gets two octaves ofquobble(int, float)
; still has a range of -1 to 1. This tends to look much more natural than just one octave of quobble(), because the points where it always will hit 0 are spaced differently for the two octaves here.- Parameters:
x
- should go up and/or down steadily and by small amounts (less than 1.0, certainly)seed
- should stay the same for a given curve- Returns:
- a noise value between -1.0 and 1.0
-
quobble
public static double quobble(int seed, double value) Quilez' 1D noise, with some changes to work on the CPU. Takes a distance value and any int seed, and produces a smoothly-changing result as value goes up or down and seed stays the same. Uses a quartic curve. The quartic curve means that at specific positions, each separated by an integer from each other, the noise will reliably be 0. This does not typically happen on integers forvalue
, but it can ifseed
is 0.- Parameters:
value
- should go up and/or down steadily and by small amounts (less than 1.0, certainly)seed
- should stay the same for a given curve- Returns:
- a noise value between -1.0 and 1.0
-
quobbleOctave2
public static double quobbleOctave2(int seed, double x) Just gets two octaves ofquobble(int, double)
; still has a range of -1 to 1. This tends to look much more natural than just one octave of quobble(), because the points where it always will hit 0 are spaced differently for the two octaves here.- Parameters:
x
- should go up and/or down steadily and by small amounts (less than 1.0, certainly)seed
- should stay the same for a given curve- Returns:
- a noise value between -1.0 and 1.0
-
quobble
public static float quobble(long seed, float value) Quilez' 1D noise, with some changes to work on the CPU. Takes a distance value and any long seed, and produces a smoothly-changing result as value goes up or down and seed stays the same. Uses a quartic curve. The quartic curve means that at specific positions, each separated by an integer from each other, the noise will reliably be 0. This does not typically happen on integers forvalue
, but it can ifseed
is 0 or some very high numbers.
The distance (value
) should be between -16384 and 1073733631 for this to return correct results. Because floats incur precision loss earlier than 1073733631, the actual upper bound is lower. The limit of -8192 comes from how this usesMathTools.fastFloor(float)
internally onvalue + value
.- Parameters:
value
- should go up and/or down steadily and by small amounts (less than 1.0, certainly)seed
- should stay the same for a given curve- Returns:
- a noise value between -1.0 and 1.0
-
quobbleOctave2
public static float quobbleOctave2(long seed, float x) Just gets two octaves ofquobble(long, float)
; still has a range of -1 to 1. This tends to look much more natural than just one octave of quobble(), because the points where it always will hit 0 are spaced differently for the two octaves here.- Parameters:
x
- should go up and/or down steadily and by small amounts (less than 1.0, certainly)seed
- should stay the same for a given curve- Returns:
- a noise value between -1.0 and 1.0
-
quobble
public static double quobble(long seed, double value) Quilez' 1D noise, with some changes to work on the CPU. Takes a distance value and any long seed, and produces a smoothly-changing result as value goes up or down and seed stays the same. Uses a quartic curve. The quartic curve means that at specific positions, each separated by an integer from each other, the noise will reliably be 0. This does not typically happen on integers forvalue
, but it can ifseed
is 0.- Parameters:
value
- should go up and/or down steadily and by small amounts (less than 1.0, certainly)seed
- should stay the same for a given curve- Returns:
- a noise value between -1.0 and 1.0
-
quobbleOctave2
public static double quobbleOctave2(long seed, double x) Just gets two octaves ofquobble(long, double)
; still has a range of -1 to 1. This tends to look much more natural than just one octave of quobble(), because the points where it always will hit 0 are spaced differently for the two octaves here.- Parameters:
x
- should go up and/or down steadily and by small amounts (less than 1.0, certainly)seed
- should stay the same for a given curve- Returns:
- a noise value between -1.0 and 1.0
-
trobble
public static double trobble(long seed, double value) Trigonometric wobble. Domain forvalue
is extremely large. Range is (-1, 1).- Parameters:
seed
- a long seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a double that typically changes slowly, by less than 1.0, with direction changes at integer inputs- Returns:
- a pseudo-random double between -1.0 and 1.0 (both exclusive), smoothly changing with value
-
trobble
public static float trobble(long seed, float value) Trigonometric wobble. Domain forvalue
is effectively [-16384, 16384]. Range is (-1, 1).- Parameters:
seed
- a long seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 2.0, with direction changes at integer inputs- Returns:
- a pseudo-random float between -1f and 1f (both exclusive), smoothly changing with value
-
trobble
public static double trobble(int seed, double value) Trigonometric wobble. Domain forvalue
is extremely large. Range is (-1, 1).- Parameters:
seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a double that typically changes slowly, by less than 2.0, with direction changes at integer inputs- Returns:
- a pseudo-random double between -1.0 and 1.0 (both exclusive), smoothly changing with value
-
trobble
public static float trobble(int seed, float value) Trigonometric wobble. Domain forvalue
is effectively [-16384, 16384]. Range is (-1, 1).- Parameters:
seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 2.0, with direction changes at integer inputs- Returns:
- a pseudo-random float between -1f and 1f (both exclusive), smoothly changing with value
-
smoothWobble
public static float smoothWobble(int seed, float t) Sway very smoothly using bicubic interpolation between 4 points (the two integers before t and the two after), and additional processing at the last step to push results closer to the min and max valid values. This is nearly the same asbicubicWobble(int, float)
, but it isn't at all as biased towards central results.- Parameters:
t
- a distance traveled; should change by less than 1 between calls, and should be less than about 10000seed
- any int- Returns:
- a smoothly-interpolated swaying value between -1 and 1, both exclusive
-
smoothWobble
public static double smoothWobble(int seed, double t) Sway very smoothly using bicubic interpolation between 4 points (the two integers before t and the two after), and additional processing at the last step to push results closer to the min and max valid values. This is nearly the same asbicubicWobble(int, double)
, but it isn't at all as biased towards central results.- Parameters:
t
- a distance traveled; should change by less than 1 between callsseed
- any int- Returns:
- a smoothly-interpolated swaying value between -1 and 1, both exclusive
-
smoothWobble
public static float smoothWobble(long seed, float t) Sway very smoothly using bicubic interpolation between 4 points (the two integers before t and the two after), and additional processing at the last step to push results closer to the min and max valid values. This is nearly the same asbicubicWobble(long, float)
, but it isn't at all as biased towards central results.- Parameters:
t
- a distance traveled; should change by less than 1 between callsseed
- any long- Returns:
- a smoothly-interpolated swaying value between -1 and 1, both exclusive
-
smoothWobble
public static double smoothWobble(long seed, double t) Sway very smoothly using bicubic interpolation between 4 points (the two integers before t and the two after), and additional processing at the last step to push results closer to the min and max valid values. This is nearly the same asbicubicWobble(long, double)
, but it isn't at all as biased towards central results.- Parameters:
t
- a distance traveled; should change by less than 1 between callsseed
- any long- Returns:
- a smoothly-interpolated swaying value between -1 and 1, both exclusive
-
wobbleAngle
public static float wobbleAngle(long seed, float value) A 1D "noise" method that produces smooth transitions like a sine wave, but also wrapping around at pi * 2 so this can be used to get smoothly-changing random angles. Has (seeded) random peaks and valleys where it slows its range of change, but can return any value from 0 to 6.283185307179586f, or pi * 2. The pattern this will produce will be completely different if the seed changes, and the value is expected to be something other than an angle, like time. Uses a simple method of cubic interpolation between random values, where a random value is used without modification when given an integer forvalue
. Note that this uses a different type of interpolation than a sine wave would, and the shape here uses cubic interpolation.- Parameters:
seed
- a long seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 1.0, with possible direction changes at integer inputs- Returns:
- a pseudo-random float between 0f and 6.283185307179586f (both inclusive), smoothly changing with value and wrapping
-
wobbleAngleDeg
public static float wobbleAngleDeg(long seed, float value) A 1D "noise" method that produces smooth transitions like a sine wave, but also wrapping around at 360.0 so this can be used to get smoothly-changing random angles. Has (seeded) random peaks and valleys where it slows its range of change, but can return any value from 0 to 360.0f . The pattern this will produce will be completely different if the seed changes, and the value is expected to be something other than an angle, like time. Uses a simple method of cubic interpolation between random values, where a random value is used without modification when given an integer forvalue
. Note that this uses a different type of interpolation than a sine wave would, and the shape here uses cubic interpolation.- Parameters:
seed
- a long seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 1.0, with possible direction changes at integer inputs- Returns:
- a pseudo-random float between 0f and 360.0f (both inclusive), smoothly changing with value and wrapping
-
wobbleAngleTurns
public static float wobbleAngleTurns(long seed, float value) A 1D "noise" method that produces smooth transitions like a sine wave, but also wrapping around at 1.0 so this can be used to get smoothly-changing random angles in turns. Has (seeded) random peaks and valleys where it slows its range of change, but can return any value from 0 to 1.0. The pattern this will produce will be completely different if the seed changes, and the value is expected to be something other than an angle, like time. Uses a simple method of cubic interpolation between random values, where a random value is used without modification when given an integer forvalue
. Note that this uses a different type of interpolation than a sine wave would, and the shape here uses cubic interpolation.- Parameters:
seed
- a long seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 1.0, with possible direction changes at integer inputs- Returns:
- a pseudo-random float between 0.0f and 1.0f (both inclusive), smoothly changing with value and wrapping
-
wobbleAngle
public static float wobbleAngle(int seed, float value) A 1D "noise" method that produces smooth transitions like a sine wave, but also wrapping around at pi * 2 so this can be used to get smoothly-changing random angles. Has (seeded) random peaks and valleys where it slows its range of change, but can return any value from 0 to 6.283185307179586f, or pi * 2. The pattern this will produce will be completely different if the seed changes, and the value is expected to be something other than an angle, like time. Uses a simple method of cubic interpolation between random values, where a random value is used without modification when given an integer forvalue
. Note that this uses a different type of interpolation than a sine wave would, and the shape here uses cubic interpolation.- Parameters:
seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 1.0, with possible direction changes at integer inputs- Returns:
- a pseudo-random float between 0f and 6.283185307179586f (both inclusive), smoothly changing with value and wrapping
-
wobbleAngleDeg
public static float wobbleAngleDeg(int seed, float value) A 1D "noise" method that produces smooth transitions like a sine wave, but also wrapping around at 360.0 so this can be used to get smoothly-changing random angles. Has (seeded) random peaks and valleys where it slows its range of change, but can return any value from 0 to 360.0f . The pattern this will produce will be completely different if the seed changes, and the value is expected to be something other than an angle, like time. Uses a simple method of cubic interpolation between random values, where a random value is used without modification when given an integer forvalue
. Note that this uses a different type of interpolation than a sine wave would, and the shape here uses cubic interpolation.- Parameters:
seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 1.0, with possible direction changes at integer inputs- Returns:
- a pseudo-random float between 0f and 360.0f (both inclusive), smoothly changing with value and wrapping
-
wobbleAngleTurns
public static float wobbleAngleTurns(int seed, float value) A 1D "noise" method that produces smooth transitions like a sine wave, but also wrapping around at 1.0 so this can be used to get smoothly-changing random angles in turns. Has (seeded) random peaks and valleys where it slows its range of change, but can return any value from 0 to 1.0. The pattern this will produce will be completely different if the seed changes, and the value is expected to be something other than an angle, like time. Uses a simple method of cubic interpolation between random values, where a random value is used without modification when given an integer forvalue
. Note that this uses a different type of interpolation than a sine wave would, and the shape here uses cubic interpolation.- Parameters:
seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 1.0, with possible direction changes at integer inputs- Returns:
- a pseudo-random float between 0.0f and 1.0f (both inclusive), smoothly changing with value and wrapping
-
splobbleAngle
public static float splobbleAngle(int seed, float value) Likesplobble(int, float)
, this is a 1D wobble that can become more sharp or more gradual at different points on its length, but this produces a (wrapping) angle measured in radians.- Parameters:
seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 1.0, with possible direction changes at integer inputs- Returns:
- a pseudo-random float between 0.0f and 6.283185307179586f (both inclusive), smoothly changing with value and wrapping
-
splobbleAngleDeg
public static float splobbleAngleDeg(int seed, float value) Likesplobble(int, float)
, this is a 1D wobble that can become more sharp or more gradual at different points on its length, but this produces a (wrapping) angle measured in degrees.- Parameters:
seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 1.0, with possible direction changes at integer inputs- Returns:
- a pseudo-random float between 0.0f and 360.0f (both inclusive), smoothly changing with value and wrapping
-
splobbleAngleTurns
public static float splobbleAngleTurns(int seed, float value) Likesplobble(int, float)
, this is a 1D wobble that can become more sharp or more gradual at different points on its length, but this produces a (wrapping) angle measured in turns.- Parameters:
seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 1.0, with possible direction changes at integer inputs- Returns:
- a pseudo-random float between 0.0f and 1.0f (both inclusive), smoothly changing with value and wrapping
-
splobbleAngle
public static float splobbleAngle(long seed, float value) Likesplobble(long, float)
, this is a 1D wobble that can become more sharp or more gradual at different points on its length, but this produces a (wrapping) angle measured in radians.- Parameters:
seed
- a long seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 1.0, with possible direction changes at integer inputs- Returns:
- a pseudo-random float between 0.0f and 6.283185307179586f (both inclusive), smoothly changing with value and wrapping
-
splobbleAngleDeg
public static float splobbleAngleDeg(long seed, float value) Likesplobble(long, float)
, this is a 1D wobble that can become more sharp or more gradual at different points on its length, but this produces a (wrapping) angle measured in degrees.- Parameters:
seed
- a long seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 1.0, with possible direction changes at integer inputs- Returns:
- a pseudo-random float between 0.0f and 360.0f (both inclusive), smoothly changing with value and wrapping
-
splobbleAngleTurns
public static float splobbleAngleTurns(long seed, float value) Likesplobble(long, float)
, this is a 1D wobble that can become more sharp or more gradual at different points on its length, but this produces a (wrapping) angle measured in turns.- Parameters:
seed
- a long seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 1.0, with possible direction changes at integer inputs- Returns:
- a pseudo-random float between 0.0f and 1.0f (both inclusive), smoothly changing with value and wrapping
-
wobbleWrapped
public static float wobbleWrapped(long seed, float value, int modulus) Very similar towobble(long, float)
, but only tolerates non-negativevalue
and wraps value when it gets too close tomodulus
. Could find various uses when wrapping is needed. One such potential use is for looping animations; if the modulus is set so thatvalue
equalsmodulus
(or an integer multiple of it) exactly when the animation starts and ends, the animation will then loop seamlessly, at least for anything that depends on this method.
The wobble methods have a shape where they flatten out whenvalue
is an integer, so typically you should add a value smaller than 1 to value at each call if you want it to change smoothly. For the wrapped methods, the modulus is also the number of times the curve will flatten out over the course of a cycle.
Note thatwobbleWrapped(seed, 0, modulus)
andwobbleWrapped(seed, modulus, modulus)
will produce the same value as long as modulus is positive (and not large enough to incur precision loss).- Parameters:
seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a non-negative float that typically changes slowly, by less than 2.0, with direction changes at integer inputsmodulus
- where to wrap value if it gets too high; must be positive- Returns:
- a pseudo-random float between -1f and 1f (both exclusive), smoothly changing with value
-
wobbleWrappedTight
public static float wobbleWrappedTight(long seed, float value, int modulus) Very similar towobble(long, float)
, but only tolerates non-negativevalue
and wraps value when it gets too close tomodulus
. Could find various uses when wrapping is needed. One such potential use is for looping animations; if the modulus is set so thatvalue
equalsmodulus
(or an integer multiple of it) exactly when the animation starts and ends, the animation will then loop seamlessly, at least for anything that depends on this method.
The wobble methods have a shape where they flatten out whenvalue
is an integer, so typically you should add a value smaller than 1 to value at each call if you want it to change smoothly. For the wrapped methods, the modulus is also the number of times the curve will flatten out over the course of a cycle.
Note thatwobbleWrappedTight(seed, 0, modulus)
andwobbleWrappedTight(seed, modulus, modulus)
will produce the same value as long as modulus is positive (and not large enough to incur precision loss).- Parameters:
seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a non-negative float that typically changes slowly, by less than 2.0, with direction changes at integer inputsmodulus
- where to wrap value if it gets too high; must be positive- Returns:
- a pseudo-random float between 0f and 1f (both inclusive), smoothly changing with value
-
wobbleWrapped
public static float wobbleWrapped(int seed, float value, int modulus) Very similar towobble(int, float)
, but only tolerates non-negativevalue
and wraps value when it gets too close tomodulus
. Used bygenerateLookupTable(int, int, int, int)
, but could find uses elsewhere. One such potential use is for looping animations; if the modulus is set so thatvalue
equalsmodulus
(or an integer multiple of it) exactly when the animation starts and ends, the animation will then loop seamlessly, at least for anything that depends on this method.
The wobble methods have a shape where they flatten out whenvalue
is an integer, so typically you should add a value smaller than 1 to value at each call if you want it to change smoothly. For the wrapped methods, the modulus is also the number of times the curve will flatten out over the course of a cycle.
Note thatwobbleWrapped(seed, 0, modulus)
andwobbleWrapped(seed, modulus, modulus)
will produce the same value as long as modulus is positive (and not large enough to incur precision loss).- Parameters:
seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a non-negative float that typically changes slowly, by less than 2.0, with direction changes at integer inputsmodulus
- where to wrap value if it gets too high; must be positive- Returns:
- a pseudo-random float between -1f and 1f (both exclusive), smoothly changing with value
-
wobbleWrappedTight
public static float wobbleWrappedTight(int seed, float value, int modulus) Very similar towobble(int, float)
, but only tolerates non-negativevalue
and wraps value when it gets too close tomodulus
. Used bygenerateSplineLookupTable(int, int, int, int, float, float)
, but could find uses elsewhere. One such potential use is for looping animations; if the modulus is set so thatvalue
equalsmodulus
(or an integer multiple of it) exactly when the animation starts and ends, the animation will then loop seamlessly, at least for anything that depends on this method.
The wobble methods have a shape where they flatten out whenvalue
is an integer, so typically you should add a value smaller than 1 to value at each call if you want it to change smoothly. For the wrapped methods, the modulus is also the number of times the curve will flatten out over the course of a cycle.
Note thatwobbleWrappedTight(seed, 0, modulus)
andwobbleWrappedTight(seed, modulus, modulus)
will produce the same value as long as modulus is positive (and not large enough to incur precision loss).- Parameters:
seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a non-negative float that typically changes slowly, by less than 2.0, with direction changes at integer inputsmodulus
- where to wrap value if it gets too high; must be positive- Returns:
- a pseudo-random float between 0f and 1f (both inclusive), smoothly changing with value
-
generateLookupTable
public static float[] generateLookupTable(int seed, int size, int points, int octaves) Creates a wrapping lookup table ofsize
float items for a wobbling line, using a specific count of points where the wobble can reach a peak or valley, a number of octaves to refine the wobble, and a seed.- Parameters:
seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changessize
- how many items to have in the returned float arraypoints
- effectively, the frequency; how many possible peak/valley points will appear in the first octaveoctaves
- a positive int that adds more detail as it goes higher; cannot be more than 31- Returns:
- the wrapping lookup table of float values between -1 and 1
-
generateSplineLookupTable
public static float[] generateSplineLookupTable(int seed, int size, int points, int octaves, float shape, float turning) Creates a wrapping lookup table ofsize
float items for a wobbling line, using a specific count of points where the wobble can reach a peak or valley, a number of octaves to refine the wobble, and a seed. This also takes a shape and turning parameter that it uses to finish the lookup table by running every item through a call toMathTools.barronSpline(float, float, float)
; this can be useful to change how the noise is distributed from slightly favoring extremes (the default) to preferring central values (when shape is between 0 and 1) or preferring more extreme values (when shape is more than 1).- Parameters:
seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changessize
- how many items to have in the returned float arraypoints
- effectively, the frequency; how many possible peak/valley points will appear in the first octaveoctaves
- a positive int that adds more detail as it goes higher; cannot be more than 31shape
- must be greater than or equal to 0; values greater than 1 are "normal interpolations"turning
- a value between 0.0 and 1.0, inclusive, where the shape changes- Returns:
- the wrapping lookup table of float values between 0 and 1, both inclusive
-