org.alchemy.core
Class AlcMath

java.lang.Object
  extended by org.alchemy.core.AlcMath
All Implemented Interfaces:
AlcConstants

public class AlcMath
extends java.lang.Object
implements AlcConstants

Utility class that handles math functions Random number generation, noise etc... Based on Processing: http://dev.processing.org/source/index.cgi/trunk/processing/core/src/processing/core/PApplet.java?view=markup


Field Summary
 
Fields inherited from interface org.alchemy.core.AlcConstants
COLOR_UI_BG, COLOR_UI_BOX, COLOR_UI_END, COLOR_UI_HIGHLIGHT, COLOR_UI_LINE, COLOR_UI_LINE_ALPHA, COLOR_UI_START, CURSOR_ARROW, CURSOR_BLANK, CURSOR_CIRCLE, CURSOR_CROSS, CURSOR_EYEDROPPER, CURSOR_HAND, CURSOR_MOVE, CURSOR_TEXT, CURSOR_WAIT, DIR_DESKTOP, DIR_HOME, DIR_SEPARATOR, DIR_TEMP, FONT_LARGE, FONT_LARGE_BOLD, FONT_MEDIUM, FONT_MEDIUM_BOLD, FONT_SMALL, FONT_SMALL_BOLD, FONT_SMALLER, JAVA_VERSION, JAVA_VERSION_NAME, KEY_MODIFIER, LOCALE, MATH_DEG_TO_RAD, MATH_HALF_PI, MATH_PI, MATH_QUARTER_PI, MATH_RAD_TO_DEG, MATH_THIRD_PI, MATH_TWO_PI, MODULE_AFFECT, MODULE_CREATE, OS_LINUX, OS_MAC, OS_NAME, OS_OTHER, OS_WINDOWS, PEN_CURSOR, PEN_ERASER, PEN_STYLUS, STYLE_BOTH, STYLE_CLIP, STYLE_FILL, STYLE_STROKE, TOOLKIT, USER_NAME
 
Method Summary
static float constrain(float value, float min, float max)
          Constrains a value to not exceed a maximum and minimum value.
static int constrain(int value, int min, int max)
          Constrains a value to not exceed a maximum and minimum value.
static float distance(float x1, float y1, float x2, float y2)
          Calculates the distance between two points.
static float map(float value, float istart, float istop, float ostart, float ostop)
          Convenience function to map a variable from one coordinate space to another.
static double mean(int[] p)
          Return the mean of an int array
 float noise(float x)
          Computes the Perlin noise function value at point x.
 float noise(float x, float y)
          Computes the Perlin noise function value at the point x, y.
 float noise(float x, float y, float z)
          Computes the Perlin noise function value at x, y, z.
 void noiseDetail(int lod)
          make perlin noise quality user controlled to allow for different levels of detail.
 void noiseDetail(int lod, float falloff)
           
 void noiseSeed(long what)
           
 float random(float howbig)
          Return a random number in the range [0, howbig).
 float random(float howsmall, float howbig)
          Return a random number in the range [howsmall, howbig).
 void randomSeed(long what)
           
static float sq(float num)
          Squares a number (multiplies a number by itself).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

random

public final float random(float howbig)
Return a random number in the range [0, howbig).

The number returned will range from zero up to (but not including) 'howbig'.

Parameters:
howbig -
Returns:

random

public final float random(float howsmall,
                          float howbig)
Return a random number in the range [howsmall, howbig).

The number returned will range from 'howsmall' up to (but not including 'howbig'.

If howsmall is >= howbig, howsmall will be returned, meaning that random(5, 5) will return 5 (useful) and random(7, 4) will return 7 (not useful.. better idea?)


randomSeed

public final void randomSeed(long what)

noise

public float noise(float x)
Computes the Perlin noise function value at point x.


noise

public float noise(float x,
                   float y)
Computes the Perlin noise function value at the point x, y.


noise

public final float noise(float x,
                         float y,
                         float z)
Computes the Perlin noise function value at x, y, z.


noiseDetail

public final void noiseDetail(int lod)
make perlin noise quality user controlled to allow for different levels of detail. lower values will produce smoother results as higher octaves are surpressed


noiseDetail

public final void noiseDetail(int lod,
                              float falloff)

noiseSeed

public final void noiseSeed(long what)

mean

public static final double mean(int[] p)
Return the mean of an int array


map

public static final float map(float value,
                              float istart,
                              float istop,
                              float ostart,
                              float ostop)
Convenience function to map a variable from one coordinate space to another. Equivalent to unlerp() followed by lerp().

Parameters:
value - The incoming value to be converted
istart - Lower bound of the value's current range
istop - Upper bound of the value's current range
ostart - Lower bound of the value's target range
ostop - Upper bound of the value's target range
Returns:
The mapped number

constrain

public static final int constrain(int value,
                                  int min,
                                  int max)
Constrains a value to not exceed a maximum and minimum value.

Parameters:
value - The value to constrain
min - Minimum limit
max - Maximum limit
Returns:

constrain

public static final float constrain(float value,
                                    float min,
                                    float max)
Constrains a value to not exceed a maximum and minimum value.

Parameters:
value - The value to constrain
min - Minimum limit
max - Maximum limit
Returns:

distance

public static final float distance(float x1,
                                   float y1,
                                   float x2,
                                   float y2)
Calculates the distance between two points.

Parameters:
x1 - x-coordinate of the first point
y1 - y-coordinate of the first point
x2 - x-coordinate of the second point
y2 - y-coordinate of the second point
Returns:
The distance between the two points

sq

public static final float sq(float num)
Squares a number (multiplies a number by itself).

Parameters:
num - The number to square
Returns:
The squared number