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 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 float a 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 float a 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 double a 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 double a 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)
    Like Math.ceil(double), but returns an int.
    static int fastCeil​(float t)
    Like Math.ceil(double), but takes a float and returns an int.
    static int fastFloor​(double t)
    Like Math.floor(double) , but returns an int.
    static int fastFloor​(float t)
    Like Math.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)
    Like Math.floor(double), but returns a long.
    static long longFloor​(float t)
    Like Math.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)
    Like seamless2D(double[][], long, int, Noise4D), but this produces 1D noise that "tiles" by repeating its output every sizeX units that x 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)
    Like seamless2D(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)
    Like seamless3D(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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • longFloor

      public static long longFloor​(double t)
      Like Math.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

      public static long longFloor​(float t)
      Like Math.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

      public static int fastFloor​(double t)
      Like Math.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

      public static int fastFloor​(float t)
      Like Math.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

      public static int fastCeil​(double t)
      Like Math.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

      public static int fastCeil​(float t)
      Like Math.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

      public 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). 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) than lerp(double, double, double).
      Parameters:
      start - a valid double
      end - a valid double
      a - a double between 0 and 1 inclusive
      Returns:
      a double between start and end inclusive
    • cerp

      public 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). 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) than lerp(float, float, float).
      Parameters:
      start - a valid float
      end - a valid float
      a - a float between 0 and 1 inclusive
      Returns:
      a float between start and end inclusive
    • querp

      public static double querp​(double start, double end, double a)
    • querp

      public static float querp​(float start, float end, float a)
    • lerp

      public 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).
      Parameters:
      start - a valid double, as in, not infinite or NaN
      end - a valid double, as in, not infinite or NaN
      a - a double between 0 and 1 inclusive
      Returns:
      a double between x and y inclusive
    • lerp

      public 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).
      Parameters:
      start - a valid float, as in, not infinite or NaN
      end - a valid float, as in, not infinite or NaN
      a - a float between 0 and 1 inclusive
      Returns:
      a float between x and y inclusive
    • emphasize

      public static double emphasize​(double a)
      Given a float a 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

      public static double emphasizeSigned​(double a)
      Given a float a 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 by ClassicNoise and JitterNoise to increase the frequency of high and low results, which improves the behavior of Noise.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

      public static double extreme​(double a)
      Given a double a 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

      public static double extremeSigned​(double a)
      Given a double a 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

      public 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. Uses (x,y) order. Allows a seed to change the generated noise. If you need to call this very often, consider seamless2D(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 noise
      octaves - 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

      public 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. 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 with new double[width][height] or something similar
      seed - an int seed that affects the noise produced, with different seeds producing very different noise
      octaves - 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 with new double[width][height] or something similar
      seed - an int seed that affects the noise produced, with different seeds producing very different noise
      octaves - 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​(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. 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, consider seamless3D(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 noise
      octaves - 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

      public 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. 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 with new double[depth][width][height] or something similar
      seed - an int seed that affects the noise produced, with different seeds producing very different noise
      octaves - 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 with new double[depth][width][height] or something similar
      seed - an int seed that affects the noise produced, with different seeds producing very different noise
      octaves - 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 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. 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 with new double[depth][width][height] or something similar
      seed - an int seed that affects the noise produced, with different seeds producing very different noise
      octaves - 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

      public static double seamless1D​(Noise.Noise2D noise, double x, double sizeX, long seed)
      Like seamless2D(double[][], long, int, Noise4D), but this produces 1D noise that "tiles" by repeating its output every sizeX units that x 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 a SeededNoise or FastNoise
      x - the x-coordinate to sample
      sizeX - the range of x to generate before repeating; must be greater than 0
      seed - 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)
      Like seamless2D(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 a SeededNoise or FastNoise
      x - the x-coordinate to sample
      y - the y-coordinate to sample
      sizeX - the range of x to generate before repeating; must be greater than 0
      sizeY - the range of y to generate before repeating; must be greater than 0
      seed - 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)
      Like seamless3D(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 a SeededNoise or FastNoise
      x - the x-coordinate to sample
      y - the y-coordinate to sample
      z - the z-coordinate to sample
      sizeX - the range of x to generate before repeating; must be greater than 0
      sizeY - the range of y to generate before repeating; must be greater than 0
      sizeZ - the range of z to generate before repeating; must be greater than 0
      seed - the noise seed, as a long
      Returns:
      continuous noise from -1.0 to 1.0, inclusive