Package heronarts.lx.utils
Class LXUtils
java.lang.Object
heronarts.lx.utils.LXUtils
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic floatatan2pf(float y, float x) Returns the result of Math.atan2 pushed into the positive space [0-TWO_PI]static doubleavg(double v1, double v2) static floatavgf(float v1, float v2) static doubleclamp(double value, double min, double max) static intclamp(int value, int min, int max) static floatclampf(float value, float min, float max) static longclampl(long value, long min, long max) static doubleconstrain(double value, double min, double max) static intconstrain(int value, int min, int max) static floatconstrainf(float value, float min, float max) static longconstrainl(long value, long min, long max) static floatcosf(double radians) Returns a floating-point rounded value of the cos function to 8 decimal places.static doubledist(double x1, double y1, double x2, double y2) static doubledist(double x1, double y1, double z1, double x2, double y2, double z2) static doubledistance(double x1, double y1, double x2, double y2) static doubledistance(double x1, double y1, double z1, double x2, double y2, double z2) static floatdistf(float x1, float y1, float x2, float y2) static floatdistf(float x1, float y1, float z1, float x2, float y2, float z2) static doubleilerp(double amt, double v1, double v2) Inverse linear interpolation, normalizes a value relative to boundsstatic floatilerpf(float amt, float v1, float v2) Inverse linear interpolation, normalizes a value relative to boundsstatic booleaninRange(double val, double min, double max) Returns true if value is between [min, max] inclusivestatic booleaninRange(float val, float min, float max) Returns true if value is between [min, max] inclusivestatic booleaninRange(int val, int min, int max) Returns true if value is between [min, max] inclusivestatic booleanstatic doublelerp(double v1, double v2, double amt) static floatlerpf(float v1, float v2, float amt) static intlerpi(int v1, int v2, float amt) static doublemax(double a, double b) static doublemax(double a, double b, double c) static intmax(int a, int b) static intmax(int a, int b, int c) static floatmaxf(float a, float b) static floatmaxf(float a, float b, float c) static doublemin(double a, double b) static doublemin(double a, double b, double c) static intmin(int a, int b) static intmin(int a, int b, int c) static floatminf(float a, float b) static floatminf(float a, float b, float c) static floatnoise(float x, float y, float z) This function computes a random value at the coordinate (x,y,z).static floatnoise(float x, float y, float z, int seed) This function computes a random value at the coordinate (x,y,z).static floatnoiseFBM(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 floatnoiseRidge(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 floatnoiseTurbulence(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 doublerandom(double max) static doublerandom(double min, double max) static floatrandomf(float max) static floatrandomf(float min, float max) static intrandomi(int max) static intrandomi(int min, int max) static floatround2f(float val) Round the floating value to 2 decimal placesstatic floatsinf(double radians) Returns a floating-point rounded value of the sin function to 8 decimal places.static floattanf(double radians) Returns a floating-point rounded value of the tan function to 8 decimal places.static doubletri(double t) static floattrif(float t) static doublewrap(double value, double min, double max) static intwrap(int value, int min, int max) static doublewrapdist(double v1, double v2, double modulus) Computes the distance between v1 and v2 with a wrap-around at the modulus.static floatwrapdistf(float v1, float v2, float modulus) static floatwrapf(float value, float min, float max) static doublewrapn(double value) static floatwrapnf(float value)
-
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) -
clampl
public static long clampl(long value, long min, long 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) -
constrainl
public static long constrainl(long value, long min, long 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) -
inRange
public static boolean inRange(int val, int min, int max) Returns true if value is between [min, max] inclusive- Parameters:
val- Valuemin- Min valuemax- Max value- Returns:
- True if contained in range
-
inRange
public static boolean inRange(float val, float min, float max) Returns true if value is between [min, max] inclusive- Parameters:
val- Valuemin- Min valuemax- Max value- Returns:
- True if contained in range
-
inRange
public static boolean inRange(double val, double min, double max) Returns true if value is between [min, max] inclusive- Parameters:
val- Valuemin- Min valuemax- Max value- Returns:
- True if contained in range
-
ilerpf
public static float ilerpf(float amt, float v1, float v2) Inverse linear interpolation, normalizes a value relative to bounds- Parameters:
amt- Interpolated valuev1- Start valuev2- 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 valuev1- Start valuev2- 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 valuev2- Second valuemodulus- 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) -
round2f
public static float round2f(float val) Round the floating value to 2 decimal places- Parameters:
val- Floating point value- Returns:
- Value rounded to 2 decimal places
-
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- Yx- 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 coordinatey- Y coordinatez- 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 coordinatey- Y coordinatez- Z coordinateseed- 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 coordinatey- Y coordinatez- Z coordinatelacunarity- spacing between successive octaves (use exactly 2.0 for wrapping output)gain- relative weighting applied to each successive octaveoffset- used to invert the ridges, may need to be larger, not sureoctaves- 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 coordinatey- Y coordinatez- Z coordinatelacunarity- spacing between successive octaves (use exactly 2.0 for wrapping output)gain- relative weighting applied to each successive octaveoctaves- 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 coordinatey- Y coordinatez- Z coordinatelacunarity- spacing between successive octaves (use exactly 2.0 for wrapping output)gain- relative weighting applied to each successive octaveoctaves- number of "octaves" of noise3() to sum- Returns:
- Noise value
-
isEmpty
-