Class LXUtils

java.lang.Object
heronarts.lx.utils.LXUtils

public class LXUtils extends Object
Helper class of useful utilities, many just mirror Processing built-ins but reduce the awkwardness of calling through applet in the library code.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static float
    atan2pf(float y, float x)
    Returns the result of Math.atan2 pushed into the positive space [0-TWO_PI]
    static double
    avg(double v1, double v2)
     
    static float
    avgf(float v1, float v2)
     
    static double
    clamp(double value, double min, double max)
     
    static int
    clamp(int value, int min, int max)
     
    static float
    clampf(float value, float min, float max)
     
    static double
    constrain(double value, double min, double max)
     
    static int
    constrain(int value, int min, int max)
     
    static float
    constrainf(float value, float min, float max)
     
    static float
    cosf(double radians)
    Returns a floating-point rounded value of the cos function to 8 decimal places.
    static double
    dist(double x1, double y1, double x2, double y2)
     
    static double
    dist(double x1, double y1, double z1, double x2, double y2, double z2)
     
    static double
    distance(double x1, double y1, double x2, double y2)
     
    static double
    distance(double x1, double y1, double z1, double x2, double y2, double z2)
     
    static float
    distf(float x1, float y1, float x2, float y2)
     
    static float
    distf(float x1, float y1, float z1, float x2, float y2, float z2)
     
    static double
    ilerp(double amt, double v1, double v2)
    Inverse linear interpolation, normalizes a value relative to bounds
    static float
    ilerpf(float amt, float v1, float v2)
    Inverse linear interpolation, normalizes a value relative to bounds
    static boolean
     
    static double
    lerp(double v1, double v2, double amt)
     
    static float
    lerpf(float v1, float v2, float amt)
     
    static int
    lerpi(int v1, int v2, float amt)
     
    static double
    max(double a, double b)
     
    static double
    max(double a, double b, double c)
     
    static int
    max(int a, int b)
     
    static int
    max(int a, int b, int c)
     
    static float
    maxf(float a, float b)
     
    static float
    maxf(float a, float b, float c)
     
    static double
    min(double a, double b)
     
    static double
    min(double a, double b, double c)
     
    static int
    min(int a, int b)
     
    static int
    min(int a, int b, int c)
     
    static float
    minf(float a, float b)
     
    static float
    minf(float a, float b, float c)
     
    static float
    noise(float x, float y, float z)
    This function computes a random value at the coordinate (x,y,z).
    static float
    noise(float x, float y, float z, int seed)
    This function computes a random value at the coordinate (x,y,z).
    static float
    noiseFBM(float x, float y, float z, float lacunarity, float gain, int octaves)
    Common fractal noise functions are included, which produce a wide variety of nice effects depending on the parameters provided.
    static float
    noiseRidge(float x, float y, float z, float lacunarity, float gain, float offset, int octaves)
    Common fractal noise functions are included, which produce a wide variety of nice effects depending on the parameters provided.
    static float
    noiseTurbulence(float x, float y, float z, float lacunarity, float gain, int octaves)
    Common fractal noise functions are included, which produce a wide variety of nice effects depending on the parameters provided.
    static double
    random(double max)
     
    static double
    random(double min, double max)
     
    static float
    randomf(float max)
     
    static float
    randomf(float min, float max)
     
    static int
    randomi(int max)
     
    static int
    randomi(int min, int max)
     
    static float
    sinf(double radians)
    Returns a floating-point rounded value of the sin function to 8 decimal places.
    static float
    tanf(double radians)
    Returns a floating-point rounded value of the tan function to 8 decimal places.
    static double
    tri(double t)
     
    static float
    trif(float t)
     
    static double
    wrap(double value, double min, double max)
     
    static int
    wrap(int value, int min, int max)
     
    static double
    wrapdist(double v1, double v2, double modulus)
    Computes the distance between v1 and v2 with a wrap-around at the modulus.
    static float
    wrapdistf(float v1, float v2, float modulus)
     
    static float
    wrapf(float value, float min, float max)
     
    static double
    wrapn(double value)
     
    static float
    wrapnf(float value)
     

    Methods inherited from class java.lang.Object

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

    • min

      public static int min(int a, int b)
    • min

      public static int min(int a, int b, int c)
    • max

      public static int max(int a, int b)
    • max

      public static int max(int a, int b, int c)
    • minf

      public static float minf(float a, float b)
    • minf

      public static float minf(float a, float b, float c)
    • maxf

      public static float maxf(float a, float b)
    • maxf

      public static float maxf(float a, float b, float c)
    • min

      public static double min(double a, double b)
    • min

      public static double min(double a, double b, double c)
    • max

      public static double max(double a, double b)
    • max

      public static double max(double a, double b, double c)
    • clamp

      public static double clamp(double value, double min, double max)
    • clampf

      public static float clampf(float value, float min, float max)
    • clamp

      public static int clamp(int value, int min, int max)
    • constrain

      public static double constrain(double value, double min, double max)
    • constrainf

      public static float constrainf(float value, float min, float max)
    • constrain

      public static int constrain(int value, int min, int max)
    • wrapn

      public static double wrapn(double value)
    • wrapnf

      public static float wrapnf(float value)
    • wrap

      public static int wrap(int value, int min, int max)
    • wrap

      public static double wrap(double value, double min, double max)
    • wrapf

      public static float wrapf(float value, float min, float max)
    • randomi

      public static int randomi(int max)
    • randomi

      public static int randomi(int min, int max)
    • random

      public static double random(double max)
    • random

      public static double random(double min, double max)
    • randomf

      public static float randomf(float max)
    • randomf

      public static float randomf(float min, float max)
    • distance

      public static double distance(double x1, double y1, double x2, double y2)
    • distance

      public static double distance(double x1, double y1, double z1, double x2, double y2, double z2)
    • lerp

      public static double lerp(double v1, double v2, double amt)
    • lerpf

      public static float lerpf(float v1, float v2, float amt)
    • lerpi

      public static int lerpi(int v1, int v2, float amt)
    • ilerpf

      public static float ilerpf(float amt, float v1, float v2)
      Inverse linear interpolation, normalizes a value relative to bounds
      Parameters:
      amt - Interpolated value
      v1 - Start value
      v2 - End value
      Returns:
      Normalized value in range 0-1 for amt in [v1,v2]
    • ilerp

      public static double ilerp(double amt, double v1, double v2)
      Inverse linear interpolation, normalizes a value relative to bounds
      Parameters:
      amt - Interpolated value
      v1 - Start value
      v2 - End value
      Returns:
      Normalized value in range 0-1 for amt in [v1,v2]
    • tri

      public static double tri(double t)
    • trif

      public static float trif(float t)
    • avg

      public static double avg(double v1, double v2)
    • avgf

      public static float avgf(float v1, float v2)
    • dist

      public static double dist(double x1, double y1, double x2, double y2)
    • distf

      public static float distf(float x1, float y1, float x2, float y2)
    • dist

      public static double dist(double x1, double y1, double z1, double x2, double y2, double z2)
    • distf

      public static float distf(float x1, float y1, float z1, float x2, float y2, float z2)
    • wrapdist

      public static double wrapdist(double v1, double v2, double modulus)
      Computes the distance between v1 and v2 with a wrap-around at the modulus. Both v1 and v2 must be in the range [0, modulus]. For example, if v1=1, v2=11, and modulus = 12, then the distance is 2, not 10.
      Parameters:
      v1 - First value
      v2 - Second value
      modulus - Modulus to wrap around
      Returns:
      shortest distance between v1-v2 wrapping around the modulus
    • wrapdistf

      public static float wrapdistf(float v1, float v2, float modulus)
    • sinf

      public static float sinf(double radians)
      Returns a floating-point rounded value of the sin function to 8 decimal places. This is often useful because Math.sin(Math.PI) is NOT actually 0.
      Parameters:
      radians - Radians to take sin of
      Returns:
      Result rounded to 8 decimal places
    • cosf

      public static float cosf(double radians)
      Returns a floating-point rounded value of the cos function to 8 decimal places. This is often useful because Math.sin(Math.PI) is NOT actually 0.
      Parameters:
      radians - Radians to take cos of
      Returns:
      Result rounded to 8 decimal places
    • atan2pf

      public static float atan2pf(float y, float x)
      Returns the result of Math.atan2 pushed into the positive space [0-TWO_PI]
      Parameters:
      y - Y
      x - X
      Returns:
      Result of atan2, in the range 0-TWO_PI
    • tanf

      public static float tanf(double radians)
      Returns a floating-point rounded value of the tan function to 8 decimal places. This is often useful because Math.sin(Math.PI) is NOT actually 0.
      Parameters:
      radians - Radians to take cos of
      Returns:
      Result rounded to 8 decimal places
    • noise

      public static float noise(float x, float y, float z)
      This function computes a random value at the coordinate (x,y,z). Adjacent random values are continuous but the noise fluctuates its randomness with period 1, i.e. takes on wholly unrelated values at integer points. Specifically, this implements Ken Perlin's revised noise function from 2002.
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
      Returns:
      Noise value
    • noise

      public static float noise(float x, float y, float z, int seed)
      This function computes a random value at the coordinate (x,y,z). Adjacent random values are continuous but the noise fluctuates its randomness with period 1, i.e. takes on wholly unrelated values at integer points. Specifically, this implements Ken Perlin's revised noise function from 2002.
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
      seed - Seed
      Returns:
      Noise value
    • noiseRidge

      public static float noiseRidge(float x, float y, float z, float lacunarity, float gain, float offset, int octaves)
      Common fractal noise functions are included, which produce a wide variety of nice effects depending on the parameters provided. Note that each function will call stb_perlin_noise3 'octaves' times, so this parameter will affect runtime.
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
      lacunarity - spacing between successive octaves (use exactly 2.0 for wrapping output)
      gain - relative weighting applied to each successive octave
      offset - used to invert the ridges, may need to be larger, not sure
      octaves - number of "octaves" of noise3() to sum
      Returns:
      Noise value
    • noiseFBM

      public static float noiseFBM(float x, float y, float z, float lacunarity, float gain, int octaves)
      Common fractal noise functions are included, which produce a wide variety of nice effects depending on the parameters provided. Note that each function will call stb_perlin_noise3 'octaves' times, so this parameter will affect runtime.
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
      lacunarity - spacing between successive octaves (use exactly 2.0 for wrapping output)
      gain - relative weighting applied to each successive octave
      octaves - number of "octaves" of noise3() to sum
      Returns:
      Noise value
    • noiseTurbulence

      public static float noiseTurbulence(float x, float y, float z, float lacunarity, float gain, int octaves)
      Common fractal noise functions are included, which produce a wide variety of nice effects depending on the parameters provided. Note that each function will call stb_perlin_noise3 'octaves' times, so this parameter will affect runtime.
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
      lacunarity - spacing between successive octaves (use exactly 2.0 for wrapping output)
      gain - relative weighting applied to each successive octave
      octaves - number of "octaves" of noise3() to sum
      Returns:
      Noise value
    • isEmpty

      public static boolean isEmpty(String s)