Commits

Anonymous committed 0212d65

initial add

  • Participants

Comments (0)

Files changed (17)

+syntax: glob
+target/
+.idea
+*.iml
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>net.fishbulb.misc</groupId>
+    <artifactId>gdx-sandbox</artifactId>
+    <version>0.1-SNAPSHOT</version>
+    <packaging>jar</packaging>
+    <name>GDX Sandbox</name>
+
+    <properties>
+        <gdx.version>0.9.8-SNAPSHOT</gdx.version>
+    </properties>
+
+    <repositories>
+        <repository>
+            <id>gdx-nightlies</id>
+            <url>http://libgdx.badlogicgames.com/nightlies/maven</url>
+        </repository>
+    </repositories>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>2.5.1</version>
+                <configuration>
+                    <source>1.7</source>
+                    <target>1.7</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>appassembler-maven-plugin</artifactId>
+                <version>1.3</version>
+                <executions>
+                    <execution>
+                        <id>dist-default</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>assemble</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <binFileExtensions>
+                        <unix>.sh</unix>
+                        <windows>.bat</windows>
+                    </binFileExtensions>
+                    <programs>
+                        <program>
+                            <mainClass>net.fishbulb.misc.sandbox.MainDeskop</mainClass>
+                            <name>main</name>
+                        </program>
+                    </programs>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.badlogic.gdx</groupId>
+            <artifactId>gdx</artifactId>
+            <version>${gdx.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.badlogic.gdx</groupId>
+            <artifactId>gdx-backend-lwjgl</artifactId>
+            <version>${gdx.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <version>0.11.6</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <version>14.0-rc2</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.googlecode.jmockit</groupId>
+            <artifactId>jmockit</artifactId>
+            <version>1.0</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.testng</groupId>
+            <artifactId>testng</artifactId>
+            <version>6.8</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>

src/main/java/net/fishbulb/sandbox/Main.java

+package net.fishbulb.sandbox;
+
+import com.badlogic.gdx.ApplicationListener;
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.Input;
+import com.badlogic.gdx.InputAdapter;
+import com.badlogic.gdx.graphics.GL10;
+
+public class Main extends InputAdapter implements ApplicationListener {
+
+
+    @Override
+    public void create() {
+        Gdx.input.setInputProcessor(this);
+    }
+
+    @Override
+    public void render() {
+        Gdx.gl.glClearColor(0, 0, 0, 0);
+        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
+    }
+
+    @Override
+    public void resize(int width, int height) {
+    }
+
+    @Override
+    public void pause() {}
+
+    @Override
+    public void resume() {}
+
+    @Override
+    public void dispose() {}
+
+    @Override
+    public boolean keyUp(int keyCode) {
+        return true;
+    }
+
+    @Override
+    public boolean keyDown(int keyCode) {
+        switch (keyCode) {
+            case Input.Keys.ESCAPE:
+                Gdx.app.exit();
+                break;
+            case Input.Keys.SPACE:
+                break;
+
+        }
+        return false;
+    }
+
+}

src/main/java/net/fishbulb/sandbox/MainDesktop.java

+package net.fishbulb.sandbox;
+
+import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
+import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
+
+public final class MainDesktop {
+
+    public static void main(String[] args) {
+		LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
+		config.useGL20 = true;
+        config.width = 800;
+        config.height = 600;
+        config.vSyncEnabled = true;
+        config.title = "Sandbox";
+        new LwjglApplication(new Main(), config);
+	}
+}

src/main/java/toxi/math/MathUtils.java

+/*
+ *   __               .__       .__  ._____.           
+ * _/  |_  _______  __|__| ____ |  | |__\_ |__   ______
+ * \   __\/  _ \  \/  /  |/ ___\|  | |  || __ \ /  ___/
+ *  |  | (  <_> >    <|  \  \___|  |_|  || \_\ \\___ \ 
+ *  |__|  \____/__/\_ \__|\___  >____/__||___  /____  >
+ *                   \/       \/             \/     \/ 
+ *
+ * Copyright (c) 2006-2011 Karsten Schmidt
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * http://creativecommons.org/licenses/LGPL/2.1/
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package toxi.math;
+
+import java.util.Random;
+
+/**
+ * Miscellaneous math utilities.
+ */
+public final class MathUtils {
+
+    public static final float THIRD = 1f / 3;
+
+    /**
+     * Square root of 2
+     */
+    public static final float SQRT2 = (float) Math.sqrt(2);
+
+    /**
+     * Square root of 3
+     */
+    public static final float SQRT3 = (float) Math.sqrt(3);
+
+    /**
+     * Log(2)
+     */
+    public static final float LOG2 = (float) Math.log(2);
+
+    /**
+     * PI
+     */
+    public static final float PI = 3.14159265358979323846f;
+
+    /**
+     * The reciprocal of PI: (1/PI)
+     */
+    public static final float INV_PI = 1f / PI;
+
+    /**
+     * PI/2
+     */
+    public static final float HALF_PI = PI / 2;
+
+    /**
+     * PI/3
+     */
+    public static final float THIRD_PI = PI / 3;
+
+    /**
+     * PI/4
+     */
+    public static final float QUARTER_PI = PI / 4;
+
+    /**
+     * PI*2
+     */
+    public static final float TWO_PI = PI * 2;
+
+    /**
+     * PI*1.5
+     */
+    public static final float THREE_HALVES_PI = TWO_PI - HALF_PI;
+
+    /**
+     * PI*PI
+     */
+    public static final float PI_SQUARED = PI * PI;
+
+    /**
+     * Epsilon value
+     */
+    public static final float EPS = 1.1920928955078125E-7f;
+
+    /**
+     * Degrees to radians conversion factor
+     */
+    public static final float DEG2RAD = PI / 180;
+
+    /**
+     * Radians to degrees conversion factor
+     */
+    public static final float RAD2DEG = 180 / PI;
+
+    private static final float SHIFT23 = 1 << 23;
+
+    private static final float INV_SHIFT23 = 1.0f / SHIFT23;
+    private final static double SIN_A = -4d / (PI * PI);
+
+    private final static double SIN_B = 4d / PI;
+    private final static double SIN_P = 9d / 40;
+    /**
+     * Default random number generator used by random methods of this class
+     * which don't use a passed in {@link Random} instance.
+     */
+    public static Random RND = new Random();
+
+    /**
+     * @param x
+     * @return absolute value of x
+     */
+    public static final double abs(double x) {
+        return x < 0 ? -x : x;
+    }
+
+    /**
+     * @param x
+     * @return absolute value of x
+     */
+    public static final float abs(float x) {
+        return x < 0 ? -x : x;
+    }
+
+    /**
+     * @param x
+     * @return absolute value of x
+     */
+    public static final int abs(int x) {
+        int y = x >> 31;
+        return (x ^ y) - y;
+    }
+
+    /**
+     * Rounds up the value to the nearest higher power^2 value.
+     * 
+     * @param x
+     * @return power^2 value
+     */
+    public static final int ceilPowerOf2(int x) {
+        int pow2 = 1;
+        while (pow2 < x) {
+            pow2 <<= 1;
+        }
+        return pow2;
+    }
+
+    public static final double clip(double a, double min, double max) {
+        return a < min ? min : (a > max ? max : a);
+    }
+
+    public static final float clip(float a, float min, float max) {
+        return a < min ? min : (a > max ? max : a);
+    }
+
+    public static final int clip(int a, int min, int max) {
+        return a < min ? min : (a > max ? max : a);
+    }
+
+    public static double clipNormalized(double a) {
+        if (a < 0) {
+            return 0;
+        } else if (a > 1) {
+            return 1;
+        }
+        return a;
+    }
+
+    /**
+     * Clips the value to the 0.0 .. 1.0 interval.
+     * 
+     * @param a
+     * @return clipped value
+     * @since 0012
+     */
+    public static final float clipNormalized(float a) {
+        if (a < 0) {
+            return 0;
+        } else if (a > 1) {
+            return 1;
+        }
+        return a;
+    }
+
+    public static final double cos(final double theta) {
+        return sin(theta + HALF_PI);
+    }
+
+    /**
+     * Returns fast cosine approximation of a value. Note: code from <a
+     * href="http://wiki.java.net/bin/view/Games/JeffGems">wiki posting on
+     * java.net by jeffpk</a>
+     * 
+     * @param theta
+     *            angle in radians.
+     * @return cosine of theta.
+     */
+    public static final float cos(final float theta) {
+        return sin(theta + HALF_PI);
+    }
+
+    public static final double degrees(double radians) {
+        return radians * RAD2DEG;
+    }
+
+    public static final float degrees(float radians) {
+        return radians * RAD2DEG;
+    }
+
+    public static double dualSign(double a, double b) {
+        double x = (a >= 0 ? a : -a);
+        return (b >= 0 ? x : -x);
+    }
+
+    /**
+     * Fast cosine approximation.
+     * 
+     * @param x
+     *            angle in -PI/2 .. +PI/2 interval
+     * @return cosine
+     */
+    public static final double fastCos(final double x) {
+        return fastSin(x + ((x > HALF_PI) ? -THREE_HALVES_PI : HALF_PI));
+    }
+
+    /**
+     * @deprecated
+     */
+    @Deprecated
+    public static final float fastInverseSqrt(float x) {
+        float half = 0.5F * x;
+        int i = Float.floatToIntBits(x);
+        i = 0x5f375a86 - (i >> 1);
+        x = Float.intBitsToFloat(i);
+        return x * (1.5F - half * x * x);
+    }
+
+    /**
+     * Computes a fast approximation to <code>Math.pow(a, b)</code>. Adapted
+     * from http://www.dctsystems.co.uk/Software/power.html.
+     * 
+     * @param a
+     *            a positive number
+     * @param b
+     *            a number
+     * @return a^b
+     * 
+     */
+    public static final float fastPow(float a, float b) {
+        float x = Float.floatToRawIntBits(a);
+        x *= INV_SHIFT23;
+        x -= 127;
+        float y = x - (x >= 0 ? (int) x : (int) x - 1);
+        b *= x + (y - y * y) * 0.346607f;
+        y = b - (b >= 0 ? (int) b : (int) b - 1);
+        y = (y - y * y) * 0.33971f;
+        return Float.intBitsToFloat((int) ((b + 127 - y) * SHIFT23));
+    }
+
+    /**
+     * Fast sine approximation.
+     * 
+     * @param x
+     *            angle in -PI/2 .. +PI/2 interval
+     * @return sine
+     */
+    public static final double fastSin(double x) {
+        // float B = 4/pi;
+        // float C = -4/(pi*pi);
+        // float y = B * x + C * x * abs(x);
+        // y = P * (y * abs(y) - y) + y;
+        x = SIN_B * x + SIN_A * x * abs(x);
+        return SIN_P * (x * abs(x) - x) + x;
+    }
+
+    public static final boolean flipCoin() {
+        return RND.nextBoolean();
+    }
+
+    public static final boolean flipCoin(Random rnd) {
+        return rnd.nextBoolean();
+    }
+
+    public static final long floor(double x) {
+        long y = (long) x;
+        if (x < 0 && x != y) {
+            y--;
+        }
+        return y;
+    }
+
+    /**
+     * This method is a *lot* faster than using (int)Math.floor(x).
+     * 
+     * @param x
+     *            value to be floored
+     * @return floored value as integer
+     * @since 0012
+     */
+    public static final int floor(float x) {
+        int y = (int) x;
+        if (x < 0 && x != y) {
+            y--;
+        }
+        return y;
+    }
+
+    /**
+     * Rounds down the value to the nearest lower power^2 value.
+     * 
+     * @param x
+     * @return power^2 value
+     */
+    public static final int floorPowerOf2(int x) {
+        return (int) Math.pow(2, (int) (Math.log(x) / LOG2));
+    }
+
+    /**
+     * Computes the Greatest Common Devisor of integers p and q.
+     * 
+     * @param p
+     * @param q
+     * @return gcd
+     */
+    public static final int gcd(int p, int q) {
+        if (q == 0) {
+            return p;
+        }
+        return gcd(q, p % q);
+    }
+
+    /**
+     * Creates a single normalized impulse signal with its peak at t=1/k. The
+     * attack and decay period is configurable via the k parameter. Code from:
+     * http://www.iquilezles.org/www/articles/functions/functions.htm
+     * 
+     * @param k
+     *            smoothness
+     * @param t
+     *            time position (should be >= 0)
+     * @return impulse value (as double)
+     */
+    public static double impulse(double k, double t) {
+        double h = k * t;
+        return h * Math.exp(1.0 - h);
+    }
+
+    /**
+     * Creates a single normalized impulse signal with its peak at t=1/k. The
+     * attack and decay period is configurable via the k parameter. Code from:
+     * http://www.iquilezles.org/www/articles/functions/functions.htm
+     * 
+     * @param k
+     *            smoothness
+     * @param t
+     *            time position (should be >= 0)
+     * @return impulse value (as float)
+     */
+    public static float impulse(float k, float t) {
+        float h = k * t;
+        return (float) (h * Math.exp(1.0f - h));
+    }
+
+    public static final int lcm(int p, int q) {
+        return abs(p * q) / gcd(p, q);
+    }
+
+    public static final double max(double a, double b) {
+        return a > b ? a : b;
+    }
+
+    public static final double max(double a, double b, double c) {
+        return (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
+    }
+
+    public static final double max(double[] values) {
+        return max(values[0], values[1], values[2]);
+    }
+
+    public static final float max(float a, float b) {
+        return a > b ? a : b;
+    }
+
+    /**
+     * Returns the maximum value of three floats.
+     * 
+     * @param a
+     * @param b
+     * @param c
+     * @return max val
+     */
+    public static final float max(float a, float b, float c) {
+        return (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
+    }
+
+    public static final float max(float[] values) {
+        return max(values[0], values[1], values[2]);
+    }
+
+    public static final int max(int a, int b) {
+        return a > b ? a : b;
+    }
+
+    /**
+     * Returns the maximum value of three ints.
+     * 
+     * @param a
+     * @param b
+     * @param c
+     * @return max val
+     */
+    public static final int max(int a, int b, int c) {
+        return (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
+    }
+
+    public static final int max(int[] values) {
+        return max(values[0], values[1], values[2]);
+    }
+
+    public static final double min(double a, double b) {
+        return a < b ? a : b;
+    }
+
+    public static final double min(double a, double b, double c) {
+        return (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c);
+    }
+
+    public static final float min(float a, float b) {
+        return a < b ? a : b;
+    }
+
+    /**
+     * Returns the minimum value of three floats.
+     * 
+     * @param a
+     * @param b
+     * @param c
+     * @return min val
+     */
+    public static final float min(float a, float b, float c) {
+        return (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c);
+    }
+
+    public static final int min(int a, int b) {
+        return a < b ? a : b;
+    }
+
+    /**
+     * Returns the minimum value of three ints.
+     * 
+     * @param a
+     * @param b
+     * @param c
+     * @return min val
+     */
+    public static final int min(int a, int b, int c) {
+        return (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c);
+    }
+
+    /**
+     * Returns a random number in the interval -1 .. +1.
+     * 
+     * @return random float
+     */
+    public static final float normalizedRandom() {
+        return RND.nextFloat() * 2 - 1;
+    }
+
+    /**
+     * Returns a random number in the interval -1 .. +1 using the {@link Random}
+     * instance provided.
+     * 
+     * @return random float
+     */
+    public static final float normalizedRandom(Random rnd) {
+        return rnd.nextFloat() * 2 - 1;
+    }
+
+    public static double radians(double degrees) {
+        return degrees * DEG2RAD;
+    }
+
+    public static final float radians(float degrees) {
+        return degrees * DEG2RAD;
+    }
+
+    public static final float random(float max) {
+        return RND.nextFloat() * max;
+    }
+
+    public static final float random(float min, float max) {
+        return RND.nextFloat() * (max - min) + min;
+    }
+
+    public static final int random(int max) {
+        return (int) (RND.nextFloat() * max);
+    }
+
+    public static final int random(int min, int max) {
+        return (int) (RND.nextFloat() * (max - min)) + min;
+    }
+
+    public static final double random(Random rnd, double max) {
+        return rnd.nextDouble() * max;
+    }
+
+    public static final double random(Random rnd, double min, double max) {
+        return rnd.nextDouble() * (max - min) + min;
+    }
+
+    public static final float random(Random rnd, float max) {
+        return rnd.nextFloat() * max;
+    }
+
+    public static final float random(Random rnd, float min, float max) {
+        return rnd.nextFloat() * (max - min) + min;
+    }
+
+    public static final int random(Random rnd, int max) {
+        return (int) (rnd.nextDouble() * max);
+    }
+
+    public static final int random(Random rnd, int min, int max) {
+        return (int) (rnd.nextDouble() * (max - min)) + min;
+    }
+
+    public static final boolean randomChance(double chance) {
+        return RND.nextDouble() < chance;
+    }
+
+    public static final boolean randomChance(float chance) {
+        return RND.nextFloat() < chance;
+    }
+
+    public static final boolean randomChance(Random rnd, double chance) {
+        return rnd.nextDouble() < chance;
+    }
+
+    public static final boolean randomChance(Random rnd, float chance) {
+        return rnd.nextFloat() < chance;
+    }
+
+    public static final double reduceAngle(double theta) {
+        theta %= TWO_PI;
+        if (abs(theta) > PI) {
+            theta = theta - TWO_PI;
+        }
+        if (abs(theta) > HALF_PI) {
+            theta = PI - theta;
+        }
+        return theta;
+    }
+
+    /**
+     * Reduces the given angle into the -PI/4 ... PI/4 interval for faster
+     * computation of sin/cos. This method is used by {@link #sin(float)} &
+     * {@link #cos(float)}.
+     * 
+     * @param theta
+     *            angle in radians
+     * @return reduced angle
+     * @see #sin(float)
+     * @see #cos(float)
+     */
+    public static final float reduceAngle(float theta) {
+        theta %= TWO_PI;
+        if (abs(theta) > PI) {
+            theta = theta - TWO_PI;
+        }
+        if (abs(theta) > HALF_PI) {
+            theta = PI - theta;
+        }
+        return theta;
+    }
+
+    /**
+     * Rounds a double precision value to the given precision.
+     * 
+     * @param val
+     * @param prec
+     * @return rounded value
+     */
+    public static final double roundTo(double val, double prec) {
+        return floor(val / prec + 0.5) * prec;
+    }
+
+    /**
+     * Rounds a single precision value to the given precision.
+     * 
+     * @param val
+     * @param prec
+     * @return rounded value
+     */
+    public static final float roundTo(float val, float prec) {
+        return floor(val / prec + 0.5f) * prec;
+    }
+
+    /**
+     * Rounds an integer value to the given precision.
+     * 
+     * @param val
+     * @param prec
+     * @return rounded value
+     */
+    public static final int roundTo(int val, int prec) {
+        return floor((float) val / prec + 0.5f) * prec;
+    }
+
+    /**
+     * Sets the default Random number generator for this class. This generator
+     * is being reused by all future calls to random() method versions which
+     * don't explicitly ask for a {@link Random} instance to be used.
+     * 
+     * @param rnd
+     */
+    public static void setDefaultRandomGenerator(Random rnd) {
+        RND = rnd;
+    }
+
+    public static int sign(double x) {
+        return x < 0 ? -1 : (x > 0 ? 1 : 0);
+    }
+
+    public static int sign(float x) {
+        return x < 0 ? -1 : (x > 0 ? 1 : 0);
+    }
+
+    public static int sign(int x) {
+        return x < 0 ? -1 : (x > 0 ? 1 : 0);
+    }
+
+    public static final double sin(double theta) {
+        theta = reduceAngle(theta);
+        if (abs(theta) <= QUARTER_PI) {
+            return (float) fastSin(theta);
+        }
+        return (float) fastCos(HALF_PI - theta);
+    }
+
+    /**
+     * Returns a fast sine approximation of a value. Note: code from <a
+     * href="http://wiki.java.net/bin/view/Games/JeffGems">wiki posting on
+     * java.net by jeffpk</a>
+     * 
+     * @param theta
+     *            angle in radians.
+     * @return sine of theta.
+     */
+    public static final float sin(float theta) {
+        theta = reduceAngle(theta);
+        if (abs(theta) <= QUARTER_PI) {
+            return (float) fastSin(theta);
+        }
+        return (float) fastCos(HALF_PI - theta);
+    }
+
+    /**
+     * @deprecated
+     */
+    @Deprecated
+    public static final float sqrt(float x) {
+        x = fastInverseSqrt(x);
+        if (x > 0) {
+            return 1.0f / x;
+        } else {
+            return 0;
+        }
+    }
+}

src/main/java/toxi/math/SinCosLUT.java

+/*
+ *   __               .__       .__  ._____.           
+ * _/  |_  _______  __|__| ____ |  | |__\_ |__   ______
+ * \   __\/  _ \  \/  /  |/ ___\|  | |  || __ \ /  ___/
+ *  |  | (  <_> >    <|  \  \___|  |_|  || \_\ \\___ \ 
+ *  |__|  \____/__/\_ \__|\___  >____/__||___  /____  >
+ *                   \/       \/             \/     \/ 
+ *
+ * Copyright (c) 2006-2011 Karsten Schmidt
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * http://creativecommons.org/licenses/LGPL/2.1/
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package toxi.math;
+
+/**
+ * Lookup table for fast sine & cosine computations. Tables with varying
+ * precisions can be created to which input angles will be rounded to. The
+ * sin/cos methods can be used with both positive and negative input angles as
+ * with the normal Math.sin()/Math.cos() versions.
+ */
+public final class SinCosLUT {
+
+    /**
+     * default precision
+     */
+    public static final float DEFAULT_PRECISION = 0.25f;
+
+    private static SinCosLUT DEFAULT_INSTANCE;
+
+    public static final SinCosLUT getDefaultInstance() {
+        if (DEFAULT_INSTANCE == null) {
+            DEFAULT_INSTANCE = new SinCosLUT();
+        }
+        return DEFAULT_INSTANCE;
+    }
+
+    /**
+     * Lookup table for sine values
+     */
+    private final float[] sinLUT;
+
+    private final float precision;
+
+    private final int period;
+    private final int quadrant;
+
+    private final float deg2rad;
+    private final float rad2deg;
+
+    public SinCosLUT() {
+        this(DEFAULT_PRECISION);
+    }
+
+    public SinCosLUT(float precision) {
+        this.precision = precision;
+        this.period = (int) (360 / precision);
+        this.quadrant = period >> 2;
+        this.deg2rad = (float) (Math.PI / 180.0) * precision;
+        this.rad2deg = (float) (180.0 / Math.PI) / precision;
+        this.sinLUT = new float[period];
+        for (int i = 0; i < period; i++) {
+            sinLUT[i] = (float) Math.sin(i * deg2rad);
+        }
+    }
+
+    /**
+     * Calculate cosine for the passed in angle in radians.
+     * 
+     * @param theta
+     * @return cosine value for theta
+     */
+    public final float cos(float theta) {
+        while (theta < 0) {
+            theta += MathUtils.TWO_PI;
+        }
+        return sinLUT[((int) (theta * rad2deg) + quadrant) % period];
+    }
+
+    public int getPeriod() {
+        return period;
+    }
+
+    public float getPrecision() {
+        return precision;
+    }
+
+    public float[] getSinLUT() {
+        return sinLUT;
+    }
+
+    /**
+     * Calculates sine for the passed angle in radians.
+     * 
+     * @param theta
+     * @return sine value for theta
+     */
+    public final float sin(float theta) {
+        while (theta < 0) {
+            theta += MathUtils.TWO_PI;
+        }
+        return sinLUT[(int) (theta * rad2deg) % period];
+    }
+}

src/main/java/toxi/math/noise/PerlinNoise.java

+/*
+ *   __               .__       .__  ._____.           
+ * _/  |_  _______  __|__| ____ |  | |__\_ |__   ______
+ * \   __\/  _ \  \/  /  |/ ___\|  | |  || __ \ /  ___/
+ *  |  | (  <_> >    <|  \  \___|  |_|  || \_\ \\___ \ 
+ *  |__|  \____/__/\_ \__|\___  >____/__||___  /____  >
+ *                   \/       \/             \/     \/ 
+ *
+ * Copyright (c) 2006-2011 Karsten Schmidt
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * http://creativecommons.org/licenses/LGPL/2.1/
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package toxi.math.noise;
+
+import toxi.math.SinCosLUT;
+
+import java.util.Random;
+
+/**
+ * PERLIN NOISE taken from the java port I originally did for PApplet, based on
+ * an implementation by the german demo group farbrausch as used in their demo
+ * "Art": http://www.farb-rausch.de/fr010src.zip
+ */
+public class PerlinNoise {
+
+    protected static final int PERLIN_YWRAPB = 4;
+
+    protected static final int PERLIN_YWRAP = 1 << PERLIN_YWRAPB;
+
+    protected static final int PERLIN_ZWRAPB = 8;
+
+    protected static final int PERLIN_ZWRAP = 1 << PERLIN_ZWRAPB;
+
+    protected static final int PERLIN_SIZE = 4095;
+
+    private static final float PERLIN_MIN_AMPLITUDE = 0.001f;
+
+    protected int perlin_octaves = 4; // default to medium smooth
+
+    protected float perlin_amp_falloff = 0.5f; // 50% reduction/octave
+
+    // [toxi 031112]
+    // new vars needed due to recent change of cos table in PGraphics
+    protected int perlin_TWOPI, perlin_PI;
+
+    protected float[] perlin_cosTable;
+
+    protected float perlin[];
+
+    protected Random perlinRandom;
+
+    public PerlinNoise() {
+        noiseSeed(System.nanoTime());
+    }
+
+    /**
+     * Computes the Perlin noise function value at point x.
+     */
+    public float noise(float x) {
+        // is this legit? it's a dumb way to do it (but repair it later)
+        return noise(x, 0f, 0f);
+    }
+
+    /**
+     * Computes the Perlin noise function value at the point x, y.
+     */
+    public float noise(float x, float y) {
+        return noise(x, y, 0f);
+    }
+
+    /**
+     * Computes the Perlin noise function value at x, y, z.
+     */
+    public float noise(float x, float y, float z) {
+        if (perlin == null) {
+            if (perlinRandom == null) {
+                perlinRandom = new Random();
+            }
+            perlin = new float[PERLIN_SIZE + 1];
+            for (int i = 0; i < PERLIN_SIZE + 1; i++) {
+                perlin[i] = perlinRandom.nextFloat(); // (float)Math.random();
+            }
+            // [toxi 031112]
+            // noise broke due to recent change of cos table in PGraphics
+            // this will take care of it
+            perlin_cosTable = SinCosLUT.getDefaultInstance().getSinLUT();
+            perlin_TWOPI = perlin_PI = SinCosLUT.getDefaultInstance()
+                    .getPeriod();
+            perlin_PI >>= 1;
+        }
+
+        if (x < 0) {
+            x = -x;
+        }
+        if (y < 0) {
+            y = -y;
+        }
+        if (z < 0) {
+            z = -z;
+        }
+
+        int xi = (int) x, yi = (int) y, zi = (int) z;
+        float xf = (x - xi);
+        float yf = (y - yi);
+        float zf = (z - zi);
+        float rxf, ryf;
+
+        float r = 0;
+        float ampl = 0.5f;
+
+        float n1, n2, n3;
+
+        for (int i = 0; i < perlin_octaves; i++) {
+            int of = xi + (yi << PERLIN_YWRAPB) + (zi << PERLIN_ZWRAPB);
+
+            rxf = noise_fsc(xf);
+            ryf = noise_fsc(yf);
+
+            n1 = perlin[of & PERLIN_SIZE];
+            n1 += rxf * (perlin[(of + 1) & PERLIN_SIZE] - n1);
+            n2 = perlin[(of + PERLIN_YWRAP) & PERLIN_SIZE];
+            n2 += rxf * (perlin[(of + PERLIN_YWRAP + 1) & PERLIN_SIZE] - n2);
+            n1 += ryf * (n2 - n1);
+
+            of += PERLIN_ZWRAP;
+            n2 = perlin[of & PERLIN_SIZE];
+            n2 += rxf * (perlin[(of + 1) & PERLIN_SIZE] - n2);
+            n3 = perlin[(of + PERLIN_YWRAP) & PERLIN_SIZE];
+            n3 += rxf * (perlin[(of + PERLIN_YWRAP + 1) & PERLIN_SIZE] - n3);
+            n2 += ryf * (n3 - n2);
+
+            n1 += noise_fsc(zf) * (n2 - n1);
+
+            r += n1 * ampl;
+            ampl *= perlin_amp_falloff;
+
+            // break if amp has no more impact
+            if (ampl < PERLIN_MIN_AMPLITUDE) {
+                break;
+            }
+
+            xi <<= 1;
+            xf *= 2;
+            yi <<= 1;
+            yf *= 2;
+            zi <<= 1;
+            zf *= 2;
+
+            if (xf >= 1.0f) {
+                xi++;
+                xf--;
+            }
+            if (yf >= 1.0f) {
+                yi++;
+                yf--;
+            }
+            if (zf >= 1.0f) {
+                zi++;
+                zf--;
+            }
+        }
+        return r;
+    }
+
+    // [toxi 031112]
+    // now adjusts to the size of the cosLUT used via
+    // the new variables, defined above
+    private float noise_fsc(float i) {
+        // using bagel's cosine table instead
+        return 0.5f * (1.0f - perlin_cosTable[(int) ((i + 0.5f) * perlin_PI)
+                % perlin_TWOPI]);
+    }
+
+    // [toxi 040903]
+    // make perlin noise quality user controlled to allow
+    // for different levels of detail. lower values will produce
+    // smoother results as higher octaves are surpressed
+
+    public void noiseDetail(int lod) {
+        if (lod > 0) {
+            perlin_octaves = lod;
+        }
+    }
+
+    public void noiseDetail(int lod, float falloff) {
+        if (lod > 0) {
+            perlin_octaves = lod;
+        }
+        if (falloff > 0) {
+            perlin_amp_falloff = falloff;
+        }
+    }
+
+    public void noiseSeed(long what) {
+        if (perlinRandom == null) {
+            perlinRandom = new Random();
+        }
+        perlinRandom.setSeed(what);
+        perlin = null;
+    }
+}

src/main/java/toxi/math/noise/SimplexNoise.java

+/*
+ *   __               .__       .__  ._____.           
+ * _/  |_  _______  __|__| ____ |  | |__\_ |__   ______
+ * \   __\/  _ \  \/  /  |/ ___\|  | |  || __ \ /  ___/
+ *  |  | (  <_> >    <|  \  \___|  |_|  || \_\ \\___ \ 
+ *  |__|  \____/__/\_ \__|\___  >____/__||___  /____  >
+ *                   \/       \/             \/     \/ 
+ *
+ * Copyright (c) 2006-2011 Karsten Schmidt
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * http://creativecommons.org/licenses/LGPL/2.1/
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package toxi.math.noise;
+
+/**
+ * Simplex Noise in 2D, 3D and 4D. Based on the example code of this paper:
+ * http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
+ * 
+ * @author Stefan Gustavson, Linkping University, Sweden (stegu at itn dot liu
+ *         dot se)
+ * @author Karsten Schmidt (slight optimizations & restructuring)
+ */
+public class SimplexNoise {
+
+    private static final double SQRT3 = Math.sqrt(3.0);
+    private static final double SQRT5 = Math.sqrt(5.0);
+
+    /**
+     * Skewing and unskewing factors for 2D, 3D and 4D, some of them
+     * pre-multiplied.
+     */
+    private static final double F2 = 0.5 * (SQRT3 - 1.0);
+    private static final double G2 = (3.0 - SQRT3) / 6.0;
+    private static final double G22 = G2 * 2.0 - 1;
+
+    private static final double F3 = 1.0 / 3.0;
+    private static final double G3 = 1.0 / 6.0;
+
+    private static final double F4 = (SQRT5 - 1.0) / 4.0;
+    private static final double G4 = (5.0 - SQRT5) / 20.0;
+    private static final double G42 = G4 * 2.0;
+    private static final double G43 = G4 * 3.0;
+    private static final double G44 = G4 * 4.0 - 1.0;
+
+    /**
+     * Gradient vectors for 3D (pointing to mid points of all edges of a unit
+     * cube)
+     */
+    private static final int[][] grad3 = { { 1, 1, 0 }, { -1, 1, 0 },
+            { 1, -1, 0 }, { -1, -1, 0 }, { 1, 0, 1 }, { -1, 0, 1 },
+            { 1, 0, -1 }, { -1, 0, -1 }, { 0, 1, 1 }, { 0, -1, 1 },
+            { 0, 1, -1 }, { 0, -1, -1 } };
+
+    /**
+     * Gradient vectors for 4D (pointing to mid points of all edges of a unit 4D
+     * hypercube)
+     */
+    private static final int[][] grad4 = { { 0, 1, 1, 1 }, { 0, 1, 1, -1 },
+            { 0, 1, -1, 1 }, { 0, 1, -1, -1 }, { 0, -1, 1, 1 },
+            { 0, -1, 1, -1 }, { 0, -1, -1, 1 }, { 0, -1, -1, -1 },
+            { 1, 0, 1, 1 }, { 1, 0, 1, -1 }, { 1, 0, -1, 1 }, { 1, 0, -1, -1 },
+            { -1, 0, 1, 1 }, { -1, 0, 1, -1 }, { -1, 0, -1, 1 },
+            { -1, 0, -1, -1 }, { 1, 1, 0, 1 }, { 1, 1, 0, -1 },
+            { 1, -1, 0, 1 }, { 1, -1, 0, -1 }, { -1, 1, 0, 1 },
+            { -1, 1, 0, -1 }, { -1, -1, 0, 1 }, { -1, -1, 0, -1 },
+            { 1, 1, 1, 0 }, { 1, 1, -1, 0 }, { 1, -1, 1, 0 }, { 1, -1, -1, 0 },
+            { -1, 1, 1, 0 }, { -1, 1, -1, 0 }, { -1, -1, 1, 0 },
+            { -1, -1, -1, 0 } };
+
+    /**
+     * Permutation table
+     */
+    private static final int[] p = { 151, 160, 137, 91, 90, 15, 131, 13, 201,
+            95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37,
+            240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62,
+            94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56,
+            87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139,
+            48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133,
+            230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25,
+            63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200,
+            196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3,
+            64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255,
+            82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42,
+            223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153,
+            101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79,
+            113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242,
+            193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249,
+            14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204,
+            176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222,
+            114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180 };
+
+    /**
+     * To remove the need for index wrapping, double the permutation table
+     * length
+     */
+    private static int[] perm = new int[0x200];
+    /**
+     * A lookup table to traverse the simplex around a given point in 4D.
+     * Details can be found where this table is used, in the 4D noise method.
+     */
+    private static final int[][] simplex = { { 0, 1, 2, 3 }, { 0, 1, 3, 2 },
+            { 0, 0, 0, 0 }, { 0, 2, 3, 1 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
+            { 0, 0, 0, 0 }, { 1, 2, 3, 0 }, { 0, 2, 1, 3 }, { 0, 0, 0, 0 },
+            { 0, 3, 1, 2 }, { 0, 3, 2, 1 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
+            { 0, 0, 0, 0 }, { 1, 3, 2, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
+            { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
+            { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 1, 2, 0, 3 }, { 0, 0, 0, 0 },
+            { 1, 3, 0, 2 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
+            { 2, 3, 0, 1 }, { 2, 3, 1, 0 }, { 1, 0, 2, 3 }, { 1, 0, 3, 2 },
+            { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 2, 0, 3, 1 },
+            { 0, 0, 0, 0 }, { 2, 1, 3, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
+            { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
+            { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 2, 0, 1, 3 }, { 0, 0, 0, 0 },
+            { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 3, 0, 1, 2 }, { 3, 0, 2, 1 },
+            { 0, 0, 0, 0 }, { 3, 1, 2, 0 }, { 2, 1, 0, 3 }, { 0, 0, 0, 0 },
+            { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 3, 1, 0, 2 }, { 0, 0, 0, 0 },
+            { 3, 2, 0, 1 }, { 3, 2, 1, 0 } };
+
+    static {
+        for (int i = 0; i < 0x200; i++) {
+            perm[i] = p[i & 0xff];
+        }
+    }
+
+    /**
+     * Computes dot product in 2D.
+     * 
+     * @param g
+     *            2-vector (grid offset)
+     * @param x
+     * @param y
+     * @return dot product
+     */
+    private static double dot(int g[], double x, double y) {
+        return g[0] * x + g[1] * y;
+    }
+
+    /**
+     * Computes dot product in 3D.
+     * 
+     * @param g
+     *            3-vector (grid offset)
+     * @param x
+     * @param y
+     * @param z
+     * @return dot product
+     */
+    private static double dot(int g[], double x, double y, double z) {
+        return g[0] * x + g[1] * y + g[2] * z;
+    }
+
+    /**
+     * Computes dot product in 4D.
+     * 
+     * @param g
+     *            4-vector (grid offset)
+     * @param x
+     * @param y
+     * @param z
+     * @param w
+     * @return dot product
+     */
+    private static double dot(int g[], double x, double y, double z, double w) {
+        return g[0] * x + g[1] * y + g[2] * z + g[3] * w;
+    }
+
+    /**
+     * This method is a *lot* faster than using (int)Math.floor(x).
+     * 
+     * @param x
+     *            value to be floored
+     * @return
+     */
+    private static final int fastfloor(double x) {
+        return x >= 0 ? (int) x : (int) x - 1;
+    }
+
+    /**
+     * Computes 2D Simplex Noise.
+     * 
+     * @param x
+     *            coordinate
+     * @param y
+     *            coordinate
+     * @return noise value in range -1 ... +1.
+     */
+    public static double noise(double x, double y) {
+        double n0 = 0, n1 = 0, n2 = 0; // Noise contributions from the three
+        // corners
+        // Skew the input space to determine which simplex cell we're in
+        double s = (x + y) * F2; // Hairy factor for 2D
+        int i = fastfloor(x + s);
+        int j = fastfloor(y + s);
+        double t = (i + j) * G2;
+        double x0 = x - (i - t); // The x,y distances from the cell origin
+        double y0 = y - (j - t);
+        // For the 2D case, the simplex shape is an equilateral triangle.
+        // Determine which simplex we are in.
+        int i1, j1; // Offsets for second (middle) corner of simplex in (i,j)
+        if (x0 > y0) {
+            i1 = 1;
+            j1 = 0;
+        } // lower triangle, XY order: (0,0)->(1,0)->(1,1)
+        else {
+            i1 = 0;
+            j1 = 1;
+        } // upper triangle, YX order: (0,0)->(0,1)->(1,1)
+          // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
+          // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
+          // c = (3-sqrt(3))/6
+        double x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed
+        double y1 = y0 - j1 + G2;
+        double x2 = x0 + G22; // Offsets for last corner in (x,y) unskewed
+        double y2 = y0 + G22;
+        // Work out the hashed gradient indices of the three simplex corners
+        int ii = i & 0xff;
+        int jj = j & 0xff;
+        // Calculate the contribution from the three corners
+        double t0 = 0.5 - x0 * x0 - y0 * y0;
+        if (t0 > 0) {
+            t0 *= t0;
+            int gi0 = perm[ii + perm[jj]] % 12;
+            n0 = t0 * t0 * dot(grad3[gi0], x0, y0); // (x,y) of grad3 used for
+            // 2D gradient
+        }
+        double t1 = 0.5 - x1 * x1 - y1 * y1;
+        if (t1 > 0) {
+            t1 *= t1;
+            int gi1 = perm[ii + i1 + perm[jj + j1]] % 12;
+            n1 = t1 * t1 * dot(grad3[gi1], x1, y1);
+        }
+        double t2 = 0.5 - x2 * x2 - y2 * y2;
+        if (t2 > 0) {
+            t2 *= t2;
+            int gi2 = perm[ii + 1 + perm[jj + 1]] % 12;
+            n2 = t2 * t2 * dot(grad3[gi2], x2, y2);
+        }
+        // Add contributions from each corner to get the final noise value.
+        // The result is scaled to return values in the interval [-1,1].
+        return 70.0 * (n0 + n1 + n2);
+    }
+
+    /**
+     * Computes 3D Simplex Noise.
+     * 
+     * @param x
+     *            coordinate
+     * @param y
+     *            coordinate
+     * @param z
+     *            coordinate
+     * @return noise value in range -1 ... +1
+     */
+    public static double noise(double x, double y, double z) {
+        double n0 = 0, n1 = 0, n2 = 0, n3 = 0;
+        // Noise contributions from the
+        // four corners
+        // Skew the input space to determine which simplex cell we're in
+        // final double F3 = 1.0 / 3.0;
+        double s = (x + y + z) * F3; // Very nice and simple skew factor
+        // for 3D
+        int i = fastfloor(x + s);
+        int j = fastfloor(y + s);
+        int k = fastfloor(z + s);
+        // final double G3 = 1.0 / 6.0; // Very nice and simple unskew factor,
+        // too
+        double t = (i + j + k) * G3;
+        double x0 = x - (i - t); // The x,y,z distances from the cell origin
+        double y0 = y - (j - t);
+        double z0 = z - (k - t);
+        // For the 3D case, the simplex shape is a slightly irregular
+        // tetrahedron.
+        // Determine which simplex we are in.
+        int i1, j1, k1; // Offsets for second corner of simplex in (i,j,k)
+        // coords
+        int i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords
+        if (x0 >= y0) {
+            if (y0 >= z0) {
+                i1 = 1;
+                j1 = 0;
+                k1 = 0;
+                i2 = 1;
+                j2 = 1;
+                k2 = 0;
+            } // X Y Z order
+            else if (x0 >= z0) {
+                i1 = 1;
+                j1 = 0;
+                k1 = 0;
+                i2 = 1;
+                j2 = 0;
+                k2 = 1;
+            } // X Z Y order
+            else {
+                i1 = 0;
+                j1 = 0;
+                k1 = 1;
+                i2 = 1;
+                j2 = 0;
+                k2 = 1;
+            } // Z X Y order
+        } else { // x0<y0
+            if (y0 < z0) {
+                i1 = 0;
+                j1 = 0;
+                k1 = 1;
+                i2 = 0;
+                j2 = 1;
+                k2 = 1;
+            } // Z Y X order
+            else if (x0 < z0) {
+                i1 = 0;
+                j1 = 1;
+                k1 = 0;
+                i2 = 0;
+                j2 = 1;
+                k2 = 1;
+            } // Y Z X order
+            else {
+                i1 = 0;
+                j1 = 1;
+                k1 = 0;
+                i2 = 1;
+                j2 = 1;
+                k2 = 0;
+            } // Y X Z order
+        }
+        // A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),
+        // a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z),
+        // and
+        // a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z),
+        // where
+        // c = 1/6.
+        double x1 = x0 - i1 + G3; // Offsets for second corner in (x,y,z) coords
+        double y1 = y0 - j1 + G3;
+        double z1 = z0 - k1 + G3;
+
+        double x2 = x0 - i2 + F3; // Offsets for third corner in (x,y,z)
+        double y2 = y0 - j2 + F3;
+        double z2 = z0 - k2 + F3;
+
+        double x3 = x0 - 0.5; // Offsets for last corner in (x,y,z)
+        double y3 = y0 - 0.5;
+        double z3 = z0 - 0.5;
+        // Work out the hashed gradient indices of the four simplex corners
+        int ii = i & 0xff;
+        int jj = j & 0xff;
+        int kk = k & 0xff;
+
+        // Calculate the contribution from the four corners
+        double t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0;
+        if (t0 > 0) {
+            t0 *= t0;
+            int gi0 = perm[ii + perm[jj + perm[kk]]] % 12;
+            n0 = t0 * t0 * dot(grad3[gi0], x0, y0, z0);
+        }
+        double t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1;
+        if (t1 > 0) {
+            t1 *= t1;
+            int gi1 = perm[ii + i1 + perm[jj + j1 + perm[kk + k1]]] % 12;
+            n1 = t1 * t1 * dot(grad3[gi1], x1, y1, z1);
+        }
+        double t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2;
+        if (t2 > 0) {
+            t2 *= t2;
+            int gi2 = perm[ii + i2 + perm[jj + j2 + perm[kk + k2]]] % 12;
+            n2 = t2 * t2 * dot(grad3[gi2], x2, y2, z2);
+        }
+        double t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3;
+        if (t3 > 0) {
+            t3 *= t3;
+            int gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1]]] % 12;
+            n3 = t3 * t3 * dot(grad3[gi3], x3, y3, z3);
+        }
+        // Add contributions from each corner to get the final noise value.
+        // The result is scaled to stay just inside [-1,1]
+        return 32.0 * (n0 + n1 + n2 + n3);
+    }
+
+    /**
+     * Computes 4D Simplex Noise.
+     * 
+     * @param x
+     *            coordinate
+     * @param y
+     *            coordinate
+     * @param z
+     *            coordinate
+     * @param w
+     *            coordinate
+     * @return noise value in range -1 ... +1
+     */
+    public static double noise(double x, double y, double z, double w) {
+        // The skewing and unskewing factors are hairy again for the 4D case
+        double n0 = 0, n1 = 0, n2 = 0, n3 = 0, n4 = 0; // Noise contributions
+        // from the five corners
+        // Skew the (x,y,z,w) space to determine which cell of 24 simplices
+        double s = (x + y + z + w) * F4; // Factor for 4D skewing
+        int i = fastfloor(x + s);
+        int j = fastfloor(y + s);
+        int k = fastfloor(z + s);
+        int l = fastfloor(w + s);
+        double t = (i + j + k + l) * G4; // Factor for 4D unskewing
+        double x0 = x - (i - t); // The x,y,z,w distances from the cell origin
+        double y0 = y - (j - t);
+        double z0 = z - (k - t);
+        double w0 = w - (l - t);
+        // For the 4D case, the simplex is a 4D shape I won't even try to
+        // describe.
+        // To find out which of the 24 possible simplices we're in, we need to
+        // determine the magnitude ordering of x0, y0, z0 and w0.
+        // The method below is a good way of finding the ordering of x,y,z,w and
+        // then find the correct traversal order for the simplex were in.
+        // First, six pair-wise comparisons are performed between each possible
+        // pair of the four coordinates, and the results are used to add up
+        // binary bits for an integer index.
+        int c = 0;
+        if (x0 > y0) {
+            c = 0x20;
+        }
+        if (x0 > z0) {
+            c |= 0x10;
+        }
+        if (y0 > z0) {
+            c |= 0x08;
+        }
+        if (x0 > w0) {
+            c |= 0x04;
+        }
+        if (y0 > w0) {
+            c |= 0x02;
+        }
+        if (z0 > w0) {
+            c |= 0x01;
+        }
+        int i1, j1, k1, l1; // The integer offsets for the second simplex corner
+        int i2, j2, k2, l2; // The integer offsets for the third simplex corner
+        int i3, j3, k3, l3; // The integer offsets for the fourth simplex corner
+        // simplex[c] is a 4-vector with the numbers 0, 1, 2 and 3 in some
+        // order. Many values of c will never occur, since e.g. x>y>z>w makes
+        // x<z, y<w and x<w impossible. Only the 24 indices which have non-zero
+        // entries make any sense. We use a thresholding to set the coordinates
+        // in turn from the largest magnitude. The number 3 in the "simplex"
+        // array is at the position of the largest coordinate.
+        int[] sc = simplex[c];
+        i1 = sc[0] >= 3 ? 1 : 0;
+        j1 = sc[1] >= 3 ? 1 : 0;
+        k1 = sc[2] >= 3 ? 1 : 0;
+        l1 = sc[3] >= 3 ? 1 : 0;
+        // The number 2 in the "simplex" array is at the second largest
+        // coordinate.
+        i2 = sc[0] >= 2 ? 1 : 0;
+        j2 = sc[1] >= 2 ? 1 : 0;
+        k2 = sc[2] >= 2 ? 1 : 0;
+        l2 = sc[3] >= 2 ? 1 : 0;
+        // The number 1 in the "simplex" array is at the second smallest
+        // coordinate.
+        i3 = sc[0] >= 1 ? 1 : 0;
+        j3 = sc[1] >= 1 ? 1 : 0;
+        k3 = sc[2] >= 1 ? 1 : 0;
+        l3 = sc[3] >= 1 ? 1 : 0;
+        // The fifth corner has all coordinate offsets = 1, so no need to look
+        // that up.
+        double x1 = x0 - i1 + G4; // Offsets for second corner in (x,y,z,w)
+        double y1 = y0 - j1 + G4;
+        double z1 = z0 - k1 + G4;
+        double w1 = w0 - l1 + G4;
+
+        double x2 = x0 - i2 + G42; // Offsets for third corner in (x,y,z,w)
+        double y2 = y0 - j2 + G42;
+        double z2 = z0 - k2 + G42;
+        double w2 = w0 - l2 + G42;
+
+        double x3 = x0 - i3 + G43; // Offsets for fourth corner in (x,y,z,w)
+        double y3 = y0 - j3 + G43;
+        double z3 = z0 - k3 + G43;
+        double w3 = w0 - l3 + G43;
+
+        double x4 = x0 + G44; // Offsets for last corner in (x,y,z,w)
+        double y4 = y0 + G44;
+        double z4 = z0 + G44;
+        double w4 = w0 + G44;
+
+        // Work out the hashed gradient indices of the five simplex corners
+        int ii = i & 0xff;
+        int jj = j & 0xff;
+        int kk = k & 0xff;
+        int ll = l & 0xff;
+
+        // Calculate the contribution from the five corners
+        double t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
+        if (t0 > 0) {
+            t0 *= t0;
+            int gi0 = perm[ii + perm[jj + perm[kk + perm[ll]]]] % 32;
+            n0 = t0 * t0 * dot(grad4[gi0], x0, y0, z0, w0);
+        }
+        double t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1;
+        if (t1 > 0) {
+            t1 *= t1;
+            int gi1 = perm[ii + i1
+                    + perm[jj + j1 + perm[kk + k1 + perm[ll + l1]]]] % 32;
+            n1 = t1 * t1 * dot(grad4[gi1], x1, y1, z1, w1);
+        }
+        double t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2;
+        if (t2 > 0) {
+            t2 *= t2;
+            int gi2 = perm[ii + i2
+                    + perm[jj + j2 + perm[kk + k2 + perm[ll + l2]]]] % 32;
+            n2 = t2 * t2 * dot(grad4[gi2], x2, y2, z2, w2);
+        }
+        double t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3;
+        if (t3 > 0) {
+            t3 *= t3;
+            int gi3 = perm[ii + i3
+                    + perm[jj + j3 + perm[kk + k3 + perm[ll + l3]]]] % 32;
+            n3 = t3 * t3 * dot(grad4[gi3], x3, y3, z3, w3);
+        }
+        double t4 = 0.6 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4;
+        if (t4 > 0) {
+            t4 *= t4;
+            int gi4 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32;
+            n4 = t4 * t4 * dot(grad4[gi4], x4, y4, z4, w4);
+        }
+        // Sum up and scale the result to cover the range [-1,1]
+        return 27.0 * (n0 + n1 + n2 + n3 + n4);
+    }
+}

src/main/resources/libgdx-logo.png

Added
New image

src/main/resources/tiles/consolas10x10_gs_tc.png

Added
New image

src/main/resources/tiles/dg_dungeon32.png

Added
New image

src/main/resources/tiles/rogue_male.png

Added
New image

src/main/resources/tiles/terminal.png

Added
New image

src/main/resources/tiles/terminal_trans.png

Added
New image

src/main/resources/tiles/warrior_male.png

Added
New image

src/main/resources/tiles/wizard_male.png

Added
New image

src/test/resources/log4testng.properties

+# https://github.com/cbeust/testng/issues/285
+# Log levels are broken.  This is fixed in head, but not in IDEA's version
+# This means we'll have to use warn() for everything
+# log4testng.rootLogger=DEBUG