Class DualMutantNoiseWrapper

java.lang.Object
com.github.yellowstonegames.grid.DualMutantNoiseWrapper
All Implemented Interfaces:
com.github.yellowstonegames.core.ISerializersNeeded, INoise, Externalizable, Serializable

@Beta public class DualMutantNoiseWrapper extends Object implements INoise, com.github.yellowstonegames.core.ISerializersNeeded
A wrapper around an INoise that allows two extra degrees of freedom to adjust the inputs by a small amount, continuously rather than in jumps (as adjusting the seed would do). You can change the mutationA and/or mutationB by any amount at a time, though usually it is a small change, and often the two mutations change in a looping cycle. To make the mutations loop seamlessly, you can pass the same values to getNoise and only change mutations, assigning one TrigTools.sin(float) and the other TrigTools.cos(float) with the same angle. By changing the angle from 0 to TrigTools.PI2 over one full loop, you can make the noise change seamlessly.
Internally this works by calling the same method you call here on an internal INoise, basis, but using a higher dimension and passing mutationA and mutationB in as higher-dimensional inputs. This means if you call getNoise(float, float), passing x and y, internally this calls INoise.getNoise(float, float, float, float) and passes x, y, mutationA, and mutationB.
This defaults to using a FoamNoise for its basis INoise, which allows dimensions 2 through 5 to be produced with a mutation value.
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface INoise

    INoise.Serializer
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The INoise this uses for all its internal noise generation.
    float
    The first extra input that is passed to basis, in addition to the inputs to each noise call.
    float
    The second extra input that is passed to basis, in addition to the inputs to each noise call.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Makes a MutantNoise with a FoamNoise basis (seeded with 1234567890L) and mutations both 0.0f .
    Makes a MutantNoise with a FoamNoise basis (seeded with the given seed) and mutations both 0.0f.
    DualMutantNoiseWrapper(long seed, float mutationA, float mutationB)
    Makes a MutantNoise with a FoamNoise basis (seeded with the given seed) and the given mutations.
    Makes a MutantNoise with the given basis INoise and mutations both 0.0f.
    DualMutantNoiseWrapper(INoise base, float mutationA, float mutationB)
    Makes a MutantNoise with the given basis INoise and mutation.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a copy of this INoise, which should be a deep copy for any mutable state but can be shallow for immutable types such as functions.
    final boolean
     
    int
    Maximum dimension is two less than the maximum dimension of the basis INoise.
    int
    Minimum dimension is 2, unless the basis INoise has a minimum dimension of 5 or greater.
    float
    Gets the mutation value.
    float
    Gets the angle in radians of the current mutation values.
    float
    Gets the angle in degrees, from -180 to 180, of the current mutation values.
    float
    Gets the angle in degrees, from 0 to 360, of the current mutation values.
    float
    Gets the angle in turns, from 0 to 1.0, of the current mutation values.
    float
    Gets the second mutation value.
    float
    Gets the magnitude of the circle that contains the current mutation values.
    float
    Gets the squared magnitude of the circle that contains the current mutation values.
    float
    getNoise(float x, float y)
    Gets 2D noise with a default or pre-set seed.
    float
    getNoise(float x, float y, float z)
    Gets 3D noise with a default or pre-set seed.
    float
    getNoise(float x, float y, float z, float w)
    Gets 4D noise with a default or pre-set seed.
    float
    getNoise(float x, float y, float z, float w, float u)
    Gets 5D noise with a default or pre-set seed.
    float
    getNoise(float x, float y, float z, float w, float u, float v)
    Not supported.
    float
    getNoise(float x, float y, float z, float w, float u, float v, float m)
    Not supported.
    float
    getNoiseWithSeed(float x, float y, float z, float w, float u, float v, float m, long seed)
    Not supported.
    float
    getNoiseWithSeed(float x, float y, float z, float w, float u, float v, long seed)
    Not supported.
    float
    getNoiseWithSeed(float x, float y, float z, float w, float u, long seed)
    Gets 5D noise with a specific seed.
    float
    getNoiseWithSeed(float x, float y, float z, float w, long seed)
    Gets 4D noise with a specific seed.
    float
    getNoiseWithSeed(float x, float y, float z, long seed)
    Gets 3D noise with a specific seed.
    float
    getNoiseWithSeed(float x, float y, long seed)
    Gets 2D noise with a specific seed.
    long
    Gets the current seed of the generator, as a long even if the seed is stored internally as an int.
     
    The String "DuMu" .
    boolean
    Setting the seed is efficient here if and only if it is efficient for the basis INoise.
    int
     
     
    void
    setMutationA(float mutationA)
    Sets the mutation value.
    void
    setMutationAngle(float angleRadians, float magnitude)
    Sets both mutation values so they are on a circle with the given magnitude at the given angle, in radians.
    void
    setMutationAngleDegrees(float angleDegrees, float magnitude)
    Sets both mutation values so they are on a circle with the given magnitude at the given angle, in degrees.
    void
    setMutationAngleTurns(float angleTurns, float magnitude)
    Sets both mutation values so they are on a circle with the given magnitude at the given angle, in turns.
    void
    setMutationB(float mutationB)
    Sets the second mutation value.
    void
    setSeed(long seed)
    Sets the seed to the given long, if long seeds are supported, or (int)seed if only int seeds are supported.
    Given a serialized String produced by INoise.stringSerialize(), reassigns this INoise to have the described state from the given String.
    Produces a String that describes everything needed to recreate this INoise in full.
     

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface INoise

    readExternal, writeExternal
  • Field Details

    • basis

      public INoise basis
      The INoise this uses for all its internal noise generation. This defaults to a FoamNoise, but can be any INoise with INoise.getMaxDimension() greater than 3.
    • mutationA

      public float mutationA
      The first extra input that is passed to basis, in addition to the inputs to each noise call. This typically changes only be a small amount at a time, to make minor continuous adjustments to a noise result, instead of using setSeed(long) to make a non-continuous adjustment that "jumps." This defaults to 0.
    • mutationB

      public float mutationB
      The second extra input that is passed to basis, in addition to the inputs to each noise call. This typically changes only be a small amount at a time, to make minor continuous adjustments to a noise result, instead of using setSeed(long) to make a non-continuous adjustment that "jumps." This defaults to 0.
  • Constructor Details

    • DualMutantNoiseWrapper

      public DualMutantNoiseWrapper()
      Makes a MutantNoise with a FoamNoise basis (seeded with 1234567890L) and mutations both 0.0f .
    • DualMutantNoiseWrapper

      public DualMutantNoiseWrapper(long seed)
      Makes a MutantNoise with a FoamNoise basis (seeded with the given seed) and mutations both 0.0f.
      Parameters:
      seed - the seed to use for any noise call that doesn't take a seed already
    • DualMutantNoiseWrapper

      public DualMutantNoiseWrapper(long seed, float mutationA, float mutationB)
      Makes a MutantNoise with a FoamNoise basis (seeded with the given seed) and the given mutations.
      Parameters:
      seed - the seed to use for any noise call that doesn't take a seed already
      mutationA - the initial value for the first extra input to be passed in addition to the inputs to each noise call
      mutationB - the initial value for the second extra input to be passed in addition to the inputs to each noise call
    • DualMutantNoiseWrapper

      public DualMutantNoiseWrapper(INoise base)
      Makes a MutantNoise with the given basis INoise and mutations both 0.0f.
      Parameters:
      base - the INoise to use as a basis
    • DualMutantNoiseWrapper

      public DualMutantNoiseWrapper(INoise base, float mutationA, float mutationB)
      Makes a MutantNoise with the given basis INoise and mutation.
      Parameters:
      base - the INoise to use as a basis
      mutationA - the initial value for the first extra input to be passed in addition to the inputs to each noise call
      mutationB - the initial value for the second extra input to be passed in addition to the inputs to each noise call
  • Method Details

    • getMinDimension

      public int getMinDimension()
      Minimum dimension is 2, unless the basis INoise has a minimum dimension of 5 or greater. With the default basis, a FoamNoise, this will be 2.
      Specified by:
      getMinDimension in interface INoise
      Returns:
      2, in almost all cases
    • getMaxDimension

      public int getMaxDimension()
      Maximum dimension is two less than the maximum dimension of the basis INoise. With the default basis, a FoamNoise, this will be 5.
      Specified by:
      getMaxDimension in interface INoise
      Returns:
      two less than basis.getMaxDimension()
    • hasEfficientSetSeed

      public boolean hasEfficientSetSeed()
      Setting the seed is efficient here if and only if it is efficient for the basis INoise.
      Specified by:
      hasEfficientSetSeed in interface INoise
      Returns:
      basis.hasEfficientSetSeed()
    • getNoise

      public float getNoise(float x, float y)
      Description copied from interface: INoise
      Gets 2D noise with a default or pre-set seed.
      Specified by:
      getNoise in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoise

      public float getNoise(float x, float y, float z)
      Description copied from interface: INoise
      Gets 3D noise with a default or pre-set seed.
      Specified by:
      getNoise in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoise

      public float getNoise(float x, float y, float z, float w)
      Description copied from interface: INoise
      Gets 4D noise with a default or pre-set seed.
      Specified by:
      getNoise in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoise

      public float getNoise(float x, float y, float z, float w, float u)
      Description copied from interface: INoise
      Gets 5D noise with a default or pre-set seed.
      Specified by:
      getNoise in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      u - u position; can be any finite float
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoise

      public float getNoise(float x, float y, float z, float w, float u, float v)
      Not supported.
      Specified by:
      getNoise in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      u - u position; can be any finite float
      v - v position; can be any finite float
      Returns:
      never returns
      Throws:
      UnsupportedOperationException - not supported
    • getNoise

      public float getNoise(float x, float y, float z, float w, float u, float v, float m)
      Not supported.
      Specified by:
      getNoise in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      u - u position; can be any finite float
      v - v position; can be any finite float
      m - m position; can be any finite float
      Returns:
      never returns
      Throws:
      UnsupportedOperationException - not supported
    • setSeed

      public void setSeed(long seed)
      Description copied from interface: INoise
      Sets the seed to the given long, if long seeds are supported, or (int)seed if only int seeds are supported. If this generator cannot be seeded, this should do nothing, and should not throw an exception. If this operation allocates or is time-intensive, then INoise.hasEfficientSetSeed() should return false. That method is checked in INoise.getNoiseWithSeed(float, float, long), and if it returns false, the noise call will avoid calling setSeed(). You can always at least try to set the seed, even if it does nothing or is heavy on performance, and doing it a few times each frame should typically be fine for any generator. In the case this is called thousands of times each frame, check INoise.hasEfficientSetSeed().
      Specified by:
      setSeed in interface INoise
      Parameters:
      seed - a long or int seed, with no restrictions unless otherwise documented
    • getSeed

      public long getSeed()
      Description copied from interface: INoise
      Gets the current seed of the generator, as a long even if the seed is stored internally as an int. This must be implemented, but if the generator doesn't have a seed that can be expressed as a long (potentially using BitConversion.floatToIntBits(float)), this can just return 0.
      Specified by:
      getSeed in interface INoise
      Returns:
      the current seed, as a long
    • getMutationA

      public float getMutationA()
      Gets the mutation value. The mutation is an extra input that is passed to basis, in addition to the inputs to each noise call. This typically changes only be a small amount at a time, to make minor continuous adjustments to a noise result, instead of using setSeed(long) to make a non-continuous adjustment that "jumps."
      Returns:
      the first mutation value
    • setMutationA

      public void setMutationA(float mutationA)
      Sets the mutation value. The mutation is an extra input that is passed to basis, in addition to the inputs to each noise call. This typically changes only be a small amount at a time, to make minor continuous adjustments to a noise result, instead of using setSeed(long) to make a non-continuous adjustment that "jumps."
      Parameters:
      mutationA - the float value to use for the mutation
    • getMutationB

      public float getMutationB()
      Gets the second mutation value. This is the second extra input that is passed to basis, in addition to the inputs to each noise call. This typically changes only be a small amount at a time, to make minor continuous adjustments to a noise result, instead of using setSeed(long) to make a non-continuous adjustment that "jumps."
      Returns:
      the second mutation value
    • setMutationB

      public void setMutationB(float mutationB)
      Sets the second mutation value. This is the second extra input that is passed to basis, in addition to the inputs to each noise call. This typically changes only be a small amount at a time, to make minor continuous adjustments to a noise result, instead of using setSeed(long) to make a non-continuous adjustment that "jumps."
      Parameters:
      mutationB - the float value to use for the second mutation
    • getMutationMagnitude

      public float getMutationMagnitude()
      Gets the magnitude of the circle that contains the current mutation values.
      Returns:
      the Euclidean distance from 0,0 to mutationA,mutationB
    • getMutationMagnitudeSquared

      public float getMutationMagnitudeSquared()
      Gets the squared magnitude of the circle that contains the current mutation values.
      Returns:
      the squared Euclidean distance from 0,0 to mutationA,mutationB
    • getMutationAngle

      public float getMutationAngle()
      Gets the angle in radians of the current mutation values.
      Returns:
      the angle in radians
    • getMutationAngleDegrees

      public float getMutationAngleDegrees()
      Gets the angle in degrees, from -180 to 180, of the current mutation values.
      Returns:
      the angle in degrees
    • getMutationAngleDegrees360

      public float getMutationAngleDegrees360()
      Gets the angle in degrees, from 0 to 360, of the current mutation values.
      Returns:
      the angle in degrees
    • getMutationAngleTurns

      public float getMutationAngleTurns()
      Gets the angle in turns, from 0 to 1.0, of the current mutation values.
      Returns:
      the angle in turns
    • setMutationAngle

      public void setMutationAngle(float angleRadians, float magnitude)
      Sets both mutation values so they are on a circle with the given magnitude at the given angle, in radians. If the magnitude does not change and the angle makes a full circle, the noise produced will loop seamlessly. Larger magnitude values will make changes to the angle more significant.
      Parameters:
      angleRadians - the angle on the circle, in radians
      magnitude - the radius of the circle; larger values will change more for the same change in angle
    • setMutationAngleDegrees

      public void setMutationAngleDegrees(float angleDegrees, float magnitude)
      Sets both mutation values so they are on a circle with the given magnitude at the given angle, in degrees. If the magnitude does not change and the angle makes a full circle, the noise produced will loop seamlessly. Larger magnitude values will make changes to the angle more significant.
      Parameters:
      angleDegrees - the angle on the circle, in degrees
      magnitude - the radius of the circle; larger values will change more for the same change in angle
    • setMutationAngleTurns

      public void setMutationAngleTurns(float angleTurns, float magnitude)
      Sets both mutation values so they are on a circle with the given magnitude at the given angle, in turns. If the magnitude does not change and the angle makes a full circle, the noise produced will loop seamlessly. Larger magnitude values will make changes to the angle more significant.
      Parameters:
      angleTurns - the angle on the circle, in turns
      magnitude - the radius of the circle; larger values will change more for the same change in angle
    • getTag

      public String getTag()
      The String "DuMu" .
      Specified by:
      getTag in interface INoise
      Returns:
      "DuMu"
    • stringSerialize

      public String stringSerialize()
      Description copied from interface: INoise
      Produces a String that describes everything needed to recreate this INoise in full. This String can be read back in by INoise.stringDeserialize(String) to reassign the described state to another INoise. The syntax here should always start and end with the ` character, which is used by INoise.stringDeserialize(String) to identify the portion of a String that can be read back. The ` character should not be otherwise used unless to serialize another INoise that this uses.
      If you use Base to produce String representations for numeric fields in an INoise, Base.BASE10 is strongly recommended; in most cases, you can just use string concatenation with the fields separated by the tilde character, "~". For printing a float field with Base to a StringBuilder sb, use Base.BASE10.appendGeneral(sb, field).
      The default implementation throws an UnsupportedOperationException only. INoise classes do not have to implement any serialization methods, but they aren't serializable by the methods in this class or in INoise.Serializer unless they do implement this, INoise.getTag(), INoise.stringDeserialize(String), and INoise.copy().
      Specified by:
      stringSerialize in interface INoise
      Returns:
      a String that describes this INoise for serialization
    • stringDeserialize

      public DualMutantNoiseWrapper stringDeserialize(String data)
      Description copied from interface: INoise
      Given a serialized String produced by INoise.stringSerialize(), reassigns this INoise to have the described state from the given String. The serialized String must have been produced by the same class as this object is.
      Any class that implements INoise.stringSerialize() should also implement this method in a compatible way. Using base-10 is expected for most uses. Using Base.BASE10.readFloat(data, start, end) may be useful to parse only the part of data between start and end.
      The default implementation throws an UnsupportedOperationException only. INoise classes do not have to implement any serialization methods, but they aren't serializable by the methods in this class or in INoise.Serializer unless they do implement this, INoise.getTag(), INoise.stringSerialize(), and INoise.copy().
      Specified by:
      stringDeserialize in interface INoise
      Parameters:
      data - a serialized String, typically produced by INoise.stringSerialize()
      Returns:
      this INoise, after being modified (if possible)
    • recreateFromString

      public static DualMutantNoiseWrapper recreateFromString(String data)
    • getSerializersNeeded

      public List<Class<?>> getSerializersNeeded()
      Specified by:
      getSerializersNeeded in interface com.github.yellowstonegames.core.ISerializersNeeded
    • copy

      public DualMutantNoiseWrapper copy()
      Description copied from interface: INoise
      Creates a copy of this INoise, which should be a deep copy for any mutable state but can be shallow for immutable types such as functions. This almost always just calls a copy constructor.
      The default implementation throws an UnsupportedOperationException only. Implementors are strongly encouraged to implement this in general, and that is required to use an INoise class with INoise.Serializer.
      Specified by:
      copy in interface INoise
      Returns:
      a copy of this INoise
    • equals

      public final boolean equals(Object o)
      Specified by:
      equals in interface INoise
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getNoiseWithSeed

      public float getNoiseWithSeed(float x, float y, long seed)
      Description copied from interface: INoise
      Gets 2D noise with a specific seed. If the seed cannot be retrieved or changed per-call, then this falls back to changing the position instead of the seed; you can check if this will happen with INoise.hasEfficientSetSeed().
      Specified by:
      getNoiseWithSeed in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      seed - can be any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoiseWithSeed

      public float getNoiseWithSeed(float x, float y, float z, long seed)
      Description copied from interface: INoise
      Gets 3D noise with a specific seed. If the seed cannot be retrieved or changed per-call, then this falls back to changing the position instead of the seed; you can check if this will happen with INoise.hasEfficientSetSeed().
      Specified by:
      getNoiseWithSeed in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      seed - can be any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoiseWithSeed

      public float getNoiseWithSeed(float x, float y, float z, float w, long seed)
      Description copied from interface: INoise
      Gets 4D noise with a specific seed. If the seed cannot be retrieved or changed per-call, then this falls back to changing the position instead of the seed; you can check if this will happen with INoise.hasEfficientSetSeed().
      Specified by:
      getNoiseWithSeed in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      seed - can be any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoiseWithSeed

      public float getNoiseWithSeed(float x, float y, float z, float w, float u, long seed)
      Description copied from interface: INoise
      Gets 5D noise with a specific seed. If the seed cannot be retrieved or changed per-call, then this falls back to changing the position instead of the seed; you can check if this will happen with INoise.hasEfficientSetSeed().
      Specified by:
      getNoiseWithSeed in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      u - u position; can be any finite float
      seed - can be any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoiseWithSeed

      public float getNoiseWithSeed(float x, float y, float z, float w, float u, float v, long seed)
      Not supported.
      Specified by:
      getNoiseWithSeed in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      u - u position; can be any finite float
      v - v position; can be any finite float
      seed - can be any long
      Returns:
      never returns
      Throws:
      UnsupportedOperationException - not supported
    • getNoiseWithSeed

      public float getNoiseWithSeed(float x, float y, float z, float w, float u, float v, float m, long seed)
      Not supported.
      Specified by:
      getNoiseWithSeed in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      u - u position; can be any finite float
      v - v position; can be any finite float
      m - m position; can be any finite float
      seed - can be any long
      Returns:
      never returns
      Throws:
      UnsupportedOperationException - not supported