From edf3a817ac5b555d83efa5a4d87767e128dd2db5 Mon Sep 17 00:00:00 2001 From: monkstone Date: Mon, 5 Apr 2021 19:38:44 +0100 Subject: [PATCH 1/3] Change to use module for noise --- lib/picrate/app.rb | 6 +- .../java/monkstone/FastNoiseModuleJava.java | 127 + src/main/java/monkstone/PicrateLibrary.java | 2 + .../java/monkstone/SmoothNoiseModuleJava.java | 127 + .../java/monkstone/noise/FastTerrain.java | 874 ------- src/main/java/monkstone/noise/Noise.java | 90 - .../java/monkstone/noise/NoiseGenerator.java | 75 - src/main/java/monkstone/noise/NoiseMode.java | 28 - .../java/monkstone/noise/OpenSimplex2F.java | 1572 ++++++------ .../java/monkstone/noise/OpenSimplex2S.java | 2244 +++++++++-------- .../java/monkstone/noise/SmoothTerrain.java | 1099 -------- 11 files changed, 2147 insertions(+), 4097 deletions(-) create mode 100644 src/main/java/monkstone/FastNoiseModuleJava.java create mode 100644 src/main/java/monkstone/SmoothNoiseModuleJava.java delete mode 100644 src/main/java/monkstone/noise/FastTerrain.java delete mode 100644 src/main/java/monkstone/noise/Noise.java delete mode 100644 src/main/java/monkstone/noise/NoiseGenerator.java delete mode 100644 src/main/java/monkstone/noise/NoiseMode.java delete mode 100644 src/main/java/monkstone/noise/SmoothTerrain.java diff --git a/lib/picrate/app.rb b/lib/picrate/app.rb index 420bd5d..dc9afc9 100644 --- a/lib/picrate/app.rb +++ b/lib/picrate/app.rb @@ -16,10 +16,6 @@ module Render java_import 'monkstone.vecmath.ShapeRender' end - module NoiseModule - java_import 'monkstone.noise.NoiseMode' - end - # This class is the base class the user should inherit from when making # their own sketch. # @@ -59,7 +55,7 @@ class App < PApplet include HelperMethods include MathTool include Math - include NoiseModule + include FastNoise # Alias some methods for familiarity for Shoes coders. alias oval ellipse alias stroke_width stroke_weight diff --git a/src/main/java/monkstone/FastNoiseModuleJava.java b/src/main/java/monkstone/FastNoiseModuleJava.java new file mode 100644 index 0000000..b9aa227 --- /dev/null +++ b/src/main/java/monkstone/FastNoiseModuleJava.java @@ -0,0 +1,127 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package monkstone; + +import monkstone.noise.OpenSimplex2F; +import org.jruby.Ruby; +import org.jruby.RubyFixnum; +import org.jruby.RubyFloat; +import org.jruby.RubyModule; +import org.jruby.anno.JRubyMethod; +import org.jruby.anno.JRubyModule; +import org.jruby.runtime.ThreadContext; +import org.jruby.runtime.builtin.IRubyObject; + +/** + * + * @author Martin Prout + */ +@JRubyModule(name = "FastNoise") +public class FastNoiseModuleJava { + + static OpenSimplex2F ng = new OpenSimplex2F(System.currentTimeMillis()); + + /** + * + * @param runtime Ruby + */ + public static void createNoiseModule(Ruby runtime) { + RubyModule noiseModule = runtime.defineModule("FastNoise"); + noiseModule.defineAnnotatedMethods(FastNoiseModuleJava.class); + } + + /** + * + * @param context ThreadContext + * @param recv IRubyObject + * @param args array of numeric values + * @return mapped value RubyFloat + */ + @JRubyMethod(name = "tnoise", rest = true, module = true) + public static IRubyObject terrainNoiseImpl(ThreadContext context, IRubyObject recv, IRubyObject[] args) { + double result = 0; + double one; + double two; + double three; + double four; + switch (args.length) { + case 2: + two = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue(); + one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue(); + result = ng.noise2_XBeforeY(one, two); + break; + case 3: + three = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue(); + two = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue(); + one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue(); + result = ng.noise3_XYBeforeZ(one, two, three); + break; + case 4: + four = (args[3] instanceof RubyFloat) ? ((RubyFloat) args[3]).getValue() : ((RubyFixnum) args[3]).getDoubleValue(); + three = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue(); + two = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue(); + one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue(); + result = ng.noise4_XYBeforeZW(one, two, three, four); + break; + default: + throw new RuntimeException("Min 2D Max 4D Noise"); + } + return RubyFloat.newFloat(context.runtime, result); + } + + /** + * + * @param context ThreadContext + * @param recv IRubyObject + * @param args array of numeric values + * @return mapped value RubyFloat + */ + @JRubyMethod(name = "noise", rest = true, module = true) + public static IRubyObject noiseImpl(ThreadContext context, IRubyObject recv, IRubyObject[] args) { + double result = 0; + double one; + double two; + double three; + double four; + switch (args.length) { + case 1: + one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue(); + result = ng.noise2(one, 0); + break; + case 2: + two = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue(); + one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue(); + result = ng.noise2(one, two); + break; + case 3: + three = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue(); + two = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue(); + one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue(); + result = ng.noise3_Classic(one, two, three); + break; + case 4: + four = (args[3] instanceof RubyFloat) ? ((RubyFloat) args[3]).getValue() : ((RubyFixnum) args[3]).getDoubleValue(); + three = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue(); + two = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue(); + one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue(); + result = ng.noise4_Classic(one, two, three, four); + break; + default: + throw new RuntimeException("Maximum of 4D Noise"); + } + return RubyFloat.newFloat(context.runtime, result); + } +// @JRubyMethod(name = "noise_seed", rest = true, module = true) +// public static IRubyObject noiseSeedImpl(ThreadContext context, IRubyObject recv, IRubyObject arg) { +// long seed; +// if (arg instanceof RubyNumeric) { +// seed = ((RubyNumeric) arg).getLongValue(); +// ng = new OpenSimplex2F(seed); +// return RubyBoolean.newBoolean(context.runtime, true); +// } +// return RubyBoolean.newBoolean(context.runtime, false); +// } +} diff --git a/src/main/java/monkstone/PicrateLibrary.java b/src/main/java/monkstone/PicrateLibrary.java index 7d5bde1..8ecd149 100644 --- a/src/main/java/monkstone/PicrateLibrary.java +++ b/src/main/java/monkstone/PicrateLibrary.java @@ -30,6 +30,8 @@ public class PicrateLibrary implements Library{ */ public static void load(final Ruby runtime) { MathToolModule.createMathToolModule(runtime); + FastNoiseModuleJava.createNoiseModule(runtime); + SmoothNoiseModuleJava.createNoiseModule(runtime); Deglut.createDeglut(runtime); Vec2.createVec2(runtime); Vec3.createVec3(runtime); diff --git a/src/main/java/monkstone/SmoothNoiseModuleJava.java b/src/main/java/monkstone/SmoothNoiseModuleJava.java new file mode 100644 index 0000000..66ec47b --- /dev/null +++ b/src/main/java/monkstone/SmoothNoiseModuleJava.java @@ -0,0 +1,127 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package monkstone; + +import monkstone.noise.OpenSimplex2S; +import org.jruby.Ruby; +import org.jruby.RubyFixnum; +import org.jruby.RubyFloat; +import org.jruby.RubyModule; +import org.jruby.anno.JRubyMethod; +import org.jruby.anno.JRubyModule; +import org.jruby.runtime.ThreadContext; +import org.jruby.runtime.builtin.IRubyObject; + +/** + * + * @author Martin Prout + */ +@JRubyModule(name = "SmoothNoise") +public class SmoothNoiseModuleJava { + + static OpenSimplex2S ng = new OpenSimplex2S(System.currentTimeMillis()); + + /** + * + * @param runtime Ruby + */ + public static void createNoiseModule(Ruby runtime) { + RubyModule noiseModule = runtime.defineModule("SmoothNoise"); + noiseModule.defineAnnotatedMethods(SmoothNoiseModuleJava.class); + } + + /** + * + * @param context ThreadContext + * @param recv IRubyObject + * @param args array of numeric values + * @return mapped value RubyFloat + */ + @JRubyMethod(name = "tnoise", rest = true, module = true) + public static IRubyObject terrainNoiseImpl(ThreadContext context, IRubyObject recv, IRubyObject[] args) { + double result = 0; + double one; + double two; + double three; + double four; + switch (args.length) { + case 2: + two = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue(); + one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue(); + result = ng.noise2_XBeforeY(one, two); + break; + case 3: + three = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue(); + two = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue(); + one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue(); + result = ng.noise3_XYBeforeZ(one, two, three); + break; + case 4: + four = (args[3] instanceof RubyFloat) ? ((RubyFloat) args[3]).getValue() : ((RubyFixnum) args[3]).getDoubleValue(); + three = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue(); + two = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue(); + one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue(); + result = ng.noise4_XYBeforeZW(one, two, three, four); + break; + default: + throw new RuntimeException("Min 2D Max 4D Noise"); + } + return RubyFloat.newFloat(context.runtime, result); + } + + /** + * + * @param context ThreadContext + * @param recv IRubyObject + * @param args array of numeric values + * @return mapped value RubyFloat + */ + @JRubyMethod(name = "noise", rest = true, module = true) + public static IRubyObject noiseImpl(ThreadContext context, IRubyObject recv, IRubyObject[] args) { + double result = 0; + double one; + double two; + double three; + double four; + switch (args.length) { + case 1: + one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue(); + result = ng.noise2(one, 0); + break; + case 2: + two = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue(); + one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue(); + result = ng.noise2(one, two); + break; + case 3: + three = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue(); + two = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue(); + one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue(); + result = ng.noise3_Classic(one, two, three); + break; + case 4: + four = (args[3] instanceof RubyFloat) ? ((RubyFloat) args[3]).getValue() : ((RubyFixnum) args[3]).getDoubleValue(); + three = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue(); + two = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue(); + one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue(); + result = ng.noise4_Classic(one, two, three, four); + break; + default: + throw new RuntimeException("Maximum of 4D Noise"); + } + return RubyFloat.newFloat(context.runtime, result); + } +// @JRubyMethod(name = "noise_seed", rest = true, module = true) +// public static IRubyObject noiseSeedImpl(ThreadContext context, IRubyObject recv, IRubyObject arg) { +// long seed; +// if (arg instanceof RubyNumeric) { +// seed = ((RubyNumeric) arg).getLongValue(); +// ng = new OpenSimplex2S(seed); +// return RubyBoolean.newBoolean(context.runtime, true); +// } +// return RubyBoolean.newBoolean(context.runtime, false); +// } +} diff --git a/src/main/java/monkstone/noise/FastTerrain.java b/src/main/java/monkstone/noise/FastTerrain.java deleted file mode 100644 index 990c26b..0000000 --- a/src/main/java/monkstone/noise/FastTerrain.java +++ /dev/null @@ -1,874 +0,0 @@ -package monkstone.noise; - -/** - * K.jpg's OpenSimplex 2, faster variant - * - * - 2D is standard simplex implemented using a lookup table. - 3D is - * "Re-oriented 4-point BCC noise" which constructs a congruent BCC lattice in a - * much different way than usual. - 4D constructs the lattice as a union of five - * copies of its reciprocal. It successively finds the closest point on each. - * - * Multiple versions of each function are provided. See the documentation above - * each, for more info. - */ -public class FastTerrain implements Noise { - - private static final int PSIZE = 2048; - private static final int PMASK = 2047; - - private final short[] perm; - private final Grad2[] permGrad2; - private final Grad3[] permGrad3; - private final Grad4[] permGrad4; - - public FastTerrain(long seed) { - perm = new short[PSIZE]; - permGrad2 = new Grad2[PSIZE]; - permGrad3 = new Grad3[PSIZE]; - permGrad4 = new Grad4[PSIZE]; - short[] source = new short[PSIZE]; - for (short i = 0; i < PSIZE; i++) { - source[i] = i; - } - for (int i = PSIZE - 1; i >= 0; i--) { - seed = seed * 6364136223846793005L + 1442695040888963407L; - int r = (int) ((seed + 31) % (i + 1)); - if (r < 0) { - r += (i + 1); - } - perm[i] = source[r]; - permGrad2[i] = GRADIENTS_2D[perm[i]]; - permGrad3[i] = GRADIENTS_3D[perm[i]]; - permGrad4[i] = GRADIENTS_4D[perm[i]]; - source[r] = source[i]; - } - } - - /* - * Noise Evaluators - */ - /** - * 2D Simplex noise, standard lattice orientation. - * - * @param x - * @param y - * @return - */ - public double noise2(double x, double y) { - - // Get points for A2* lattice - double s = 0.366025403784439 * (x + y); - double xs = x + s, ys = y + s; - - return noise2_Base(xs, ys); - } - - /** - * 2D Simplex noise, with Y pointing down the main diagonal.Might be better - * for a 2D sandbox style game, where Y is vertical.Probably slightly less - * optimal for heightmaps or continent maps. - * - * @param x - * @param y - * @return - */ - public double noise2_XBeforeY(double x, double y) { - - // Skew transform and rotation baked into one. - double xx = x * 0.7071067811865476; - double yy = y * 1.224744871380249; - - return noise2_Base(yy + xx, yy - xx); - } - - /** - * 2D Simplex noise base. Lookup table implementation inspired by - * DigitalShadow. - */ - private double noise2_Base(double xs, double ys) { - double value = 0; - - // Get base points and offsets - int xsb = fastFloor(xs), ysb = fastFloor(ys); - double xsi = xs - xsb, ysi = ys - ysb; - - // Index to point list - int index = (int) ((ysi - xsi) / 2 + 1); - - double ssi = (xsi + ysi) * -0.211324865405187; - double xi = xsi + ssi, yi = ysi + ssi; - - // Point contributions - for (int i = 0; i < 3; i++) { - LatticePoint2D c = LOOKUP_2D[index + i]; - - double dx = xi + c.dx, dy = yi + c.dy; - double attn = 0.5 - dx * dx - dy * dy; - if (attn <= 0) { - continue; - } - - int pxm = (xsb + c.xsv) & PMASK, pym = (ysb + c.ysv) & PMASK; - Grad2 grad = permGrad2[perm[pxm] ^ pym]; - double extrapolation = grad.dx * dx + grad.dy * dy; - - attn *= attn; - value += attn * attn * extrapolation; - } - - return value; - } - - /** - * 3D Re-oriented 4-point BCC noise, with better visual isotropy in (X, - * Y).Recommended for 3D terrain and time-varied animations.The Z coordinate - * should always be the "different" coordinate in your use case.If Y is - * vertical in world coordinates, call noise3_XYBeforeZ(x, z, Y) or use - * noise3_XZBeforeY.If Z is vertical in world coordinates, call - * noise3_XYBeforeZ(x, y, Z). For a time varied animation, call - * noise3_XYBeforeZ(x, y, T). - * - * @param x - * @param y - * @param z - * @return - */ - public double noise3_XYBeforeZ(double x, double y, double z) { - - // Re-orient the cubic lattices without skewing, to make X and Y triangular like 2D. - // Orthonormal rotation. Not a skew transform. - double xy = x + y; - double s2 = xy * -0.211324865405187; - double zz = z * 0.577350269189626; - double xr = x + s2 - zz, yr = y + s2 - zz; - double zr = xy * 0.577350269189626 + zz; - - // Evaluate both lattices to form a BCC lattice. - return noise3_BCC(xr, yr, zr); - } - - /** - * 3D Re-oriented 4-point BCC noise, with better visual isotropy in (X, - * Z).Recommended for 3D terrain and time-varied animations.The Y coordinate - * should always be the "different" coordinate in your use case.If Y is - * vertical in world coordinates, call noise3_XZBeforeY(x, Y, z).If Z is - * vertical in world coordinates, call noise3_XZBeforeY(x, Z, y) or use - * noise3_XYBeforeZ. For a time varied animation, call noise3_XZBeforeY(x, - * T, y) or use noise3_XYBeforeZ. - * - * @param x - * @param y - * @param z - * @return - */ - public double noise3_XZBeforeY(double x, double y, double z) { - - // Re-orient the cubic lattices without skewing, to make X and Z triangular like 2D. - // Orthonormal rotation. Not a skew transform. - double xz = x + z; - double s2 = xz * -0.211324865405187; - double yy = y * 0.577350269189626; - double xr = x + s2 - yy; - double zr = z + s2 - yy; - double yr = xz * 0.577350269189626 + yy; - - // Evaluate both lattices to form a BCC lattice. - return noise3_BCC(xr, yr, zr); - } - - /** - * Generate overlapping cubic lattices for 3D Re-oriented BCC noise. Lookup - * table implementation inspired by DigitalShadow. It was actually faster to - * narrow down the points in the loop itself, than to build up the index - * with enough info to isolate 4 points. - */ - private double noise3_BCC(double xr, double yr, double zr) { - - // Get base and offsets inside cube of first lattice. - int xrb = fastFloor(xr), yrb = fastFloor(yr), zrb = fastFloor(zr); - double xri = xr - xrb, yri = yr - yrb, zri = zr - zrb; - - // Identify which octant of the cube we're in. This determines which cell - // in the other cubic lattice we're in, and also narrows down one point on each. - int xht = (int) (xri + 0.5), yht = (int) (yri + 0.5), zht = (int) (zri + 0.5); - int index = (xht) | (yht << 1) | (zht << 2); - - // Point contributions - double value = 0; - LatticePoint3D c = LOOKUP_3D[index]; - while (c != null) { - double dxr = xri + c.dxr, dyr = yri + c.dyr, dzr = zri + c.dzr; - double attn = 0.5 - dxr * dxr - dyr * dyr - dzr * dzr; - if (attn < 0) { - c = c.nextOnFailure; - } else { - int pxm = (xrb + c.xrv) & PMASK, pym = (yrb + c.yrv) & PMASK, pzm = (zrb + c.zrv) & PMASK; - Grad3 grad = permGrad3[perm[perm[pxm] ^ pym] ^ pzm]; - double extrapolation = grad.dx * dxr + grad.dy * dyr + grad.dz * dzr; - - attn *= attn; - value += attn * attn * extrapolation; - c = c.nextOnSuccess; - } - } - return value; - } - - /** - * 4D FastTerrain noise, with XY and ZW forming orthogonal - * triangular-based planes.Recommended for 3D terrain, where X and Y (or Z - * and W) are horizontal.Recommended for noise(x, y, sin(time), cos(time)) - * trick. - * - * @param x - * @param y - * @param z - * @param w - * @return - */ - public double noise4_XYBeforeZW(double x, double y, double z, double w) { - - double s2 = (x + y) * -0.178275657951399372 + (z + w) * 0.215623393288842828; - double t2 = (z + w) * -0.403949762580207112 + (x + y) * -0.375199083010075342; - double xs = x + s2, ys = y + s2, zs = z + t2, ws = w + t2; - - return noise4_Base(xs, ys, zs, ws); - } - - /** - * 4D FastTerrain noise, with XYZ oriented like noise3_Classic, and W for - * an extra degree of freedom.W repeats eventually.Recommended for - * time-varied animations which texture a 3D object (W=time) - * - * @param x - * @param y - * @param z - * @param w - * @return - */ - public double noise4_XYZBeforeW(double x, double y, double z, double w) { - - double xyz = x + y + z; - double ww = w * 0.2236067977499788; - double s2 = xyz * -0.16666666666666666 + ww; - double xs = x + s2, ys = y + s2, zs = z + s2, ws = -0.5 * xyz + ww; - - return noise4_Base(xs, ys, zs, ws); - } - - /** - * 4D FastTerrain noise base. Current implementation not fully optimized - * by lookup tables. But still comes out slightly ahead of Gustavson's - * Simplex in tests. - */ - private double noise4_Base(double xs, double ys, double zs, double ws) { - double value = 0; - - // Get base points and offsets - int xsb = fastFloor(xs), ysb = fastFloor(ys), zsb = fastFloor(zs), wsb = fastFloor(ws); - double xsi = xs - xsb, ysi = ys - ysb, zsi = zs - zsb, wsi = ws - wsb; - - // If we're in the lower half, flip so we can repeat the code for the upper half. We'll flip back later. - double siSum = xsi + ysi + zsi + wsi; - double ssi = siSum * 0.309016994374947; // Prep for vertex contributions. - boolean inLowerHalf = (siSum < 2); - if (inLowerHalf) { - xsi = 1 - xsi; - ysi = 1 - ysi; - zsi = 1 - zsi; - wsi = 1 - wsi; - siSum = 4 - siSum; - } - - // Consider opposing vertex pairs of the octahedron formed by the central cross-section of the stretched tesseract - double aabb = xsi + ysi - zsi - wsi, abab = xsi - ysi + zsi - wsi, abba = xsi - ysi - zsi + wsi; - double aabbScore = Math.abs(aabb), ababScore = Math.abs(abab), abbaScore = Math.abs(abba); - - // Find the closest point on the stretched tesseract as if it were the upper half - int vertexIndex, via, vib; - double asi, bsi; - if (aabbScore > ababScore && aabbScore > abbaScore) { - if (aabb > 0) { - asi = zsi; - bsi = wsi; - vertexIndex = 0b0011; - via = 0b0111; - vib = 0b1011; - } else { - asi = xsi; - bsi = ysi; - vertexIndex = 0b1100; - via = 0b1101; - vib = 0b1110; - } - } else if (ababScore > abbaScore) { - if (abab > 0) { - asi = ysi; - bsi = wsi; - vertexIndex = 0b0101; - via = 0b0111; - vib = 0b1101; - } else { - asi = xsi; - bsi = zsi; - vertexIndex = 0b1010; - via = 0b1011; - vib = 0b1110; - } - } else { - if (abba > 0) { - asi = ysi; - bsi = zsi; - vertexIndex = 0b1001; - via = 0b1011; - vib = 0b1101; - } else { - asi = xsi; - bsi = wsi; - vertexIndex = 0b0110; - via = 0b0111; - vib = 0b1110; - } - } - if (bsi > asi) { - via = vib; - double temp = bsi; - bsi = asi; - asi = temp; - } - if (siSum + asi > 3) { - vertexIndex = via; - if (siSum + bsi > 4) { - vertexIndex = 0b1111; - } - } - - // Now flip back if we're actually in the lower half. - if (inLowerHalf) { - xsi = 1 - xsi; - ysi = 1 - ysi; - zsi = 1 - zsi; - wsi = 1 - wsi; - vertexIndex ^= 0b1111; - } - - // Five points to add, total, from five copies of the A4 lattice. - for (int i = 0; i < 5; i++) { - - // Update xsb/etc. and add the lattice point's contribution. - LatticePoint4D c = VERTICES_4D[vertexIndex]; - xsb += c.xsv; - ysb += c.ysv; - zsb += c.zsv; - wsb += c.wsv; - double xi = xsi + ssi, yi = ysi + ssi, zi = zsi + ssi, wi = wsi + ssi; - double dx = xi + c.dx, dy = yi + c.dy, dz = zi + c.dz, dw = wi + c.dw; - double attn = 0.5 - dx * dx - dy * dy - dz * dz - dw * dw; - if (attn > 0) { - int pxm = xsb & PMASK, pym = ysb & PMASK, pzm = zsb & PMASK, pwm = wsb & PMASK; - Grad4 grad = permGrad4[perm[perm[perm[pxm] ^ pym] ^ pzm] ^ pwm]; - double ramped = grad.dx * dx + grad.dy * dy + grad.dz * dz + grad.dw * dw; - - attn *= attn; - value += attn * attn * ramped; - } - - // Maybe this helps the compiler/JVM/LLVM/etc. know we can end the loop here. Maybe not. - if (i == 4) { - break; - } - - // Update the relative skewed coordinates to reference the vertex we just added. - // Rather, reference its counterpart on the lattice copy that is shifted down by - // the vector <-0.2, -0.2, -0.2, -0.2> - xsi += c.xsi; - ysi += c.ysi; - zsi += c.zsi; - wsi += c.wsi; - ssi += c.ssiDelta; - - // Next point is the closest vertex on the 4-simplex whose base vertex is the aforementioned vertex. - double score0 = 1.0 + ssi * (-1.0 / 0.309016994374947); // Seems slightly faster than 1.0-xsi-ysi-zsi-wsi - vertexIndex = 0b0000; - if (xsi >= ysi && xsi >= zsi && xsi >= wsi && xsi >= score0) { - vertexIndex = 0b0001; - } else if (ysi > xsi && ysi >= zsi && ysi >= wsi && ysi >= score0) { - vertexIndex = 0b0010; - } else if (zsi > xsi && zsi > ysi && zsi >= wsi && zsi >= score0) { - vertexIndex = 0b0100; - } else if (wsi > xsi && wsi > ysi && wsi > zsi && wsi >= score0) { - vertexIndex = 0b1000; - } - } - - return value; - } - - /* - * Utility - */ - private static int fastFloor(double x) { - int xi = (int) x; - return x < xi ? xi - 1 : xi; - } - - /* - * Definitions - */ - private static final LatticePoint2D[] LOOKUP_2D; - private static final LatticePoint3D[] LOOKUP_3D; - private static final LatticePoint4D[] VERTICES_4D; - - static { - LOOKUP_2D = new LatticePoint2D[4]; - LOOKUP_3D = new LatticePoint3D[8]; - VERTICES_4D = new LatticePoint4D[16]; - - LOOKUP_2D[0] = new LatticePoint2D(1, 0); - LOOKUP_2D[1] = new LatticePoint2D(0, 0); - LOOKUP_2D[2] = new LatticePoint2D(1, 1); - LOOKUP_2D[3] = new LatticePoint2D(0, 1); - - for (int i = 0; i < 8; i++) { - int i1, j1, k1, i2, j2, k2; - i1 = (i) & 1; - j1 = (i >> 1) & 1; - k1 = (i >> 2) & 1; - i2 = i1 ^ 1; - j2 = j1 ^ 1; - k2 = k1 ^ 1; - - // The two points within this octant, one from each of the two cubic half-lattices. - LatticePoint3D c0 = new LatticePoint3D(i1, j1, k1, 0); - LatticePoint3D c1 = new LatticePoint3D(i1 + i2, j1 + j2, k1 + k2, 1); - - // Each single step away on the first half-lattice. - LatticePoint3D c2 = new LatticePoint3D(i1 ^ 1, j1, k1, 0); - LatticePoint3D c3 = new LatticePoint3D(i1, j1 ^ 1, k1, 0); - LatticePoint3D c4 = new LatticePoint3D(i1, j1, k1 ^ 1, 0); - - // Each single step away on the second half-lattice. - LatticePoint3D c5 = new LatticePoint3D(i1 + (i2 ^ 1), j1 + j2, k1 + k2, 1); - LatticePoint3D c6 = new LatticePoint3D(i1 + i2, j1 + (j2 ^ 1), k1 + k2, 1); - LatticePoint3D c7 = new LatticePoint3D(i1 + i2, j1 + j2, k1 + (k2 ^ 1), 1); - - // First two are guaranteed. - c0.nextOnFailure = c0.nextOnSuccess = c1; - c1.nextOnFailure = c1.nextOnSuccess = c2; - - // Once we find one on the first half-lattice, the rest are out. - // In addition, knowing c2 rules out c5. - c2.nextOnFailure = c3; - c2.nextOnSuccess = c6; - c3.nextOnFailure = c4; - c3.nextOnSuccess = c5; - c4.nextOnFailure = c4.nextOnSuccess = c5; - - // Once we find one on the second half-lattice, the rest are out. - c5.nextOnFailure = c6; - c5.nextOnSuccess = null; - c6.nextOnFailure = c7; - c6.nextOnSuccess = null; - c7.nextOnFailure = c7.nextOnSuccess = null; - - LOOKUP_3D[i] = c0; - } - - for (int i = 0; i < 16; i++) { - VERTICES_4D[i] = new LatticePoint4D((i) & 1, (i >> 1) & 1, (i >> 2) & 1, (i >> 3) & 1); - } - } - - @Override - public float noise(float x, float y){ - return (float)noise2_XBeforeY(x, y); - } - - @Override - public float noise(float x, float y, float z) { - return (float)noise3_XYBeforeZ(x, y, z); - } - - @Override - public float noise(float x, float y, float z, float w) { - return (float)noise4_XYBeforeZW(x, y, z, w); - } - - @Override - public void noiseMode(NoiseMode mode) { - - } - - @Override - public void noiseSeed(long seed) { - } - - private static class LatticePoint2D { - - int xsv, ysv; - double dx, dy; - - public LatticePoint2D(int xsv, int ysv) { - this.xsv = xsv; - this.ysv = ysv; - double ssv = (xsv + ysv) * -0.211324865405187; - this.dx = -xsv - ssv; - this.dy = -ysv - ssv; - } - } - - private static class LatticePoint3D { - - public double dxr, dyr, dzr; - public int xrv, yrv, zrv; - LatticePoint3D nextOnFailure, nextOnSuccess; - - public LatticePoint3D(int xrv, int yrv, int zrv, int lattice) { - this.dxr = -xrv + lattice * 0.5; - this.dyr = -yrv + lattice * 0.5; - this.dzr = -zrv + lattice * 0.5; - this.xrv = xrv + lattice * 1024; - this.yrv = yrv + lattice * 1024; - this.zrv = zrv + lattice * 1024; - } - } - - private static class LatticePoint4D { - - int xsv, ysv, zsv, wsv; - double dx, dy, dz, dw; - double xsi, ysi, zsi, wsi; - double ssiDelta; - - public LatticePoint4D(int xsv, int ysv, int zsv, int wsv) { - this.xsv = xsv + 409; - this.ysv = ysv + 409; - this.zsv = zsv + 409; - this.wsv = wsv + 409; - double ssv = (xsv + ysv + zsv + wsv) * 0.309016994374947; - this.dx = -xsv - ssv; - this.dy = -ysv - ssv; - this.dz = -zsv - ssv; - this.dw = -wsv - ssv; - this.xsi = xsi = 0.2 - xsv; - this.ysi = ysi = 0.2 - ysv; - this.zsi = zsi = 0.2 - zsv; - this.wsi = wsi = 0.2 - wsv; - this.ssiDelta = (0.8 - xsv - ysv - zsv - wsv) * 0.309016994374947; - } - } - - /* - * Gradients - */ - private static class Grad2 { - - double dx, dy; - - public Grad2(double dx, double dy) { - this.dx = dx; - this.dy = dy; - } - } - - private static class Grad3 { - - double dx, dy, dz; - - public Grad3(double dx, double dy, double dz) { - this.dx = dx; - this.dy = dy; - this.dz = dz; - } - } - - private static class Grad4 { - - double dx, dy, dz, dw; - - public Grad4(double dx, double dy, double dz, double dw) { - this.dx = dx; - this.dy = dy; - this.dz = dz; - this.dw = dw; - } - } - - private static final double N2 = 0.01001634121365712; - private static final double N3 = 0.030485933181293584; - private static final double N4 = 0.009202377986303158; - private static final Grad2[] GRADIENTS_2D; - private static final Grad3[] GRADIENTS_3D; - private static final Grad4[] GRADIENTS_4D; - - static { - - GRADIENTS_2D = new Grad2[PSIZE]; - Grad2[] grad2 = { - new Grad2(0.130526192220052, 0.99144486137381), - new Grad2(0.38268343236509, 0.923879532511287), - new Grad2(0.608761429008721, 0.793353340291235), - new Grad2(0.793353340291235, 0.608761429008721), - new Grad2(0.923879532511287, 0.38268343236509), - new Grad2(0.99144486137381, 0.130526192220051), - new Grad2(0.99144486137381, -0.130526192220051), - new Grad2(0.923879532511287, -0.38268343236509), - new Grad2(0.793353340291235, -0.60876142900872), - new Grad2(0.608761429008721, -0.793353340291235), - new Grad2(0.38268343236509, -0.923879532511287), - new Grad2(0.130526192220052, -0.99144486137381), - new Grad2(-0.130526192220052, -0.99144486137381), - new Grad2(-0.38268343236509, -0.923879532511287), - new Grad2(-0.608761429008721, -0.793353340291235), - new Grad2(-0.793353340291235, -0.608761429008721), - new Grad2(-0.923879532511287, -0.38268343236509), - new Grad2(-0.99144486137381, -0.130526192220052), - new Grad2(-0.99144486137381, 0.130526192220051), - new Grad2(-0.923879532511287, 0.38268343236509), - new Grad2(-0.793353340291235, 0.608761429008721), - new Grad2(-0.608761429008721, 0.793353340291235), - new Grad2(-0.38268343236509, 0.923879532511287), - new Grad2(-0.130526192220052, 0.99144486137381) - }; - for (Grad2 grad21 : grad2) { - grad21.dx /= N2; - grad21.dy /= N2; - } - for (int i = 0; i < PSIZE; i++) { - GRADIENTS_2D[i] = grad2[i % grad2.length]; - } - - GRADIENTS_3D = new Grad3[PSIZE]; - Grad3[] grad3 = { - new Grad3(-2.22474487139, -2.22474487139, -1.0), - new Grad3(-2.22474487139, -2.22474487139, 1.0), - new Grad3(-3.0862664687972017, -1.1721513422464978, 0.0), - new Grad3(-1.1721513422464978, -3.0862664687972017, 0.0), - new Grad3(-2.22474487139, -1.0, -2.22474487139), - new Grad3(-2.22474487139, 1.0, -2.22474487139), - new Grad3(-1.1721513422464978, 0.0, -3.0862664687972017), - new Grad3(-3.0862664687972017, 0.0, -1.1721513422464978), - new Grad3(-2.22474487139, -1.0, 2.22474487139), - new Grad3(-2.22474487139, 1.0, 2.22474487139), - new Grad3(-3.0862664687972017, 0.0, 1.1721513422464978), - new Grad3(-1.1721513422464978, 0.0, 3.0862664687972017), - new Grad3(-2.22474487139, 2.22474487139, -1.0), - new Grad3(-2.22474487139, 2.22474487139, 1.0), - new Grad3(-1.1721513422464978, 3.0862664687972017, 0.0), - new Grad3(-3.0862664687972017, 1.1721513422464978, 0.0), - new Grad3(-1.0, -2.22474487139, -2.22474487139), - new Grad3(1.0, -2.22474487139, -2.22474487139), - new Grad3(0.0, -3.0862664687972017, -1.1721513422464978), - new Grad3(0.0, -1.1721513422464978, -3.0862664687972017), - new Grad3(-1.0, -2.22474487139, 2.22474487139), - new Grad3(1.0, -2.22474487139, 2.22474487139), - new Grad3(0.0, -1.1721513422464978, 3.0862664687972017), - new Grad3(0.0, -3.0862664687972017, 1.1721513422464978), - new Grad3(-1.0, 2.22474487139, -2.22474487139), - new Grad3(1.0, 2.22474487139, -2.22474487139), - new Grad3(0.0, 1.1721513422464978, -3.0862664687972017), - new Grad3(0.0, 3.0862664687972017, -1.1721513422464978), - new Grad3(-1.0, 2.22474487139, 2.22474487139), - new Grad3(1.0, 2.22474487139, 2.22474487139), - new Grad3(0.0, 3.0862664687972017, 1.1721513422464978), - new Grad3(0.0, 1.1721513422464978, 3.0862664687972017), - new Grad3(2.22474487139, -2.22474487139, -1.0), - new Grad3(2.22474487139, -2.22474487139, 1.0), - new Grad3(1.1721513422464978, -3.0862664687972017, 0.0), - new Grad3(3.0862664687972017, -1.1721513422464978, 0.0), - new Grad3(2.22474487139, -1.0, -2.22474487139), - new Grad3(2.22474487139, 1.0, -2.22474487139), - new Grad3(3.0862664687972017, 0.0, -1.1721513422464978), - new Grad3(1.1721513422464978, 0.0, -3.0862664687972017), - new Grad3(2.22474487139, -1.0, 2.22474487139), - new Grad3(2.22474487139, 1.0, 2.22474487139), - new Grad3(1.1721513422464978, 0.0, 3.0862664687972017), - new Grad3(3.0862664687972017, 0.0, 1.1721513422464978), - new Grad3(2.22474487139, 2.22474487139, -1.0), - new Grad3(2.22474487139, 2.22474487139, 1.0), - new Grad3(3.0862664687972017, 1.1721513422464978, 0.0), - new Grad3(1.1721513422464978, 3.0862664687972017, 0.0) - }; - for (Grad3 grad31 : grad3) { - grad31.dx /= N3; - grad31.dy /= N3; - grad31.dz /= N3; - } - for (int i = 0; i < PSIZE; i++) { - GRADIENTS_3D[i] = grad3[i % grad3.length]; - } - - GRADIENTS_4D = new Grad4[PSIZE]; - Grad4[] grad4 = { - new Grad4(-0.753341017856078, -0.37968289875261624, -0.37968289875261624, -0.37968289875261624), - new Grad4(-0.7821684431180708, -0.4321472685365301, -0.4321472685365301, 0.12128480194602098), - new Grad4(-0.7821684431180708, -0.4321472685365301, 0.12128480194602098, -0.4321472685365301), - new Grad4(-0.7821684431180708, 0.12128480194602098, -0.4321472685365301, -0.4321472685365301), - new Grad4(-0.8586508742123365, -0.508629699630796, 0.044802370851755174, 0.044802370851755174), - new Grad4(-0.8586508742123365, 0.044802370851755174, -0.508629699630796, 0.044802370851755174), - new Grad4(-0.8586508742123365, 0.044802370851755174, 0.044802370851755174, -0.508629699630796), - new Grad4(-0.9982828964265062, -0.03381941603233842, -0.03381941603233842, -0.03381941603233842), - new Grad4(-0.37968289875261624, -0.753341017856078, -0.37968289875261624, -0.37968289875261624), - new Grad4(-0.4321472685365301, -0.7821684431180708, -0.4321472685365301, 0.12128480194602098), - new Grad4(-0.4321472685365301, -0.7821684431180708, 0.12128480194602098, -0.4321472685365301), - new Grad4(0.12128480194602098, -0.7821684431180708, -0.4321472685365301, -0.4321472685365301), - new Grad4(-0.508629699630796, -0.8586508742123365, 0.044802370851755174, 0.044802370851755174), - new Grad4(0.044802370851755174, -0.8586508742123365, -0.508629699630796, 0.044802370851755174), - new Grad4(0.044802370851755174, -0.8586508742123365, 0.044802370851755174, -0.508629699630796), - new Grad4(-0.03381941603233842, -0.9982828964265062, -0.03381941603233842, -0.03381941603233842), - new Grad4(-0.37968289875261624, -0.37968289875261624, -0.753341017856078, -0.37968289875261624), - new Grad4(-0.4321472685365301, -0.4321472685365301, -0.7821684431180708, 0.12128480194602098), - new Grad4(-0.4321472685365301, 0.12128480194602098, -0.7821684431180708, -0.4321472685365301), - new Grad4(0.12128480194602098, -0.4321472685365301, -0.7821684431180708, -0.4321472685365301), - new Grad4(-0.508629699630796, 0.044802370851755174, -0.8586508742123365, 0.044802370851755174), - new Grad4(0.044802370851755174, -0.508629699630796, -0.8586508742123365, 0.044802370851755174), - new Grad4(0.044802370851755174, 0.044802370851755174, -0.8586508742123365, -0.508629699630796), - new Grad4(-0.03381941603233842, -0.03381941603233842, -0.9982828964265062, -0.03381941603233842), - new Grad4(-0.37968289875261624, -0.37968289875261624, -0.37968289875261624, -0.753341017856078), - new Grad4(-0.4321472685365301, -0.4321472685365301, 0.12128480194602098, -0.7821684431180708), - new Grad4(-0.4321472685365301, 0.12128480194602098, -0.4321472685365301, -0.7821684431180708), - new Grad4(0.12128480194602098, -0.4321472685365301, -0.4321472685365301, -0.7821684431180708), - new Grad4(-0.508629699630796, 0.044802370851755174, 0.044802370851755174, -0.8586508742123365), - new Grad4(0.044802370851755174, -0.508629699630796, 0.044802370851755174, -0.8586508742123365), - new Grad4(0.044802370851755174, 0.044802370851755174, -0.508629699630796, -0.8586508742123365), - new Grad4(-0.03381941603233842, -0.03381941603233842, -0.03381941603233842, -0.9982828964265062), - new Grad4(-0.6740059517812944, -0.3239847771997537, -0.3239847771997537, 0.5794684678643381), - new Grad4(-0.7504883828755602, -0.4004672082940195, 0.15296486218853164, 0.5029860367700724), - new Grad4(-0.7504883828755602, 0.15296486218853164, -0.4004672082940195, 0.5029860367700724), - new Grad4(-0.8828161875373585, 0.08164729285680945, 0.08164729285680945, 0.4553054119602712), - new Grad4(-0.4553054119602712, -0.08164729285680945, -0.08164729285680945, 0.8828161875373585), - new Grad4(-0.5029860367700724, -0.15296486218853164, 0.4004672082940195, 0.7504883828755602), - new Grad4(-0.5029860367700724, 0.4004672082940195, -0.15296486218853164, 0.7504883828755602), - new Grad4(-0.5794684678643381, 0.3239847771997537, 0.3239847771997537, 0.6740059517812944), - new Grad4(-0.3239847771997537, -0.6740059517812944, -0.3239847771997537, 0.5794684678643381), - new Grad4(-0.4004672082940195, -0.7504883828755602, 0.15296486218853164, 0.5029860367700724), - new Grad4(0.15296486218853164, -0.7504883828755602, -0.4004672082940195, 0.5029860367700724), - new Grad4(0.08164729285680945, -0.8828161875373585, 0.08164729285680945, 0.4553054119602712), - new Grad4(-0.08164729285680945, -0.4553054119602712, -0.08164729285680945, 0.8828161875373585), - new Grad4(-0.15296486218853164, -0.5029860367700724, 0.4004672082940195, 0.7504883828755602), - new Grad4(0.4004672082940195, -0.5029860367700724, -0.15296486218853164, 0.7504883828755602), - new Grad4(0.3239847771997537, -0.5794684678643381, 0.3239847771997537, 0.6740059517812944), - new Grad4(-0.3239847771997537, -0.3239847771997537, -0.6740059517812944, 0.5794684678643381), - new Grad4(-0.4004672082940195, 0.15296486218853164, -0.7504883828755602, 0.5029860367700724), - new Grad4(0.15296486218853164, -0.4004672082940195, -0.7504883828755602, 0.5029860367700724), - new Grad4(0.08164729285680945, 0.08164729285680945, -0.8828161875373585, 0.4553054119602712), - new Grad4(-0.08164729285680945, -0.08164729285680945, -0.4553054119602712, 0.8828161875373585), - new Grad4(-0.15296486218853164, 0.4004672082940195, -0.5029860367700724, 0.7504883828755602), - new Grad4(0.4004672082940195, -0.15296486218853164, -0.5029860367700724, 0.7504883828755602), - new Grad4(0.3239847771997537, 0.3239847771997537, -0.5794684678643381, 0.6740059517812944), - new Grad4(-0.6740059517812944, -0.3239847771997537, 0.5794684678643381, -0.3239847771997537), - new Grad4(-0.7504883828755602, -0.4004672082940195, 0.5029860367700724, 0.15296486218853164), - new Grad4(-0.7504883828755602, 0.15296486218853164, 0.5029860367700724, -0.4004672082940195), - new Grad4(-0.8828161875373585, 0.08164729285680945, 0.4553054119602712, 0.08164729285680945), - new Grad4(-0.4553054119602712, -0.08164729285680945, 0.8828161875373585, -0.08164729285680945), - new Grad4(-0.5029860367700724, -0.15296486218853164, 0.7504883828755602, 0.4004672082940195), - new Grad4(-0.5029860367700724, 0.4004672082940195, 0.7504883828755602, -0.15296486218853164), - new Grad4(-0.5794684678643381, 0.3239847771997537, 0.6740059517812944, 0.3239847771997537), - new Grad4(-0.3239847771997537, -0.6740059517812944, 0.5794684678643381, -0.3239847771997537), - new Grad4(-0.4004672082940195, -0.7504883828755602, 0.5029860367700724, 0.15296486218853164), - new Grad4(0.15296486218853164, -0.7504883828755602, 0.5029860367700724, -0.4004672082940195), - new Grad4(0.08164729285680945, -0.8828161875373585, 0.4553054119602712, 0.08164729285680945), - new Grad4(-0.08164729285680945, -0.4553054119602712, 0.8828161875373585, -0.08164729285680945), - new Grad4(-0.15296486218853164, -0.5029860367700724, 0.7504883828755602, 0.4004672082940195), - new Grad4(0.4004672082940195, -0.5029860367700724, 0.7504883828755602, -0.15296486218853164), - new Grad4(0.3239847771997537, -0.5794684678643381, 0.6740059517812944, 0.3239847771997537), - new Grad4(-0.3239847771997537, -0.3239847771997537, 0.5794684678643381, -0.6740059517812944), - new Grad4(-0.4004672082940195, 0.15296486218853164, 0.5029860367700724, -0.7504883828755602), - new Grad4(0.15296486218853164, -0.4004672082940195, 0.5029860367700724, -0.7504883828755602), - new Grad4(0.08164729285680945, 0.08164729285680945, 0.4553054119602712, -0.8828161875373585), - new Grad4(-0.08164729285680945, -0.08164729285680945, 0.8828161875373585, -0.4553054119602712), - new Grad4(-0.15296486218853164, 0.4004672082940195, 0.7504883828755602, -0.5029860367700724), - new Grad4(0.4004672082940195, -0.15296486218853164, 0.7504883828755602, -0.5029860367700724), - new Grad4(0.3239847771997537, 0.3239847771997537, 0.6740059517812944, -0.5794684678643381), - new Grad4(-0.6740059517812944, 0.5794684678643381, -0.3239847771997537, -0.3239847771997537), - new Grad4(-0.7504883828755602, 0.5029860367700724, -0.4004672082940195, 0.15296486218853164), - new Grad4(-0.7504883828755602, 0.5029860367700724, 0.15296486218853164, -0.4004672082940195), - new Grad4(-0.8828161875373585, 0.4553054119602712, 0.08164729285680945, 0.08164729285680945), - new Grad4(-0.4553054119602712, 0.8828161875373585, -0.08164729285680945, -0.08164729285680945), - new Grad4(-0.5029860367700724, 0.7504883828755602, -0.15296486218853164, 0.4004672082940195), - new Grad4(-0.5029860367700724, 0.7504883828755602, 0.4004672082940195, -0.15296486218853164), - new Grad4(-0.5794684678643381, 0.6740059517812944, 0.3239847771997537, 0.3239847771997537), - new Grad4(-0.3239847771997537, 0.5794684678643381, -0.6740059517812944, -0.3239847771997537), - new Grad4(-0.4004672082940195, 0.5029860367700724, -0.7504883828755602, 0.15296486218853164), - new Grad4(0.15296486218853164, 0.5029860367700724, -0.7504883828755602, -0.4004672082940195), - new Grad4(0.08164729285680945, 0.4553054119602712, -0.8828161875373585, 0.08164729285680945), - new Grad4(-0.08164729285680945, 0.8828161875373585, -0.4553054119602712, -0.08164729285680945), - new Grad4(-0.15296486218853164, 0.7504883828755602, -0.5029860367700724, 0.4004672082940195), - new Grad4(0.4004672082940195, 0.7504883828755602, -0.5029860367700724, -0.15296486218853164), - new Grad4(0.3239847771997537, 0.6740059517812944, -0.5794684678643381, 0.3239847771997537), - new Grad4(-0.3239847771997537, 0.5794684678643381, -0.3239847771997537, -0.6740059517812944), - new Grad4(-0.4004672082940195, 0.5029860367700724, 0.15296486218853164, -0.7504883828755602), - new Grad4(0.15296486218853164, 0.5029860367700724, -0.4004672082940195, -0.7504883828755602), - new Grad4(0.08164729285680945, 0.4553054119602712, 0.08164729285680945, -0.8828161875373585), - new Grad4(-0.08164729285680945, 0.8828161875373585, -0.08164729285680945, -0.4553054119602712), - new Grad4(-0.15296486218853164, 0.7504883828755602, 0.4004672082940195, -0.5029860367700724), - new Grad4(0.4004672082940195, 0.7504883828755602, -0.15296486218853164, -0.5029860367700724), - new Grad4(0.3239847771997537, 0.6740059517812944, 0.3239847771997537, -0.5794684678643381), - new Grad4(0.5794684678643381, -0.6740059517812944, -0.3239847771997537, -0.3239847771997537), - new Grad4(0.5029860367700724, -0.7504883828755602, -0.4004672082940195, 0.15296486218853164), - new Grad4(0.5029860367700724, -0.7504883828755602, 0.15296486218853164, -0.4004672082940195), - new Grad4(0.4553054119602712, -0.8828161875373585, 0.08164729285680945, 0.08164729285680945), - new Grad4(0.8828161875373585, -0.4553054119602712, -0.08164729285680945, -0.08164729285680945), - new Grad4(0.7504883828755602, -0.5029860367700724, -0.15296486218853164, 0.4004672082940195), - new Grad4(0.7504883828755602, -0.5029860367700724, 0.4004672082940195, -0.15296486218853164), - new Grad4(0.6740059517812944, -0.5794684678643381, 0.3239847771997537, 0.3239847771997537), - new Grad4(0.5794684678643381, -0.3239847771997537, -0.6740059517812944, -0.3239847771997537), - new Grad4(0.5029860367700724, -0.4004672082940195, -0.7504883828755602, 0.15296486218853164), - new Grad4(0.5029860367700724, 0.15296486218853164, -0.7504883828755602, -0.4004672082940195), - new Grad4(0.4553054119602712, 0.08164729285680945, -0.8828161875373585, 0.08164729285680945), - new Grad4(0.8828161875373585, -0.08164729285680945, -0.4553054119602712, -0.08164729285680945), - new Grad4(0.7504883828755602, -0.15296486218853164, -0.5029860367700724, 0.4004672082940195), - new Grad4(0.7504883828755602, 0.4004672082940195, -0.5029860367700724, -0.15296486218853164), - new Grad4(0.6740059517812944, 0.3239847771997537, -0.5794684678643381, 0.3239847771997537), - new Grad4(0.5794684678643381, -0.3239847771997537, -0.3239847771997537, -0.6740059517812944), - new Grad4(0.5029860367700724, -0.4004672082940195, 0.15296486218853164, -0.7504883828755602), - new Grad4(0.5029860367700724, 0.15296486218853164, -0.4004672082940195, -0.7504883828755602), - new Grad4(0.4553054119602712, 0.08164729285680945, 0.08164729285680945, -0.8828161875373585), - new Grad4(0.8828161875373585, -0.08164729285680945, -0.08164729285680945, -0.4553054119602712), - new Grad4(0.7504883828755602, -0.15296486218853164, 0.4004672082940195, -0.5029860367700724), - new Grad4(0.7504883828755602, 0.4004672082940195, -0.15296486218853164, -0.5029860367700724), - new Grad4(0.6740059517812944, 0.3239847771997537, 0.3239847771997537, -0.5794684678643381), - new Grad4(0.03381941603233842, 0.03381941603233842, 0.03381941603233842, 0.9982828964265062), - new Grad4(-0.044802370851755174, -0.044802370851755174, 0.508629699630796, 0.8586508742123365), - new Grad4(-0.044802370851755174, 0.508629699630796, -0.044802370851755174, 0.8586508742123365), - new Grad4(-0.12128480194602098, 0.4321472685365301, 0.4321472685365301, 0.7821684431180708), - new Grad4(0.508629699630796, -0.044802370851755174, -0.044802370851755174, 0.8586508742123365), - new Grad4(0.4321472685365301, -0.12128480194602098, 0.4321472685365301, 0.7821684431180708), - new Grad4(0.4321472685365301, 0.4321472685365301, -0.12128480194602098, 0.7821684431180708), - new Grad4(0.37968289875261624, 0.37968289875261624, 0.37968289875261624, 0.753341017856078), - new Grad4(0.03381941603233842, 0.03381941603233842, 0.9982828964265062, 0.03381941603233842), - new Grad4(-0.044802370851755174, 0.044802370851755174, 0.8586508742123365, 0.508629699630796), - new Grad4(-0.044802370851755174, 0.508629699630796, 0.8586508742123365, -0.044802370851755174), - new Grad4(-0.12128480194602098, 0.4321472685365301, 0.7821684431180708, 0.4321472685365301), - new Grad4(0.508629699630796, -0.044802370851755174, 0.8586508742123365, -0.044802370851755174), - new Grad4(0.4321472685365301, -0.12128480194602098, 0.7821684431180708, 0.4321472685365301), - new Grad4(0.4321472685365301, 0.4321472685365301, 0.7821684431180708, -0.12128480194602098), - new Grad4(0.37968289875261624, 0.37968289875261624, 0.753341017856078, 0.37968289875261624), - new Grad4(0.03381941603233842, 0.9982828964265062, 0.03381941603233842, 0.03381941603233842), - new Grad4(-0.044802370851755174, 0.8586508742123365, -0.044802370851755174, 0.508629699630796), - new Grad4(-0.044802370851755174, 0.8586508742123365, 0.508629699630796, -0.044802370851755174), - new Grad4(-0.12128480194602098, 0.7821684431180708, 0.4321472685365301, 0.4321472685365301), - new Grad4(0.508629699630796, 0.8586508742123365, -0.044802370851755174, -0.044802370851755174), - new Grad4(0.4321472685365301, 0.7821684431180708, -0.12128480194602098, 0.4321472685365301), - new Grad4(0.4321472685365301, 0.7821684431180708, 0.4321472685365301, -0.12128480194602098), - new Grad4(0.37968289875261624, 0.753341017856078, 0.37968289875261624, 0.37968289875261624), - new Grad4(0.9982828964265062, 0.03381941603233842, 0.03381941603233842, 0.03381941603233842), - new Grad4(0.8586508742123365, -0.044802370851755174, -0.044802370851755174, 0.508629699630796), - new Grad4(0.8586508742123365, -0.044802370851755174, 0.508629699630796, -0.044802370851755174), - new Grad4(0.7821684431180708, -0.12128480194602098, 0.4321472685365301, 0.4321472685365301), - new Grad4(0.8586508742123365, 0.508629699630796, -0.044802370851755174, -0.044802370851755174), - new Grad4(0.7821684431180708, 0.4321472685365301, -0.12128480194602098, 0.4321472685365301), - new Grad4(0.7821684431180708, 0.4321472685365301, 0.4321472685365301, -0.12128480194602098), - new Grad4(0.753341017856078, 0.37968289875261624, 0.37968289875261624, 0.37968289875261624) - }; - for (Grad4 grad41 : grad4) { - grad41.dx /= N4; - grad41.dy /= N4; - grad41.dz /= N4; - grad41.dw /= N4; - } - for (int i = 0; i < PSIZE; i++) { - GRADIENTS_4D[i] = grad4[i % grad4.length]; - } - } -} diff --git a/src/main/java/monkstone/noise/Noise.java b/src/main/java/monkstone/noise/Noise.java deleted file mode 100644 index fe1bad3..0000000 --- a/src/main/java/monkstone/noise/Noise.java +++ /dev/null @@ -1,90 +0,0 @@ -package monkstone.noise; - -/* - * Copyright (c) 2021 Martin Prout - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 3.0 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 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 - */ -public interface Noise { - - /** - * - * @param x - * @return - */ - default float noise(float x) { - return noise(x, 0); - } - - /** - * - * @param x - * @param y - * @return - */ - default float noise(float x, float y) { - return noise(x, y, 0); - } - - /** - *

- * Returns the Perlin noise value at specified coordinates. Perlin noise is - * a random sequence generator producing a more natural ordered, harmonic - * succession of numbers compared to the standard random() function. - * It was invented by Ken Perlin in the 1980s and been used since in - * graphical applications to produce procedural textures, natural motion, - * shapes, terrains etc. The main difference to the - * random() function is that Perlin noise is defined in an infinite - * n-dimensional space where each pair of coordinates corresponds to a fixed - * semi-random value (fixed only for the lifespan of the program). The - * resulting value will always be between 0.0 and 1.0. Processing can - * compute 1D, 2D and 3D noise, depending on the number of coordinates - * given. The noise value can be animated by moving through the noise space - * as demonstrated in the example above. The 2nd and 3rd dimension can also - * be interpreted as time.The actual noise is structured similar to an audio - * signal, in respect to the function's use of frequencies. Similar to the - * concept of harmonics in physics, perlin noise is computed over several - * octaves which are added together for the final result. Another way to - * adjust the character of the resulting sequence is the scale of the input - * coordinates. As the function works within an infinite space the value of - * the coordinates doesn't matter as such, only the distance between - * successive coordinates does (eg. when using noise() within a - * loop). As a general rule the smaller the difference between coordinates, - * the smoother the resulting noise sequence will be. Steps of 0.005-0.03 - * work best for most applications, but this will differ depending on use. - *

- * @param x x-coordinate in noise space - * @param y y-coordinate in noise space - * @param z z-coordinate in noise space - * @return - */ - float noise(float x, float y, float z); - - float noise(float x, float y, float z, float w); - - void noiseMode(NoiseMode mode); - - /** - * Sets the seed value for noise().By default, noise() - * produces different results each time the program is run. Set the - * value parameter to a constant to return the same pseudo-random - * numbers each time the software is run. - * - * @param seed - */ - void noiseSeed(long seed); -} diff --git a/src/main/java/monkstone/noise/NoiseGenerator.java b/src/main/java/monkstone/noise/NoiseGenerator.java deleted file mode 100644 index 21edc95..0000000 --- a/src/main/java/monkstone/noise/NoiseGenerator.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package monkstone.noise; - -/** - * - * @author Martin Prout - */ -public class NoiseGenerator implements Noise { - - private Noise implementation; - private NoiseMode mode; - private Long seed; - - public NoiseGenerator() { - seed = System.currentTimeMillis(); - this.implementation = new OpenSimplex2F(seed); - this.mode = NoiseMode.DEFAULT; - } - - @Override - public void noiseMode(NoiseMode mode) { - switch (mode) { - case DEFAULT: - if (this.mode != NoiseMode.DEFAULT) { - this.implementation = new OpenSimplex2F(seed); - this.mode = NoiseMode.DEFAULT; - } - break; - case OPEN_SMOOTH: - if (this.mode != NoiseMode.OPEN_SMOOTH) { - this.implementation = new OpenSimplex2S(seed); - this.mode = NoiseMode.OPEN_SMOOTH; - break; - } - case SMOOTH_TERRAIN: - if (this.mode != NoiseMode.SMOOTH_TERRAIN) { - this.implementation = new SmoothTerrain(seed); - this.mode = NoiseMode.SMOOTH_TERRAIN; - } - break; - case FAST_TERRAIN: - if (this.mode != NoiseMode.FAST_TERRAIN) { - this.implementation = new FastTerrain(seed); - this.mode = NoiseMode.FAST_TERRAIN; - } - break; - default: - this.implementation = new OpenSimplex2F(seed); - this.mode = NoiseMode.DEFAULT; - } - } - - public NoiseMode noiseMode() { - return this.mode; - } - - @Override - public float noise(float x, float y, float z) { - return implementation.noise(x, y, z); - } - - @Override - public float noise(float x, float y, float z, float w) { - return implementation.noise(x, y, z, w); - } - - @Override - public void noiseSeed(long seed) { - this.seed = seed; - } -} diff --git a/src/main/java/monkstone/noise/NoiseMode.java b/src/main/java/monkstone/noise/NoiseMode.java deleted file mode 100644 index 66a8786..0000000 --- a/src/main/java/monkstone/noise/NoiseMode.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package monkstone.noise; - -/** - * - * @author tux - */ -public enum NoiseMode { - DEFAULT("Fast OpenSimplex2"), - FAST_TERRAIN("Fast Terrain"), - SMOOTH_TERRAIN("Smooth Terrain"), - OPEN_SMOOTH("Smooth OpenSimplex2"); - - private final String description; - - NoiseMode(String description) { - this.description = description; - } - - public String description() { - return description; - } - -} diff --git a/src/main/java/monkstone/noise/OpenSimplex2F.java b/src/main/java/monkstone/noise/OpenSimplex2F.java index c59bf20..805205f 100644 --- a/src/main/java/monkstone/noise/OpenSimplex2F.java +++ b/src/main/java/monkstone/noise/OpenSimplex2F.java @@ -1,881 +1,813 @@ package monkstone.noise; - /** * K.jpg's OpenSimplex 2, faster variant * - * - 2D is standard simplex implemented using a lookup table. - 3D is - * "Re-oriented 4-point BCC noise" which constructs a congruent BCC lattice in a - * much different way than usual. - 4D constructs the lattice as a union of five - * copies of its reciprocal. It successively finds the closest point on each. + * - 2D is standard simplex implemented using a lookup table. + * - 3D is "Re-oriented 4-point BCC noise" which constructs a + * congruent BCC lattice in a much different way than usual. + * - 4D constructs the lattice as a union of five copies of its + * reciprocal. It successively finds the closest point on each. * - * Multiple versions of each function are provided. See the documentation above - * each, for more info. + * Multiple versions of each function are provided. See the + * documentation above each, for more info. */ -public class OpenSimplex2F implements Noise { +public class OpenSimplex2F { - private static final int PSIZE = 2048; - private static final int PMASK = 2047; + private static final int PSIZE = 2048; + private static final int PMASK = 2047; - private final short[] perm; - private final Grad2[] permGrad2; - private final Grad3[] permGrad3; - private final Grad4[] permGrad4; + private final short[] perm; + private final Grad2[] permGrad2; + private final Grad3[] permGrad3; + private final Grad4[] permGrad4; - public OpenSimplex2F(long seed) { - perm = new short[PSIZE]; - permGrad2 = new Grad2[PSIZE]; - permGrad3 = new Grad3[PSIZE]; - permGrad4 = new Grad4[PSIZE]; - short[] source = new short[PSIZE]; - for (short i = 0; i < PSIZE; i++) { - source[i] = i; - } - for (int i = PSIZE - 1; i >= 0; i--) { - seed = seed * 6364136223846793005L + 1442695040888963407L; - int r = (int) ((seed + 31) % (i + 1)); - if (r < 0) { - r += (i + 1); - } - perm[i] = source[r]; - permGrad2[i] = GRADIENTS_2D[perm[i]]; - permGrad3[i] = GRADIENTS_3D[perm[i]]; - permGrad4[i] = GRADIENTS_4D[perm[i]]; - source[r] = source[i]; - } - } - - /* - * Noise Evaluators - */ /** - * 2D Simplex noise, standard lattice orientation. * + * @param seed + */ + public OpenSimplex2F(long seed) { + perm = new short[PSIZE]; + permGrad2 = new Grad2[PSIZE]; + permGrad3 = new Grad3[PSIZE]; + permGrad4 = new Grad4[PSIZE]; + short[] source = new short[PSIZE]; + for (short i = 0; i < PSIZE; i++) + source[i] = i; + for (int i = PSIZE - 1; i >= 0; i--) { + seed = seed * 6364136223846793005L + 1442695040888963407L; + int r = (int)((seed + 31) % (i + 1)); + if (r < 0) + r += (i + 1); + perm[i] = source[r]; + permGrad2[i] = GRADIENTS_2D[perm[i]]; + permGrad3[i] = GRADIENTS_3D[perm[i]]; + permGrad4[i] = GRADIENTS_4D[perm[i]]; + source[r] = source[i]; + } + } + + /* + * Noise Evaluators + */ + + /** + * 2D Simplex noise, standard lattice orientation. * @param x * @param y - * @return - */ - public double noise2(double x, double y) { + * @return + */ + public double noise2(double x, double y) { - // Get points for A2* lattice - double s = 0.366025403784439 * (x + y); - double xs = x + s, ys = y + s; + // Get points for A2* lattice + double s = 0.366025403784439 * (x + y); + double xs = x + s, ys = y + s; - return noise2_Base(xs, ys); - } + return noise2_Base(xs, ys); + } - /** - * 2D Simplex noise, with Y pointing down the main diagonal.Might be better - * for a 2D sandbox style game, where Y is vertical.Probably slightly less - * optimal for heightmaps or continent maps. - * + /** + * 2D Simplex noise, with Y pointing down the main diagonal.Might be better for a 2D sandbox style game, where Y is vertical.Probably slightly less optimal for heightmaps or continent maps. * @param x * @param y - * @return - */ - public double noise2_XBeforeY(double x, double y) { + * @return + */ + public double noise2_XBeforeY(double x, double y) { - // Skew transform and rotation baked into one. - double xx = x * 0.7071067811865476; - double yy = y * 1.224744871380249; + // Skew transform and rotation baked into one. + double xx = x * 0.7071067811865476; + double yy = y * 1.224744871380249; - return noise2_Base(yy + xx, yy - xx); - } + return noise2_Base(yy + xx, yy - xx); + } - /** - * 2D Simplex noise base. Lookup table implementation inspired by - * DigitalShadow. - */ - private double noise2_Base(double xs, double ys) { - double value = 0; + /** + * 2D Simplex noise base. + * Lookup table implementation inspired by DigitalShadow. + */ + private double noise2_Base(double xs, double ys) { + double value = 0; - // Get base points and offsets - int xsb = fastFloor(xs), ysb = fastFloor(ys); - double xsi = xs - xsb, ysi = ys - ysb; + // Get base points and offsets + int xsb = fastFloor(xs), ysb = fastFloor(ys); + double xsi = xs - xsb, ysi = ys - ysb; - // Index to point list - int index = (int) ((ysi - xsi) / 2 + 1); + // Index to point list + int index = (int)((ysi - xsi) / 2 + 1); - double ssi = (xsi + ysi) * -0.211324865405187; - double xi = xsi + ssi, yi = ysi + ssi; + double ssi = (xsi + ysi) * -0.211324865405187; + double xi = xsi + ssi, yi = ysi + ssi; - // Point contributions - for (int i = 0; i < 3; i++) { - LatticePoint2D c = LOOKUP_2D[index + i]; + // Point contributions + for (int i = 0; i < 3; i++) { + LatticePoint2D c = LOOKUP_2D[index + i]; - double dx = xi + c.dx, dy = yi + c.dy; - double attn = 0.5 - dx * dx - dy * dy; - if (attn <= 0) { - continue; - } + double dx = xi + c.dx, dy = yi + c.dy; + double attn = 0.5 - dx * dx - dy * dy; + if (attn <= 0) continue; - int pxm = (xsb + c.xsv) & PMASK, pym = (ysb + c.ysv) & PMASK; - Grad2 grad = permGrad2[perm[pxm] ^ pym]; - double extrapolation = grad.dx * dx + grad.dy * dy; + int pxm = (xsb + c.xsv) & PMASK, pym = (ysb + c.ysv) & PMASK; + Grad2 grad = permGrad2[perm[pxm] ^ pym]; + double extrapolation = grad.dx * dx + grad.dy * dy; - attn *= attn; - value += attn * attn * extrapolation; - } + attn *= attn; + value += attn * attn * extrapolation; + } - return value; - } + return value; + } - /** - * 3D Re-oriented 4-point BCC noise, classic orientation.Proper substitute - * for 3D Simplex in light of Forbidden Formulae.Use noise3_XYBeforeZ or - * noise3_XZBeforeY instead, wherever appropriate. - * + /** + * 3D Re-oriented 4-point BCC noise, classic orientation.Proper substitute for 3D Simplex in light of Forbidden Formulae.Use noise3_XYBeforeZ or noise3_XZBeforeY instead, wherever appropriate. * @param x * @param y * @param z - * @return - */ - public double noise3_Classic(double x, double y, double z) { - - // Re-orient the cubic lattices via rotation, to produce the expected look on cardinal planar slices. - // If texturing objects that don't tend to have cardinal plane faces, you could even remove this. - // Orthonormal rotation. Not a skew transform. - double r = (2.0 / 3.0) * (x + y + z); - double xr = r - x, yr = r - y, zr = r - z; - - // Evaluate both lattices to form a BCC lattice. - return noise3_BCC(xr, yr, zr); - } - - /** - * 3D Re-oriented 4-point BCC noise, with better visual isotropy in (X, - * Z).Recommended for 3D terrain and time-varied animations.The Y coordinate - * should always be the "different" coordinate in your use case.If Y is - * vertical in world coordinates, call noise3_XZBeforeY(x, Y, z).If Z is - * vertical in world coordinates, call noise3_XZBeforeY(x, Z, y) or use - * noise3_XYBeforeZ. For a time varied animation, call noise3_XZBeforeY(x, - * T, y) or use noise3_XYBeforeZ. - * + * @return + */ + public double noise3_Classic(double x, double y, double z) { + + // Re-orient the cubic lattices via rotation, to produce the expected look on cardinal planar slices. + // If texturing objects that don't tend to have cardinal plane faces, you could even remove this. + // Orthonormal rotation. Not a skew transform. + double r = (2.0 / 3.0) * (x + y + z); + double xr = r - x, yr = r - y, zr = r - z; + + // Evaluate both lattices to form a BCC lattice. + return noise3_BCC(xr, yr, zr); + } + + /** + * 3D Re-oriented 4-point BCC noise, with better visual isotropy in (X, Y).Recommended for 3D terrain and time-varied animations.The Z coordinate should always be the "different" coordinate in your use case.If Y is vertical in world coordinates, call noise3_XYBeforeZ(x, z, Y) or use noise3_XZBeforeY.If Z is vertical in world coordinates, call noise3_XYBeforeZ(x, y, Z). + * For a time varied animation, call noise3_XYBeforeZ(x, y, T). * @param x * @param y * @param z - * @return - */ - public double noise3_XZBeforeY(double x, double y, double z) { - - // Re-orient the cubic lattices without skewing, to make X and Z triangular like 2D. - // Orthonormal rotation. Not a skew transform. - double xz = x + z; - double s2 = xz * -0.211324865405187; - double yy = y * 0.577350269189626; - double xr = x + s2 - yy; - double zr = z + s2 - yy; - double yr = xz * 0.577350269189626 + yy; + * @return + */ + public double noise3_XYBeforeZ(double x, double y, double z) { + + // Re-orient the cubic lattices without skewing, to make X and Y triangular like 2D. + // Orthonormal rotation. Not a skew transform. + double xy = x + y; + double s2 = xy * -0.211324865405187; + double zz = z * 0.577350269189626; + double xr = x + s2 - zz, yr = y + s2 - zz; + double zr = xy * 0.577350269189626 + zz; + + // Evaluate both lattices to form a BCC lattice. + return noise3_BCC(xr, yr, zr); + } + + /** + * 3D Re-oriented 4-point BCC noise, with better visual isotropy in (X, Z).Recommended for 3D terrain and time-varied animations.The Y coordinate should always be the "different" coordinate in your use case.If Y is vertical in world coordinates, call noise3_XZBeforeY(x, Y, z).If Z is vertical in world coordinates, call noise3_XZBeforeY(x, Z, y) or use noise3_XYBeforeZ. + * For a time varied animation, call noise3_XZBeforeY(x, T, y) or use noise3_XYBeforeZ. + * @param x + * @param y + * @param z + * @return + */ + public double noise3_XZBeforeY(double x, double y, double z) { + + // Re-orient the cubic lattices without skewing, to make X and Z triangular like 2D. + // Orthonormal rotation. Not a skew transform. + double xz = x + z; + double s2 = xz * -0.211324865405187; + double yy = y * 0.577350269189626; + double xr = x + s2 - yy; double zr = z + s2 - yy; + double yr = xz * 0.577350269189626 + yy; + + // Evaluate both lattices to form a BCC lattice. + return noise3_BCC(xr, yr, zr); + } + + /** + * Generate overlapping cubic lattices for 3D Re-oriented BCC noise. + * Lookup table implementation inspired by DigitalShadow. + * It was actually faster to narrow down the points in the loop itself, + * than to build up the index with enough info to isolate 4 points. + */ + private double noise3_BCC(double xr, double yr, double zr) { + + // Get base and offsets inside cube of first lattice. + int xrb = fastFloor(xr), yrb = fastFloor(yr), zrb = fastFloor(zr); + double xri = xr - xrb, yri = yr - yrb, zri = zr - zrb; + + // Identify which octant of the cube we're in. This determines which cell + // in the other cubic lattice we're in, and also narrows down one point on each. + int xht = (int)(xri + 0.5), yht = (int)(yri + 0.5), zht = (int)(zri + 0.5); + int index = (xht) | (yht << 1) | (zht << 2); + + // Point contributions + double value = 0; + LatticePoint3D c = LOOKUP_3D[index]; + while (c != null) { + double dxr = xri + c.dxr, dyr = yri + c.dyr, dzr = zri + c.dzr; + double attn = 0.5 - dxr * dxr - dyr * dyr - dzr * dzr; + if (attn < 0) { + c = c.nextOnFailure; + } else { + int pxm = (xrb + c.xrv) & PMASK, pym = (yrb + c.yrv) & PMASK, pzm = (zrb + c.zrv) & PMASK; + Grad3 grad = permGrad3[perm[perm[pxm] ^ pym] ^ pzm]; + double extrapolation = grad.dx * dxr + grad.dy * dyr + grad.dz * dzr; + + attn *= attn; + value += attn * attn * extrapolation; + c = c.nextOnSuccess; + } + } + return value; + } + + /** + * 4D OpenSimplex2F noise, classic lattice orientation. + * @param x + * @param y + * @param w + * @param z + * @return + */ + public double noise4_Classic(double x, double y, double z, double w) { - // Evaluate both lattices to form a BCC lattice. - return noise3_BCC(xr, yr, zr); - } + // Get points for A4 lattice + double s = -0.138196601125011 * (x + y + z + w); + double xs = x + s, ys = y + s, zs = z + s, ws = w + s; - /** - * Generate overlapping cubic lattices for 3D Re-oriented BCC noise. Lookup - * table implementation inspired by DigitalShadow. It was actually faster to - * narrow down the points in the loop itself, than to build up the index - * with enough info to isolate 4 points. - */ - private double noise3_BCC(double xr, double yr, double zr) { - - // Get base and offsets inside cube of first lattice. - int xrb = fastFloor(xr), yrb = fastFloor(yr), zrb = fastFloor(zr); - double xri = xr - xrb, yri = yr - yrb, zri = zr - zrb; - - // Identify which octant of the cube we're in. This determines which cell - // in the other cubic lattice we're in, and also narrows down one point on each. - int xht = (int) (xri + 0.5), yht = (int) (yri + 0.5), zht = (int) (zri + 0.5); - int index = (xht) | (yht << 1) | (zht << 2); - - // Point contributions - double value = 0; - LatticePoint3D c = LOOKUP_3D[index]; - while (c != null) { - double dxr = xri + c.dxr, dyr = yri + c.dyr, dzr = zri + c.dzr; - double attn = 0.5 - dxr * dxr - dyr * dyr - dzr * dzr; - if (attn < 0) { - c = c.nextOnFailure; - } else { - int pxm = (xrb + c.xrv) & PMASK, pym = (yrb + c.yrv) & PMASK, pzm = (zrb + c.zrv) & PMASK; - Grad3 grad = permGrad3[perm[perm[pxm] ^ pym] ^ pzm]; - double extrapolation = grad.dx * dxr + grad.dy * dyr + grad.dz * dzr; - - attn *= attn; - value += attn * attn * extrapolation; - c = c.nextOnSuccess; - } - } - return value; - } + return noise4_Base(xs, ys, zs, ws); + } - /** - * 4D OpenSimplex2F noise, classic lattice orientation. - * + /** + * 4D OpenSimplex2F noise, with XY and ZW forming orthogonal triangular-based planes.Recommended for 3D terrain, where X and Y (or Z and W) are horizontal.Recommended for noise(x, y, sin(time), cos(time)) trick. * @param x - * @param y * @param z + * @param y * @param w - * @return - */ - public double noise4_Classic(double x, double y, double z, double w) { + * @return + */ + public double noise4_XYBeforeZW(double x, double y, double z, double w) { - // Get points for A4 lattice - double s = -0.138196601125011 * (x + y + z + w); - double xs = x + s, ys = y + s, zs = z + s, ws = w + s; + double s2 = (x + y) * -0.178275657951399372 + (z + w) * 0.215623393288842828; + double t2 = (z + w) * -0.403949762580207112 + (x + y) * -0.375199083010075342; + double xs = x + s2, ys = y + s2, zs = z + t2, ws = w + t2; - return noise4_Base(xs, ys, zs, ws); - } + return noise4_Base(xs, ys, zs, ws); + } - /** - * 4D OpenSimplex2F noise, with XY and ZW forming orthogonal - * triangular-based planes.Recommended for 3D terrain, where X and Y (or Z - * and W) are horizontal.Recommended for noise(x, y, sin(time), cos(time)) - * trick. - * + /** + * 4D OpenSimplex2F noise, with XZ and YW forming orthogonal triangular-based planes.Recommended for 3D terrain, where X and Z (or Y and W) are horizontal. * @param x - * @param y * @param z + * @param y * @param w - * @return - */ - public double noise4_XYBeforeZW(double x, double y, double z, double w) { + * @return + */ + public double noise4_XZBeforeYW(double x, double y, double z, double w) { - double s2 = (x + y) * -0.178275657951399372 + (z + w) * 0.215623393288842828; - double t2 = (z + w) * -0.403949762580207112 + (x + y) * -0.375199083010075342; - double xs = x + s2, ys = y + s2, zs = z + t2, ws = w + t2; + double s2 = (x + z) * -0.178275657951399372 + (y + w) * 0.215623393288842828; + double t2 = (y + w) * -0.403949762580207112 + (x + z) * -0.375199083010075342; + double xs = x + s2, ys = y + t2, zs = z + s2, ws = w + t2; - return noise4_Base(xs, ys, zs, ws); - } + return noise4_Base(xs, ys, zs, ws); + } - /** - * 4D OpenSimplex2F noise, with XYZ oriented like noise3_Classic, and W for - * an extra degree of freedom.W repeats eventually.Recommended for - * time-varied animations which texture a 3D object (W=time) - * + /** + * 4D OpenSimplex2F noise, with XYZ oriented like noise3_Classic, + * and W for an extra degree of freedom.W repeats eventually.Recommended for time-varied animations which texture a 3D object (W=time) * @param x + * @param w * @param y * @param z - * @param w * @return - */ - public double noise4_XYZBeforeW(double x, double y, double z, double w) { - - double xyz = x + y + z; - double ww = w * 0.2236067977499788; - double s2 = xyz * -0.16666666666666666 + ww; - double xs = x + s2, ys = y + s2, zs = z + s2, ws = -0.5 * xyz + ww; + */ + public double noise4_XYZBeforeW(double x, double y, double z, double w) { + + double xyz = x + y + z; + double ww = w * 0.2236067977499788; + double s2 = xyz * -0.16666666666666666 + ww; + double xs = x + s2, ys = y + s2, zs = z + s2, ws = -0.5 * xyz + ww; + + return noise4_Base(xs, ys, zs, ws); + } + + /** + * 4D OpenSimplex2F noise base. + * Current implementation not fully optimized by lookup tables. + * But still comes out slightly ahead of Gustavson's Simplex in tests. + */ + private double noise4_Base(double xs, double ys, double zs, double ws) { + double value = 0; + + // Get base points and offsets + int xsb = fastFloor(xs), ysb = fastFloor(ys), zsb = fastFloor(zs), wsb = fastFloor(ws); + double xsi = xs - xsb, ysi = ys - ysb, zsi = zs - zsb, wsi = ws - wsb; + + // If we're in the lower half, flip so we can repeat the code for the upper half. We'll flip back later. + double siSum = xsi + ysi + zsi + wsi; + double ssi = siSum * 0.309016994374947; // Prep for vertex contributions. + boolean inLowerHalf = (siSum < 2); + if (inLowerHalf) { + xsi = 1 - xsi; ysi = 1 - ysi; zsi = 1 - zsi; wsi = 1 - wsi; + siSum = 4 - siSum; + } + + // Consider opposing vertex pairs of the octahedron formed by the central cross-section of the stretched tesseract + double aabb = xsi + ysi - zsi - wsi, abab = xsi - ysi + zsi - wsi, abba = xsi - ysi - zsi + wsi; + double aabbScore = Math.abs(aabb), ababScore = Math.abs(abab), abbaScore = Math.abs(abba); + + // Find the closest point on the stretched tesseract as if it were the upper half + int vertexIndex, via, vib; + double asi, bsi; + if (aabbScore > ababScore && aabbScore > abbaScore) { + if (aabb > 0) { + asi = zsi; bsi = wsi; vertexIndex = 0b0011; via = 0b0111; vib = 0b1011; + } else { + asi = xsi; bsi = ysi; vertexIndex = 0b1100; via = 0b1101; vib = 0b1110; + } + } else if (ababScore > abbaScore) { + if (abab > 0) { + asi = ysi; bsi = wsi; vertexIndex = 0b0101; via = 0b0111; vib = 0b1101; + } else { + asi = xsi; bsi = zsi; vertexIndex = 0b1010; via = 0b1011; vib = 0b1110; + } + } else { + if (abba > 0) { + asi = ysi; bsi = zsi; vertexIndex = 0b1001; via = 0b1011; vib = 0b1101; + } else { + asi = xsi; bsi = wsi; vertexIndex = 0b0110; via = 0b0111; vib = 0b1110; + } + } + if (bsi > asi) { + via = vib; + double temp = bsi; + bsi = asi; + asi = temp; + } + if (siSum + asi > 3) { + vertexIndex = via; + if (siSum + bsi > 4) { + vertexIndex = 0b1111; + } + } + + // Now flip back if we're actually in the lower half. + if (inLowerHalf) { + xsi = 1 - xsi; ysi = 1 - ysi; zsi = 1 - zsi; wsi = 1 - wsi; + vertexIndex ^= 0b1111; + } + + // Five points to add, total, from five copies of the A4 lattice. + for (int i = 0; i < 5; i++) { + + // Update xsb/etc. and add the lattice point's contribution. + LatticePoint4D c = VERTICES_4D[vertexIndex]; + xsb += c.xsv; ysb += c.ysv; zsb += c.zsv; wsb += c.wsv; + double xi = xsi + ssi, yi = ysi + ssi, zi = zsi + ssi, wi = wsi + ssi; + double dx = xi + c.dx, dy = yi + c.dy, dz = zi + c.dz, dw = wi + c.dw; + double attn = 0.5 - dx * dx - dy * dy - dz * dz - dw * dw; + if (attn > 0) { + int pxm = xsb & PMASK, pym = ysb & PMASK, pzm = zsb & PMASK, pwm = wsb & PMASK; + Grad4 grad = permGrad4[perm[perm[perm[pxm] ^ pym] ^ pzm] ^ pwm]; + double ramped = grad.dx * dx + grad.dy * dy + grad.dz * dz + grad.dw * dw; + + attn *= attn; + value += attn * attn * ramped; + } + + // Maybe this helps the compiler/JVM/LLVM/etc. know we can end the loop here. Maybe not. + if (i == 4) break; + + // Update the relative skewed coordinates to reference the vertex we just added. + // Rather, reference its counterpart on the lattice copy that is shifted down by + // the vector <-0.2, -0.2, -0.2, -0.2> + xsi += c.xsi; ysi += c.ysi; zsi += c.zsi; wsi += c.wsi; + ssi += c.ssiDelta; + + // Next point is the closest vertex on the 4-simplex whose base vertex is the aforementioned vertex. + double score0 = 1.0 + ssi * (-1.0 / 0.309016994374947); // Seems slightly faster than 1.0-xsi-ysi-zsi-wsi + vertexIndex = 0b0000; + if (xsi >= ysi && xsi >= zsi && xsi >= wsi && xsi >= score0) { + vertexIndex = 0b0001; + } + else if (ysi > xsi && ysi >= zsi && ysi >= wsi && ysi >= score0) { + vertexIndex = 0b0010; + } + else if (zsi > xsi && zsi > ysi && zsi >= wsi && zsi >= score0) { + vertexIndex = 0b0100; + } + else if (wsi > xsi && wsi > ysi && wsi > zsi && wsi >= score0) { + vertexIndex = 0b1000; + } + } + + return value; + } + + /* + * Utility + */ - return noise4_Base(xs, ys, zs, ws); - } + private static int fastFloor(double x) { + int xi = (int)x; + return x < xi ? xi - 1 : xi; + } - /** - * 4D OpenSimplex2F noise base. Current implementation not fully optimized - * by lookup tables. But still comes out slightly ahead of Gustavson's - * Simplex in tests. - */ - private double noise4_Base(double xs, double ys, double zs, double ws) { - double value = 0; - - // Get base points and offsets - int xsb = fastFloor(xs), ysb = fastFloor(ys), zsb = fastFloor(zs), wsb = fastFloor(ws); - double xsi = xs - xsb, ysi = ys - ysb, zsi = zs - zsb, wsi = ws - wsb; - - // If we're in the lower half, flip so we can repeat the code for the upper half. We'll flip back later. - double siSum = xsi + ysi + zsi + wsi; - double ssi = siSum * 0.309016994374947; // Prep for vertex contributions. - boolean inLowerHalf = (siSum < 2); - if (inLowerHalf) { - xsi = 1 - xsi; - ysi = 1 - ysi; - zsi = 1 - zsi; - wsi = 1 - wsi; - siSum = 4 - siSum; - } - - // Consider opposing vertex pairs of the octahedron formed by the central cross-section of the stretched tesseract - double aabb = xsi + ysi - zsi - wsi, abab = xsi - ysi + zsi - wsi, abba = xsi - ysi - zsi + wsi; - double aabbScore = Math.abs(aabb), ababScore = Math.abs(abab), abbaScore = Math.abs(abba); - - // Find the closest point on the stretched tesseract as if it were the upper half - int vertexIndex, via, vib; - double asi, bsi; - if (aabbScore > ababScore && aabbScore > abbaScore) { - if (aabb > 0) { - asi = zsi; - bsi = wsi; - vertexIndex = 0b0011; - via = 0b0111; - vib = 0b1011; - } else { - asi = xsi; - bsi = ysi; - vertexIndex = 0b1100; - via = 0b1101; - vib = 0b1110; - } - } else if (ababScore > abbaScore) { - if (abab > 0) { - asi = ysi; - bsi = wsi; - vertexIndex = 0b0101; - via = 0b0111; - vib = 0b1101; - } else { - asi = xsi; - bsi = zsi; - vertexIndex = 0b1010; - via = 0b1011; - vib = 0b1110; - } - } else { - if (abba > 0) { - asi = ysi; - bsi = zsi; - vertexIndex = 0b1001; - via = 0b1011; - vib = 0b1101; - } else { - asi = xsi; - bsi = wsi; - vertexIndex = 0b0110; - via = 0b0111; - vib = 0b1110; - } - } - if (bsi > asi) { - via = vib; - double temp = bsi; - bsi = asi; - asi = temp; - } - if (siSum + asi > 3) { - vertexIndex = via; - if (siSum + bsi > 4) { - vertexIndex = 0b1111; + /* + * Definitions + */ + + private static final LatticePoint2D[] LOOKUP_2D; + private static final LatticePoint3D[] LOOKUP_3D; + private static final LatticePoint4D[] VERTICES_4D; + static { + LOOKUP_2D = new LatticePoint2D[4]; + LOOKUP_3D = new LatticePoint3D[8]; + VERTICES_4D = new LatticePoint4D[16]; + + LOOKUP_2D[0] = new LatticePoint2D(1, 0); + LOOKUP_2D[1] = new LatticePoint2D(0, 0); + LOOKUP_2D[2] = new LatticePoint2D(1, 1); + LOOKUP_2D[3] = new LatticePoint2D(0, 1); + + for (int i = 0; i < 8; i++) { + int i1, j1, k1, i2, j2, k2; + i1 = (i) & 1; j1 = (i >> 1) & 1; k1 = (i >> 2) & 1; + i2 = i1 ^ 1; j2 = j1 ^ 1; k2 = k1 ^ 1; + + // The two points within this octant, one from each of the two cubic half-lattices. + LatticePoint3D c0 = new LatticePoint3D(i1, j1, k1, 0); + LatticePoint3D c1 = new LatticePoint3D(i1 + i2, j1 + j2, k1 + k2, 1); + + // Each single step away on the first half-lattice. + LatticePoint3D c2 = new LatticePoint3D(i1 ^ 1, j1, k1, 0); + LatticePoint3D c3 = new LatticePoint3D(i1, j1 ^ 1, k1, 0); + LatticePoint3D c4 = new LatticePoint3D(i1, j1, k1 ^ 1, 0); + + // Each single step away on the second half-lattice. + LatticePoint3D c5 = new LatticePoint3D(i1 + (i2 ^ 1), j1 + j2, k1 + k2, 1); + LatticePoint3D c6 = new LatticePoint3D(i1 + i2, j1 + (j2 ^ 1), k1 + k2, 1); + LatticePoint3D c7 = new LatticePoint3D(i1 + i2, j1 + j2, k1 + (k2 ^ 1), 1); + + // First two are guaranteed. + c0.nextOnFailure = c0.nextOnSuccess = c1; + c1.nextOnFailure = c1.nextOnSuccess = c2; + + // Once we find one on the first half-lattice, the rest are out. + // In addition, knowing c2 rules out c5. + c2.nextOnFailure = c3; c2.nextOnSuccess = c6; + c3.nextOnFailure = c4; c3.nextOnSuccess = c5; + c4.nextOnFailure = c4.nextOnSuccess = c5; + + // Once we find one on the second half-lattice, the rest are out. + c5.nextOnFailure = c6; c5.nextOnSuccess = null; + c6.nextOnFailure = c7; c6.nextOnSuccess = null; + c7.nextOnFailure = c7.nextOnSuccess = null; + + LOOKUP_3D[i] = c0; + } + + for (int i = 0; i < 16; i++) { + VERTICES_4D[i] = new LatticePoint4D((i) & 1, (i >> 1) & 1, (i >> 2) & 1, (i >> 3) & 1); + } + } + + private static class LatticePoint2D { + int xsv, ysv; + double dx, dy; + public LatticePoint2D(int xsv, int ysv) { + this.xsv = xsv; this.ysv = ysv; + double ssv = (xsv + ysv) * -0.211324865405187; + this.dx = -xsv - ssv; + this.dy = -ysv - ssv; + } + } + + private static class LatticePoint3D { + public double dxr, dyr, dzr; + public int xrv, yrv, zrv; + LatticePoint3D nextOnFailure, nextOnSuccess; + public LatticePoint3D(int xrv, int yrv, int zrv, int lattice) { + this.dxr = -xrv + lattice * 0.5; this.dyr = -yrv + lattice * 0.5; this.dzr = -zrv + lattice * 0.5; + this.xrv = xrv + lattice * 1024; this.yrv = yrv + lattice * 1024; this.zrv = zrv + lattice * 1024; + } + } + + private static class LatticePoint4D { + int xsv, ysv, zsv, wsv; + double dx, dy, dz, dw; + double xsi, ysi, zsi, wsi; + double ssiDelta; + public LatticePoint4D(int xsv, int ysv, int zsv, int wsv) { + this.xsv = xsv + 409; this.ysv = ysv + 409; this.zsv = zsv + 409; this.wsv = wsv + 409; + double ssv = (xsv + ysv + zsv + wsv) * 0.309016994374947; + this.dx = -xsv - ssv; + this.dy = -ysv - ssv; + this.dz = -zsv - ssv; + this.dw = -wsv - ssv; + this.xsi = xsi = 0.2 - xsv; + this.ysi = ysi = 0.2 - ysv; + this.zsi = zsi = 0.2 - zsv; + this.wsi = wsi = 0.2 - wsv; + this.ssiDelta = (0.8 - xsv - ysv - zsv - wsv) * 0.309016994374947; + } + } + + /* + * Gradients + */ + + private static class Grad2 { + double dx, dy; + public Grad2(double dx, double dy) { + this.dx = dx; this.dy = dy; + } + } + + private static class Grad3 { + double dx, dy, dz; + public Grad3(double dx, double dy, double dz) { + this.dx = dx; this.dy = dy; this.dz = dz; + } + } + + private static class Grad4 { + double dx, dy, dz, dw; + public Grad4(double dx, double dy, double dz, double dw) { + this.dx = dx; this.dy = dy; this.dz = dz; this.dw = dw; + } + } + + private static final double N2 = 0.01001634121365712; + private static final double N3 = 0.030485933181293584; + private static final double N4 = 0.009202377986303158; + private static final Grad2[] GRADIENTS_2D; + private static final Grad3[] GRADIENTS_3D; + private static final Grad4[] GRADIENTS_4D; + static { + + GRADIENTS_2D = new Grad2[PSIZE]; + Grad2[] grad2 = { + new Grad2( 0.130526192220052, 0.99144486137381), + new Grad2( 0.38268343236509, 0.923879532511287), + new Grad2( 0.608761429008721, 0.793353340291235), + new Grad2( 0.793353340291235, 0.608761429008721), + new Grad2( 0.923879532511287, 0.38268343236509), + new Grad2( 0.99144486137381, 0.130526192220051), + new Grad2( 0.99144486137381, -0.130526192220051), + new Grad2( 0.923879532511287, -0.38268343236509), + new Grad2( 0.793353340291235, -0.60876142900872), + new Grad2( 0.608761429008721, -0.793353340291235), + new Grad2( 0.38268343236509, -0.923879532511287), + new Grad2( 0.130526192220052, -0.99144486137381), + new Grad2(-0.130526192220052, -0.99144486137381), + new Grad2(-0.38268343236509, -0.923879532511287), + new Grad2(-0.608761429008721, -0.793353340291235), + new Grad2(-0.793353340291235, -0.608761429008721), + new Grad2(-0.923879532511287, -0.38268343236509), + new Grad2(-0.99144486137381, -0.130526192220052), + new Grad2(-0.99144486137381, 0.130526192220051), + new Grad2(-0.923879532511287, 0.38268343236509), + new Grad2(-0.793353340291235, 0.608761429008721), + new Grad2(-0.608761429008721, 0.793353340291235), + new Grad2(-0.38268343236509, 0.923879532511287), + new Grad2(-0.130526192220052, 0.99144486137381) + }; + for (Grad2 grad21 : grad2) { + grad21.dx /= N2; + grad21.dy /= N2; } - } - - // Now flip back if we're actually in the lower half. - if (inLowerHalf) { - xsi = 1 - xsi; - ysi = 1 - ysi; - zsi = 1 - zsi; - wsi = 1 - wsi; - vertexIndex ^= 0b1111; - } - - // Five points to add, total, from five copies of the A4 lattice. - for (int i = 0; i < 5; i++) { - - // Update xsb/etc. and add the lattice point's contribution. - LatticePoint4D c = VERTICES_4D[vertexIndex]; - xsb += c.xsv; - ysb += c.ysv; - zsb += c.zsv; - wsb += c.wsv; - double xi = xsi + ssi, yi = ysi + ssi, zi = zsi + ssi, wi = wsi + ssi; - double dx = xi + c.dx, dy = yi + c.dy, dz = zi + c.dz, dw = wi + c.dw; - double attn = 0.5 - dx * dx - dy * dy - dz * dz - dw * dw; - if (attn > 0) { - int pxm = xsb & PMASK, pym = ysb & PMASK, pzm = zsb & PMASK, pwm = wsb & PMASK; - Grad4 grad = permGrad4[perm[perm[perm[pxm] ^ pym] ^ pzm] ^ pwm]; - double ramped = grad.dx * dx + grad.dy * dy + grad.dz * dz + grad.dw * dw; - - attn *= attn; - value += attn * attn * ramped; + for (int i = 0; i < PSIZE; i++) { + GRADIENTS_2D[i] = grad2[i % grad2.length]; + } + + GRADIENTS_3D = new Grad3[PSIZE]; + Grad3[] grad3 = { + new Grad3(-2.22474487139, -2.22474487139, -1.0), + new Grad3(-2.22474487139, -2.22474487139, 1.0), + new Grad3(-3.0862664687972017, -1.1721513422464978, 0.0), + new Grad3(-1.1721513422464978, -3.0862664687972017, 0.0), + new Grad3(-2.22474487139, -1.0, -2.22474487139), + new Grad3(-2.22474487139, 1.0, -2.22474487139), + new Grad3(-1.1721513422464978, 0.0, -3.0862664687972017), + new Grad3(-3.0862664687972017, 0.0, -1.1721513422464978), + new Grad3(-2.22474487139, -1.0, 2.22474487139), + new Grad3(-2.22474487139, 1.0, 2.22474487139), + new Grad3(-3.0862664687972017, 0.0, 1.1721513422464978), + new Grad3(-1.1721513422464978, 0.0, 3.0862664687972017), + new Grad3(-2.22474487139, 2.22474487139, -1.0), + new Grad3(-2.22474487139, 2.22474487139, 1.0), + new Grad3(-1.1721513422464978, 3.0862664687972017, 0.0), + new Grad3(-3.0862664687972017, 1.1721513422464978, 0.0), + new Grad3(-1.0, -2.22474487139, -2.22474487139), + new Grad3( 1.0, -2.22474487139, -2.22474487139), + new Grad3( 0.0, -3.0862664687972017, -1.1721513422464978), + new Grad3( 0.0, -1.1721513422464978, -3.0862664687972017), + new Grad3(-1.0, -2.22474487139, 2.22474487139), + new Grad3( 1.0, -2.22474487139, 2.22474487139), + new Grad3( 0.0, -1.1721513422464978, 3.0862664687972017), + new Grad3( 0.0, -3.0862664687972017, 1.1721513422464978), + new Grad3(-1.0, 2.22474487139, -2.22474487139), + new Grad3( 1.0, 2.22474487139, -2.22474487139), + new Grad3( 0.0, 1.1721513422464978, -3.0862664687972017), + new Grad3( 0.0, 3.0862664687972017, -1.1721513422464978), + new Grad3(-1.0, 2.22474487139, 2.22474487139), + new Grad3( 1.0, 2.22474487139, 2.22474487139), + new Grad3( 0.0, 3.0862664687972017, 1.1721513422464978), + new Grad3( 0.0, 1.1721513422464978, 3.0862664687972017), + new Grad3( 2.22474487139, -2.22474487139, -1.0), + new Grad3( 2.22474487139, -2.22474487139, 1.0), + new Grad3( 1.1721513422464978, -3.0862664687972017, 0.0), + new Grad3( 3.0862664687972017, -1.1721513422464978, 0.0), + new Grad3( 2.22474487139, -1.0, -2.22474487139), + new Grad3( 2.22474487139, 1.0, -2.22474487139), + new Grad3( 3.0862664687972017, 0.0, -1.1721513422464978), + new Grad3( 1.1721513422464978, 0.0, -3.0862664687972017), + new Grad3( 2.22474487139, -1.0, 2.22474487139), + new Grad3( 2.22474487139, 1.0, 2.22474487139), + new Grad3( 1.1721513422464978, 0.0, 3.0862664687972017), + new Grad3( 3.0862664687972017, 0.0, 1.1721513422464978), + new Grad3( 2.22474487139, 2.22474487139, -1.0), + new Grad3( 2.22474487139, 2.22474487139, 1.0), + new Grad3( 3.0862664687972017, 1.1721513422464978, 0.0), + new Grad3( 1.1721513422464978, 3.0862664687972017, 0.0) + }; + for (Grad3 grad31 : grad3) { + grad31.dx /= N3; + grad31.dy /= N3; + grad31.dz /= N3; } - - // Maybe this helps the compiler/JVM/LLVM/etc. know we can end the loop here. Maybe not. - if (i == 4) { - break; - } - - // Update the relative skewed coordinates to reference the vertex we just added. - // Rather, reference its counterpart on the lattice copy that is shifted down by - // the vector <-0.2, -0.2, -0.2, -0.2> - xsi += c.xsi; - ysi += c.ysi; - zsi += c.zsi; - wsi += c.wsi; - ssi += c.ssiDelta; - - // Next point is the closest vertex on the 4-simplex whose base vertex is the aforementioned vertex. - double score0 = 1.0 + ssi * (-1.0 / 0.309016994374947); // Seems slightly faster than 1.0-xsi-ysi-zsi-wsi - vertexIndex = 0b0000; - if (xsi >= ysi && xsi >= zsi && xsi >= wsi && xsi >= score0) { - vertexIndex = 0b0001; - } else if (ysi > xsi && ysi >= zsi && ysi >= wsi && ysi >= score0) { - vertexIndex = 0b0010; - } else if (zsi > xsi && zsi > ysi && zsi >= wsi && zsi >= score0) { - vertexIndex = 0b0100; - } else if (wsi > xsi && wsi > ysi && wsi > zsi && wsi >= score0) { - vertexIndex = 0b1000; + for (int i = 0; i < PSIZE; i++) { + GRADIENTS_3D[i] = grad3[i % grad3.length]; + } + + GRADIENTS_4D = new Grad4[PSIZE]; + Grad4[] grad4 = { + new Grad4(-0.753341017856078, -0.37968289875261624, -0.37968289875261624, -0.37968289875261624), + new Grad4(-0.7821684431180708, -0.4321472685365301, -0.4321472685365301, 0.12128480194602098), + new Grad4(-0.7821684431180708, -0.4321472685365301, 0.12128480194602098, -0.4321472685365301), + new Grad4(-0.7821684431180708, 0.12128480194602098, -0.4321472685365301, -0.4321472685365301), + new Grad4(-0.8586508742123365, -0.508629699630796, 0.044802370851755174, 0.044802370851755174), + new Grad4(-0.8586508742123365, 0.044802370851755174, -0.508629699630796, 0.044802370851755174), + new Grad4(-0.8586508742123365, 0.044802370851755174, 0.044802370851755174, -0.508629699630796), + new Grad4(-0.9982828964265062, -0.03381941603233842, -0.03381941603233842, -0.03381941603233842), + new Grad4(-0.37968289875261624, -0.753341017856078, -0.37968289875261624, -0.37968289875261624), + new Grad4(-0.4321472685365301, -0.7821684431180708, -0.4321472685365301, 0.12128480194602098), + new Grad4(-0.4321472685365301, -0.7821684431180708, 0.12128480194602098, -0.4321472685365301), + new Grad4( 0.12128480194602098, -0.7821684431180708, -0.4321472685365301, -0.4321472685365301), + new Grad4(-0.508629699630796, -0.8586508742123365, 0.044802370851755174, 0.044802370851755174), + new Grad4( 0.044802370851755174, -0.8586508742123365, -0.508629699630796, 0.044802370851755174), + new Grad4( 0.044802370851755174, -0.8586508742123365, 0.044802370851755174, -0.508629699630796), + new Grad4(-0.03381941603233842, -0.9982828964265062, -0.03381941603233842, -0.03381941603233842), + new Grad4(-0.37968289875261624, -0.37968289875261624, -0.753341017856078, -0.37968289875261624), + new Grad4(-0.4321472685365301, -0.4321472685365301, -0.7821684431180708, 0.12128480194602098), + new Grad4(-0.4321472685365301, 0.12128480194602098, -0.7821684431180708, -0.4321472685365301), + new Grad4( 0.12128480194602098, -0.4321472685365301, -0.7821684431180708, -0.4321472685365301), + new Grad4(-0.508629699630796, 0.044802370851755174, -0.8586508742123365, 0.044802370851755174), + new Grad4( 0.044802370851755174, -0.508629699630796, -0.8586508742123365, 0.044802370851755174), + new Grad4( 0.044802370851755174, 0.044802370851755174, -0.8586508742123365, -0.508629699630796), + new Grad4(-0.03381941603233842, -0.03381941603233842, -0.9982828964265062, -0.03381941603233842), + new Grad4(-0.37968289875261624, -0.37968289875261624, -0.37968289875261624, -0.753341017856078), + new Grad4(-0.4321472685365301, -0.4321472685365301, 0.12128480194602098, -0.7821684431180708), + new Grad4(-0.4321472685365301, 0.12128480194602098, -0.4321472685365301, -0.7821684431180708), + new Grad4( 0.12128480194602098, -0.4321472685365301, -0.4321472685365301, -0.7821684431180708), + new Grad4(-0.508629699630796, 0.044802370851755174, 0.044802370851755174, -0.8586508742123365), + new Grad4( 0.044802370851755174, -0.508629699630796, 0.044802370851755174, -0.8586508742123365), + new Grad4( 0.044802370851755174, 0.044802370851755174, -0.508629699630796, -0.8586508742123365), + new Grad4(-0.03381941603233842, -0.03381941603233842, -0.03381941603233842, -0.9982828964265062), + new Grad4(-0.6740059517812944, -0.3239847771997537, -0.3239847771997537, 0.5794684678643381), + new Grad4(-0.7504883828755602, -0.4004672082940195, 0.15296486218853164, 0.5029860367700724), + new Grad4(-0.7504883828755602, 0.15296486218853164, -0.4004672082940195, 0.5029860367700724), + new Grad4(-0.8828161875373585, 0.08164729285680945, 0.08164729285680945, 0.4553054119602712), + new Grad4(-0.4553054119602712, -0.08164729285680945, -0.08164729285680945, 0.8828161875373585), + new Grad4(-0.5029860367700724, -0.15296486218853164, 0.4004672082940195, 0.7504883828755602), + new Grad4(-0.5029860367700724, 0.4004672082940195, -0.15296486218853164, 0.7504883828755602), + new Grad4(-0.5794684678643381, 0.3239847771997537, 0.3239847771997537, 0.6740059517812944), + new Grad4(-0.3239847771997537, -0.6740059517812944, -0.3239847771997537, 0.5794684678643381), + new Grad4(-0.4004672082940195, -0.7504883828755602, 0.15296486218853164, 0.5029860367700724), + new Grad4( 0.15296486218853164, -0.7504883828755602, -0.4004672082940195, 0.5029860367700724), + new Grad4( 0.08164729285680945, -0.8828161875373585, 0.08164729285680945, 0.4553054119602712), + new Grad4(-0.08164729285680945, -0.4553054119602712, -0.08164729285680945, 0.8828161875373585), + new Grad4(-0.15296486218853164, -0.5029860367700724, 0.4004672082940195, 0.7504883828755602), + new Grad4( 0.4004672082940195, -0.5029860367700724, -0.15296486218853164, 0.7504883828755602), + new Grad4( 0.3239847771997537, -0.5794684678643381, 0.3239847771997537, 0.6740059517812944), + new Grad4(-0.3239847771997537, -0.3239847771997537, -0.6740059517812944, 0.5794684678643381), + new Grad4(-0.4004672082940195, 0.15296486218853164, -0.7504883828755602, 0.5029860367700724), + new Grad4( 0.15296486218853164, -0.4004672082940195, -0.7504883828755602, 0.5029860367700724), + new Grad4( 0.08164729285680945, 0.08164729285680945, -0.8828161875373585, 0.4553054119602712), + new Grad4(-0.08164729285680945, -0.08164729285680945, -0.4553054119602712, 0.8828161875373585), + new Grad4(-0.15296486218853164, 0.4004672082940195, -0.5029860367700724, 0.7504883828755602), + new Grad4( 0.4004672082940195, -0.15296486218853164, -0.5029860367700724, 0.7504883828755602), + new Grad4( 0.3239847771997537, 0.3239847771997537, -0.5794684678643381, 0.6740059517812944), + new Grad4(-0.6740059517812944, -0.3239847771997537, 0.5794684678643381, -0.3239847771997537), + new Grad4(-0.7504883828755602, -0.4004672082940195, 0.5029860367700724, 0.15296486218853164), + new Grad4(-0.7504883828755602, 0.15296486218853164, 0.5029860367700724, -0.4004672082940195), + new Grad4(-0.8828161875373585, 0.08164729285680945, 0.4553054119602712, 0.08164729285680945), + new Grad4(-0.4553054119602712, -0.08164729285680945, 0.8828161875373585, -0.08164729285680945), + new Grad4(-0.5029860367700724, -0.15296486218853164, 0.7504883828755602, 0.4004672082940195), + new Grad4(-0.5029860367700724, 0.4004672082940195, 0.7504883828755602, -0.15296486218853164), + new Grad4(-0.5794684678643381, 0.3239847771997537, 0.6740059517812944, 0.3239847771997537), + new Grad4(-0.3239847771997537, -0.6740059517812944, 0.5794684678643381, -0.3239847771997537), + new Grad4(-0.4004672082940195, -0.7504883828755602, 0.5029860367700724, 0.15296486218853164), + new Grad4( 0.15296486218853164, -0.7504883828755602, 0.5029860367700724, -0.4004672082940195), + new Grad4( 0.08164729285680945, -0.8828161875373585, 0.4553054119602712, 0.08164729285680945), + new Grad4(-0.08164729285680945, -0.4553054119602712, 0.8828161875373585, -0.08164729285680945), + new Grad4(-0.15296486218853164, -0.5029860367700724, 0.7504883828755602, 0.4004672082940195), + new Grad4( 0.4004672082940195, -0.5029860367700724, 0.7504883828755602, -0.15296486218853164), + new Grad4( 0.3239847771997537, -0.5794684678643381, 0.6740059517812944, 0.3239847771997537), + new Grad4(-0.3239847771997537, -0.3239847771997537, 0.5794684678643381, -0.6740059517812944), + new Grad4(-0.4004672082940195, 0.15296486218853164, 0.5029860367700724, -0.7504883828755602), + new Grad4( 0.15296486218853164, -0.4004672082940195, 0.5029860367700724, -0.7504883828755602), + new Grad4( 0.08164729285680945, 0.08164729285680945, 0.4553054119602712, -0.8828161875373585), + new Grad4(-0.08164729285680945, -0.08164729285680945, 0.8828161875373585, -0.4553054119602712), + new Grad4(-0.15296486218853164, 0.4004672082940195, 0.7504883828755602, -0.5029860367700724), + new Grad4( 0.4004672082940195, -0.15296486218853164, 0.7504883828755602, -0.5029860367700724), + new Grad4( 0.3239847771997537, 0.3239847771997537, 0.6740059517812944, -0.5794684678643381), + new Grad4(-0.6740059517812944, 0.5794684678643381, -0.3239847771997537, -0.3239847771997537), + new Grad4(-0.7504883828755602, 0.5029860367700724, -0.4004672082940195, 0.15296486218853164), + new Grad4(-0.7504883828755602, 0.5029860367700724, 0.15296486218853164, -0.4004672082940195), + new Grad4(-0.8828161875373585, 0.4553054119602712, 0.08164729285680945, 0.08164729285680945), + new Grad4(-0.4553054119602712, 0.8828161875373585, -0.08164729285680945, -0.08164729285680945), + new Grad4(-0.5029860367700724, 0.7504883828755602, -0.15296486218853164, 0.4004672082940195), + new Grad4(-0.5029860367700724, 0.7504883828755602, 0.4004672082940195, -0.15296486218853164), + new Grad4(-0.5794684678643381, 0.6740059517812944, 0.3239847771997537, 0.3239847771997537), + new Grad4(-0.3239847771997537, 0.5794684678643381, -0.6740059517812944, -0.3239847771997537), + new Grad4(-0.4004672082940195, 0.5029860367700724, -0.7504883828755602, 0.15296486218853164), + new Grad4( 0.15296486218853164, 0.5029860367700724, -0.7504883828755602, -0.4004672082940195), + new Grad4( 0.08164729285680945, 0.4553054119602712, -0.8828161875373585, 0.08164729285680945), + new Grad4(-0.08164729285680945, 0.8828161875373585, -0.4553054119602712, -0.08164729285680945), + new Grad4(-0.15296486218853164, 0.7504883828755602, -0.5029860367700724, 0.4004672082940195), + new Grad4( 0.4004672082940195, 0.7504883828755602, -0.5029860367700724, -0.15296486218853164), + new Grad4( 0.3239847771997537, 0.6740059517812944, -0.5794684678643381, 0.3239847771997537), + new Grad4(-0.3239847771997537, 0.5794684678643381, -0.3239847771997537, -0.6740059517812944), + new Grad4(-0.4004672082940195, 0.5029860367700724, 0.15296486218853164, -0.7504883828755602), + new Grad4( 0.15296486218853164, 0.5029860367700724, -0.4004672082940195, -0.7504883828755602), + new Grad4( 0.08164729285680945, 0.4553054119602712, 0.08164729285680945, -0.8828161875373585), + new Grad4(-0.08164729285680945, 0.8828161875373585, -0.08164729285680945, -0.4553054119602712), + new Grad4(-0.15296486218853164, 0.7504883828755602, 0.4004672082940195, -0.5029860367700724), + new Grad4( 0.4004672082940195, 0.7504883828755602, -0.15296486218853164, -0.5029860367700724), + new Grad4( 0.3239847771997537, 0.6740059517812944, 0.3239847771997537, -0.5794684678643381), + new Grad4( 0.5794684678643381, -0.6740059517812944, -0.3239847771997537, -0.3239847771997537), + new Grad4( 0.5029860367700724, -0.7504883828755602, -0.4004672082940195, 0.15296486218853164), + new Grad4( 0.5029860367700724, -0.7504883828755602, 0.15296486218853164, -0.4004672082940195), + new Grad4( 0.4553054119602712, -0.8828161875373585, 0.08164729285680945, 0.08164729285680945), + new Grad4( 0.8828161875373585, -0.4553054119602712, -0.08164729285680945, -0.08164729285680945), + new Grad4( 0.7504883828755602, -0.5029860367700724, -0.15296486218853164, 0.4004672082940195), + new Grad4( 0.7504883828755602, -0.5029860367700724, 0.4004672082940195, -0.15296486218853164), + new Grad4( 0.6740059517812944, -0.5794684678643381, 0.3239847771997537, 0.3239847771997537), + new Grad4( 0.5794684678643381, -0.3239847771997537, -0.6740059517812944, -0.3239847771997537), + new Grad4( 0.5029860367700724, -0.4004672082940195, -0.7504883828755602, 0.15296486218853164), + new Grad4( 0.5029860367700724, 0.15296486218853164, -0.7504883828755602, -0.4004672082940195), + new Grad4( 0.4553054119602712, 0.08164729285680945, -0.8828161875373585, 0.08164729285680945), + new Grad4( 0.8828161875373585, -0.08164729285680945, -0.4553054119602712, -0.08164729285680945), + new Grad4( 0.7504883828755602, -0.15296486218853164, -0.5029860367700724, 0.4004672082940195), + new Grad4( 0.7504883828755602, 0.4004672082940195, -0.5029860367700724, -0.15296486218853164), + new Grad4( 0.6740059517812944, 0.3239847771997537, -0.5794684678643381, 0.3239847771997537), + new Grad4( 0.5794684678643381, -0.3239847771997537, -0.3239847771997537, -0.6740059517812944), + new Grad4( 0.5029860367700724, -0.4004672082940195, 0.15296486218853164, -0.7504883828755602), + new Grad4( 0.5029860367700724, 0.15296486218853164, -0.4004672082940195, -0.7504883828755602), + new Grad4( 0.4553054119602712, 0.08164729285680945, 0.08164729285680945, -0.8828161875373585), + new Grad4( 0.8828161875373585, -0.08164729285680945, -0.08164729285680945, -0.4553054119602712), + new Grad4( 0.7504883828755602, -0.15296486218853164, 0.4004672082940195, -0.5029860367700724), + new Grad4( 0.7504883828755602, 0.4004672082940195, -0.15296486218853164, -0.5029860367700724), + new Grad4( 0.6740059517812944, 0.3239847771997537, 0.3239847771997537, -0.5794684678643381), + new Grad4( 0.03381941603233842, 0.03381941603233842, 0.03381941603233842, 0.9982828964265062), + new Grad4(-0.044802370851755174, -0.044802370851755174, 0.508629699630796, 0.8586508742123365), + new Grad4(-0.044802370851755174, 0.508629699630796, -0.044802370851755174, 0.8586508742123365), + new Grad4(-0.12128480194602098, 0.4321472685365301, 0.4321472685365301, 0.7821684431180708), + new Grad4( 0.508629699630796, -0.044802370851755174, -0.044802370851755174, 0.8586508742123365), + new Grad4( 0.4321472685365301, -0.12128480194602098, 0.4321472685365301, 0.7821684431180708), + new Grad4( 0.4321472685365301, 0.4321472685365301, -0.12128480194602098, 0.7821684431180708), + new Grad4( 0.37968289875261624, 0.37968289875261624, 0.37968289875261624, 0.753341017856078), + new Grad4( 0.03381941603233842, 0.03381941603233842, 0.9982828964265062, 0.03381941603233842), + new Grad4(-0.044802370851755174, 0.044802370851755174, 0.8586508742123365, 0.508629699630796), + new Grad4(-0.044802370851755174, 0.508629699630796, 0.8586508742123365, -0.044802370851755174), + new Grad4(-0.12128480194602098, 0.4321472685365301, 0.7821684431180708, 0.4321472685365301), + new Grad4( 0.508629699630796, -0.044802370851755174, 0.8586508742123365, -0.044802370851755174), + new Grad4( 0.4321472685365301, -0.12128480194602098, 0.7821684431180708, 0.4321472685365301), + new Grad4( 0.4321472685365301, 0.4321472685365301, 0.7821684431180708, -0.12128480194602098), + new Grad4( 0.37968289875261624, 0.37968289875261624, 0.753341017856078, 0.37968289875261624), + new Grad4( 0.03381941603233842, 0.9982828964265062, 0.03381941603233842, 0.03381941603233842), + new Grad4(-0.044802370851755174, 0.8586508742123365, -0.044802370851755174, 0.508629699630796), + new Grad4(-0.044802370851755174, 0.8586508742123365, 0.508629699630796, -0.044802370851755174), + new Grad4(-0.12128480194602098, 0.7821684431180708, 0.4321472685365301, 0.4321472685365301), + new Grad4( 0.508629699630796, 0.8586508742123365, -0.044802370851755174, -0.044802370851755174), + new Grad4( 0.4321472685365301, 0.7821684431180708, -0.12128480194602098, 0.4321472685365301), + new Grad4( 0.4321472685365301, 0.7821684431180708, 0.4321472685365301, -0.12128480194602098), + new Grad4( 0.37968289875261624, 0.753341017856078, 0.37968289875261624, 0.37968289875261624), + new Grad4( 0.9982828964265062, 0.03381941603233842, 0.03381941603233842, 0.03381941603233842), + new Grad4( 0.8586508742123365, -0.044802370851755174, -0.044802370851755174, 0.508629699630796), + new Grad4( 0.8586508742123365, -0.044802370851755174, 0.508629699630796, -0.044802370851755174), + new Grad4( 0.7821684431180708, -0.12128480194602098, 0.4321472685365301, 0.4321472685365301), + new Grad4( 0.8586508742123365, 0.508629699630796, -0.044802370851755174, -0.044802370851755174), + new Grad4( 0.7821684431180708, 0.4321472685365301, -0.12128480194602098, 0.4321472685365301), + new Grad4( 0.7821684431180708, 0.4321472685365301, 0.4321472685365301, -0.12128480194602098), + new Grad4( 0.753341017856078, 0.37968289875261624, 0.37968289875261624, 0.37968289875261624) + }; + for (Grad4 grad41 : grad4) { + grad41.dx /= N4; + grad41.dy /= N4; + grad41.dz /= N4; + grad41.dw /= N4; } - } - - return value; - } - - /* - * Utility - */ - private static int fastFloor(double x) { - int xi = (int) x; - return x < xi ? xi - 1 : xi; - } - - /* - * Definitions - */ - private static final LatticePoint2D[] LOOKUP_2D; - private static final LatticePoint3D[] LOOKUP_3D; - private static final LatticePoint4D[] VERTICES_4D; - - static { - LOOKUP_2D = new LatticePoint2D[4]; - LOOKUP_3D = new LatticePoint3D[8]; - VERTICES_4D = new LatticePoint4D[16]; - - LOOKUP_2D[0] = new LatticePoint2D(1, 0); - LOOKUP_2D[1] = new LatticePoint2D(0, 0); - LOOKUP_2D[2] = new LatticePoint2D(1, 1); - LOOKUP_2D[3] = new LatticePoint2D(0, 1); - - for (int i = 0; i < 8; i++) { - int i1, j1, k1, i2, j2, k2; - i1 = (i) & 1; - j1 = (i >> 1) & 1; - k1 = (i >> 2) & 1; - i2 = i1 ^ 1; - j2 = j1 ^ 1; - k2 = k1 ^ 1; - - // The two points within this octant, one from each of the two cubic half-lattices. - LatticePoint3D c0 = new LatticePoint3D(i1, j1, k1, 0); - LatticePoint3D c1 = new LatticePoint3D(i1 + i2, j1 + j2, k1 + k2, 1); - - // Each single step away on the first half-lattice. - LatticePoint3D c2 = new LatticePoint3D(i1 ^ 1, j1, k1, 0); - LatticePoint3D c3 = new LatticePoint3D(i1, j1 ^ 1, k1, 0); - LatticePoint3D c4 = new LatticePoint3D(i1, j1, k1 ^ 1, 0); - - // Each single step away on the second half-lattice. - LatticePoint3D c5 = new LatticePoint3D(i1 + (i2 ^ 1), j1 + j2, k1 + k2, 1); - LatticePoint3D c6 = new LatticePoint3D(i1 + i2, j1 + (j2 ^ 1), k1 + k2, 1); - LatticePoint3D c7 = new LatticePoint3D(i1 + i2, j1 + j2, k1 + (k2 ^ 1), 1); - - // First two are guaranteed. - c0.nextOnFailure = c0.nextOnSuccess = c1; - c1.nextOnFailure = c1.nextOnSuccess = c2; - - // Once we find one on the first half-lattice, the rest are out. - // In addition, knowing c2 rules out c5. - c2.nextOnFailure = c3; - c2.nextOnSuccess = c6; - c3.nextOnFailure = c4; - c3.nextOnSuccess = c5; - c4.nextOnFailure = c4.nextOnSuccess = c5; - - // Once we find one on the second half-lattice, the rest are out. - c5.nextOnFailure = c6; - c5.nextOnSuccess = null; - c6.nextOnFailure = c7; - c6.nextOnSuccess = null; - c7.nextOnFailure = c7.nextOnSuccess = null; - - LOOKUP_3D[i] = c0; - } - - for (int i = 0; i < 16; i++) { - VERTICES_4D[i] = new LatticePoint4D((i) & 1, (i >> 1) & 1, (i >> 2) & 1, (i >> 3) & 1); - } - } - - @Override - public float noise(float x, float y, float z) { - return (float)noise3_Classic(x, y, z); - } - - @Override - public float noise(float x, float y, float z, float w) { - return (float)noise4_Classic(x, y, z, w); - } - - @Override - public void noiseMode(NoiseMode mode) { - - } - - @Override - public void noiseSeed(long seed) { - } - - private static class LatticePoint2D { - - int xsv, ysv; - double dx, dy; - - public LatticePoint2D(int xsv, int ysv) { - this.xsv = xsv; - this.ysv = ysv; - double ssv = (xsv + ysv) * -0.211324865405187; - this.dx = -xsv - ssv; - this.dy = -ysv - ssv; - } - } - - private static class LatticePoint3D { - - public double dxr, dyr, dzr; - public int xrv, yrv, zrv; - LatticePoint3D nextOnFailure, nextOnSuccess; - - public LatticePoint3D(int xrv, int yrv, int zrv, int lattice) { - this.dxr = -xrv + lattice * 0.5; - this.dyr = -yrv + lattice * 0.5; - this.dzr = -zrv + lattice * 0.5; - this.xrv = xrv + lattice * 1024; - this.yrv = yrv + lattice * 1024; - this.zrv = zrv + lattice * 1024; - } - } - - private static class LatticePoint4D { - - int xsv, ysv, zsv, wsv; - double dx, dy, dz, dw; - double xsi, ysi, zsi, wsi; - double ssiDelta; - - public LatticePoint4D(int xsv, int ysv, int zsv, int wsv) { - this.xsv = xsv + 409; - this.ysv = ysv + 409; - this.zsv = zsv + 409; - this.wsv = wsv + 409; - double ssv = (xsv + ysv + zsv + wsv) * 0.309016994374947; - this.dx = -xsv - ssv; - this.dy = -ysv - ssv; - this.dz = -zsv - ssv; - this.dw = -wsv - ssv; - this.xsi = xsi = 0.2 - xsv; - this.ysi = ysi = 0.2 - ysv; - this.zsi = zsi = 0.2 - zsv; - this.wsi = wsi = 0.2 - wsv; - this.ssiDelta = (0.8 - xsv - ysv - zsv - wsv) * 0.309016994374947; - } - } - - /* - * Gradients - */ - private static class Grad2 { - - double dx, dy; - - public Grad2(double dx, double dy) { - this.dx = dx; - this.dy = dy; - } - } - - private static class Grad3 { - - double dx, dy, dz; - - public Grad3(double dx, double dy, double dz) { - this.dx = dx; - this.dy = dy; - this.dz = dz; - } - } - - private static class Grad4 { - - double dx, dy, dz, dw; - - public Grad4(double dx, double dy, double dz, double dw) { - this.dx = dx; - this.dy = dy; - this.dz = dz; - this.dw = dw; - } - } - - private static final double N2 = 0.01001634121365712; - private static final double N3 = 0.030485933181293584; - private static final double N4 = 0.009202377986303158; - private static final Grad2[] GRADIENTS_2D; - private static final Grad3[] GRADIENTS_3D; - private static final Grad4[] GRADIENTS_4D; - - static { - - GRADIENTS_2D = new Grad2[PSIZE]; - Grad2[] grad2 = { - new Grad2(0.130526192220052, 0.99144486137381), - new Grad2(0.38268343236509, 0.923879532511287), - new Grad2(0.608761429008721, 0.793353340291235), - new Grad2(0.793353340291235, 0.608761429008721), - new Grad2(0.923879532511287, 0.38268343236509), - new Grad2(0.99144486137381, 0.130526192220051), - new Grad2(0.99144486137381, -0.130526192220051), - new Grad2(0.923879532511287, -0.38268343236509), - new Grad2(0.793353340291235, -0.60876142900872), - new Grad2(0.608761429008721, -0.793353340291235), - new Grad2(0.38268343236509, -0.923879532511287), - new Grad2(0.130526192220052, -0.99144486137381), - new Grad2(-0.130526192220052, -0.99144486137381), - new Grad2(-0.38268343236509, -0.923879532511287), - new Grad2(-0.608761429008721, -0.793353340291235), - new Grad2(-0.793353340291235, -0.608761429008721), - new Grad2(-0.923879532511287, -0.38268343236509), - new Grad2(-0.99144486137381, -0.130526192220052), - new Grad2(-0.99144486137381, 0.130526192220051), - new Grad2(-0.923879532511287, 0.38268343236509), - new Grad2(-0.793353340291235, 0.608761429008721), - new Grad2(-0.608761429008721, 0.793353340291235), - new Grad2(-0.38268343236509, 0.923879532511287), - new Grad2(-0.130526192220052, 0.99144486137381) - }; - for (Grad2 grad21 : grad2) { - grad21.dx /= N2; - grad21.dy /= N2; - } - for (int i = 0; i < PSIZE; i++) { - GRADIENTS_2D[i] = grad2[i % grad2.length]; - } - - GRADIENTS_3D = new Grad3[PSIZE]; - Grad3[] grad3 = { - new Grad3(-2.22474487139, -2.22474487139, -1.0), - new Grad3(-2.22474487139, -2.22474487139, 1.0), - new Grad3(-3.0862664687972017, -1.1721513422464978, 0.0), - new Grad3(-1.1721513422464978, -3.0862664687972017, 0.0), - new Grad3(-2.22474487139, -1.0, -2.22474487139), - new Grad3(-2.22474487139, 1.0, -2.22474487139), - new Grad3(-1.1721513422464978, 0.0, -3.0862664687972017), - new Grad3(-3.0862664687972017, 0.0, -1.1721513422464978), - new Grad3(-2.22474487139, -1.0, 2.22474487139), - new Grad3(-2.22474487139, 1.0, 2.22474487139), - new Grad3(-3.0862664687972017, 0.0, 1.1721513422464978), - new Grad3(-1.1721513422464978, 0.0, 3.0862664687972017), - new Grad3(-2.22474487139, 2.22474487139, -1.0), - new Grad3(-2.22474487139, 2.22474487139, 1.0), - new Grad3(-1.1721513422464978, 3.0862664687972017, 0.0), - new Grad3(-3.0862664687972017, 1.1721513422464978, 0.0), - new Grad3(-1.0, -2.22474487139, -2.22474487139), - new Grad3(1.0, -2.22474487139, -2.22474487139), - new Grad3(0.0, -3.0862664687972017, -1.1721513422464978), - new Grad3(0.0, -1.1721513422464978, -3.0862664687972017), - new Grad3(-1.0, -2.22474487139, 2.22474487139), - new Grad3(1.0, -2.22474487139, 2.22474487139), - new Grad3(0.0, -1.1721513422464978, 3.0862664687972017), - new Grad3(0.0, -3.0862664687972017, 1.1721513422464978), - new Grad3(-1.0, 2.22474487139, -2.22474487139), - new Grad3(1.0, 2.22474487139, -2.22474487139), - new Grad3(0.0, 1.1721513422464978, -3.0862664687972017), - new Grad3(0.0, 3.0862664687972017, -1.1721513422464978), - new Grad3(-1.0, 2.22474487139, 2.22474487139), - new Grad3(1.0, 2.22474487139, 2.22474487139), - new Grad3(0.0, 3.0862664687972017, 1.1721513422464978), - new Grad3(0.0, 1.1721513422464978, 3.0862664687972017), - new Grad3(2.22474487139, -2.22474487139, -1.0), - new Grad3(2.22474487139, -2.22474487139, 1.0), - new Grad3(1.1721513422464978, -3.0862664687972017, 0.0), - new Grad3(3.0862664687972017, -1.1721513422464978, 0.0), - new Grad3(2.22474487139, -1.0, -2.22474487139), - new Grad3(2.22474487139, 1.0, -2.22474487139), - new Grad3(3.0862664687972017, 0.0, -1.1721513422464978), - new Grad3(1.1721513422464978, 0.0, -3.0862664687972017), - new Grad3(2.22474487139, -1.0, 2.22474487139), - new Grad3(2.22474487139, 1.0, 2.22474487139), - new Grad3(1.1721513422464978, 0.0, 3.0862664687972017), - new Grad3(3.0862664687972017, 0.0, 1.1721513422464978), - new Grad3(2.22474487139, 2.22474487139, -1.0), - new Grad3(2.22474487139, 2.22474487139, 1.0), - new Grad3(3.0862664687972017, 1.1721513422464978, 0.0), - new Grad3(1.1721513422464978, 3.0862664687972017, 0.0) - }; - for (Grad3 grad31 : grad3) { - grad31.dx /= N3; - grad31.dy /= N3; - grad31.dz /= N3; - } - for (int i = 0; i < PSIZE; i++) { - GRADIENTS_3D[i] = grad3[i % grad3.length]; - } - - GRADIENTS_4D = new Grad4[PSIZE]; - Grad4[] grad4 = { - new Grad4(-0.753341017856078, -0.37968289875261624, -0.37968289875261624, -0.37968289875261624), - new Grad4(-0.7821684431180708, -0.4321472685365301, -0.4321472685365301, 0.12128480194602098), - new Grad4(-0.7821684431180708, -0.4321472685365301, 0.12128480194602098, -0.4321472685365301), - new Grad4(-0.7821684431180708, 0.12128480194602098, -0.4321472685365301, -0.4321472685365301), - new Grad4(-0.8586508742123365, -0.508629699630796, 0.044802370851755174, 0.044802370851755174), - new Grad4(-0.8586508742123365, 0.044802370851755174, -0.508629699630796, 0.044802370851755174), - new Grad4(-0.8586508742123365, 0.044802370851755174, 0.044802370851755174, -0.508629699630796), - new Grad4(-0.9982828964265062, -0.03381941603233842, -0.03381941603233842, -0.03381941603233842), - new Grad4(-0.37968289875261624, -0.753341017856078, -0.37968289875261624, -0.37968289875261624), - new Grad4(-0.4321472685365301, -0.7821684431180708, -0.4321472685365301, 0.12128480194602098), - new Grad4(-0.4321472685365301, -0.7821684431180708, 0.12128480194602098, -0.4321472685365301), - new Grad4(0.12128480194602098, -0.7821684431180708, -0.4321472685365301, -0.4321472685365301), - new Grad4(-0.508629699630796, -0.8586508742123365, 0.044802370851755174, 0.044802370851755174), - new Grad4(0.044802370851755174, -0.8586508742123365, -0.508629699630796, 0.044802370851755174), - new Grad4(0.044802370851755174, -0.8586508742123365, 0.044802370851755174, -0.508629699630796), - new Grad4(-0.03381941603233842, -0.9982828964265062, -0.03381941603233842, -0.03381941603233842), - new Grad4(-0.37968289875261624, -0.37968289875261624, -0.753341017856078, -0.37968289875261624), - new Grad4(-0.4321472685365301, -0.4321472685365301, -0.7821684431180708, 0.12128480194602098), - new Grad4(-0.4321472685365301, 0.12128480194602098, -0.7821684431180708, -0.4321472685365301), - new Grad4(0.12128480194602098, -0.4321472685365301, -0.7821684431180708, -0.4321472685365301), - new Grad4(-0.508629699630796, 0.044802370851755174, -0.8586508742123365, 0.044802370851755174), - new Grad4(0.044802370851755174, -0.508629699630796, -0.8586508742123365, 0.044802370851755174), - new Grad4(0.044802370851755174, 0.044802370851755174, -0.8586508742123365, -0.508629699630796), - new Grad4(-0.03381941603233842, -0.03381941603233842, -0.9982828964265062, -0.03381941603233842), - new Grad4(-0.37968289875261624, -0.37968289875261624, -0.37968289875261624, -0.753341017856078), - new Grad4(-0.4321472685365301, -0.4321472685365301, 0.12128480194602098, -0.7821684431180708), - new Grad4(-0.4321472685365301, 0.12128480194602098, -0.4321472685365301, -0.7821684431180708), - new Grad4(0.12128480194602098, -0.4321472685365301, -0.4321472685365301, -0.7821684431180708), - new Grad4(-0.508629699630796, 0.044802370851755174, 0.044802370851755174, -0.8586508742123365), - new Grad4(0.044802370851755174, -0.508629699630796, 0.044802370851755174, -0.8586508742123365), - new Grad4(0.044802370851755174, 0.044802370851755174, -0.508629699630796, -0.8586508742123365), - new Grad4(-0.03381941603233842, -0.03381941603233842, -0.03381941603233842, -0.9982828964265062), - new Grad4(-0.6740059517812944, -0.3239847771997537, -0.3239847771997537, 0.5794684678643381), - new Grad4(-0.7504883828755602, -0.4004672082940195, 0.15296486218853164, 0.5029860367700724), - new Grad4(-0.7504883828755602, 0.15296486218853164, -0.4004672082940195, 0.5029860367700724), - new Grad4(-0.8828161875373585, 0.08164729285680945, 0.08164729285680945, 0.4553054119602712), - new Grad4(-0.4553054119602712, -0.08164729285680945, -0.08164729285680945, 0.8828161875373585), - new Grad4(-0.5029860367700724, -0.15296486218853164, 0.4004672082940195, 0.7504883828755602), - new Grad4(-0.5029860367700724, 0.4004672082940195, -0.15296486218853164, 0.7504883828755602), - new Grad4(-0.5794684678643381, 0.3239847771997537, 0.3239847771997537, 0.6740059517812944), - new Grad4(-0.3239847771997537, -0.6740059517812944, -0.3239847771997537, 0.5794684678643381), - new Grad4(-0.4004672082940195, -0.7504883828755602, 0.15296486218853164, 0.5029860367700724), - new Grad4(0.15296486218853164, -0.7504883828755602, -0.4004672082940195, 0.5029860367700724), - new Grad4(0.08164729285680945, -0.8828161875373585, 0.08164729285680945, 0.4553054119602712), - new Grad4(-0.08164729285680945, -0.4553054119602712, -0.08164729285680945, 0.8828161875373585), - new Grad4(-0.15296486218853164, -0.5029860367700724, 0.4004672082940195, 0.7504883828755602), - new Grad4(0.4004672082940195, -0.5029860367700724, -0.15296486218853164, 0.7504883828755602), - new Grad4(0.3239847771997537, -0.5794684678643381, 0.3239847771997537, 0.6740059517812944), - new Grad4(-0.3239847771997537, -0.3239847771997537, -0.6740059517812944, 0.5794684678643381), - new Grad4(-0.4004672082940195, 0.15296486218853164, -0.7504883828755602, 0.5029860367700724), - new Grad4(0.15296486218853164, -0.4004672082940195, -0.7504883828755602, 0.5029860367700724), - new Grad4(0.08164729285680945, 0.08164729285680945, -0.8828161875373585, 0.4553054119602712), - new Grad4(-0.08164729285680945, -0.08164729285680945, -0.4553054119602712, 0.8828161875373585), - new Grad4(-0.15296486218853164, 0.4004672082940195, -0.5029860367700724, 0.7504883828755602), - new Grad4(0.4004672082940195, -0.15296486218853164, -0.5029860367700724, 0.7504883828755602), - new Grad4(0.3239847771997537, 0.3239847771997537, -0.5794684678643381, 0.6740059517812944), - new Grad4(-0.6740059517812944, -0.3239847771997537, 0.5794684678643381, -0.3239847771997537), - new Grad4(-0.7504883828755602, -0.4004672082940195, 0.5029860367700724, 0.15296486218853164), - new Grad4(-0.7504883828755602, 0.15296486218853164, 0.5029860367700724, -0.4004672082940195), - new Grad4(-0.8828161875373585, 0.08164729285680945, 0.4553054119602712, 0.08164729285680945), - new Grad4(-0.4553054119602712, -0.08164729285680945, 0.8828161875373585, -0.08164729285680945), - new Grad4(-0.5029860367700724, -0.15296486218853164, 0.7504883828755602, 0.4004672082940195), - new Grad4(-0.5029860367700724, 0.4004672082940195, 0.7504883828755602, -0.15296486218853164), - new Grad4(-0.5794684678643381, 0.3239847771997537, 0.6740059517812944, 0.3239847771997537), - new Grad4(-0.3239847771997537, -0.6740059517812944, 0.5794684678643381, -0.3239847771997537), - new Grad4(-0.4004672082940195, -0.7504883828755602, 0.5029860367700724, 0.15296486218853164), - new Grad4(0.15296486218853164, -0.7504883828755602, 0.5029860367700724, -0.4004672082940195), - new Grad4(0.08164729285680945, -0.8828161875373585, 0.4553054119602712, 0.08164729285680945), - new Grad4(-0.08164729285680945, -0.4553054119602712, 0.8828161875373585, -0.08164729285680945), - new Grad4(-0.15296486218853164, -0.5029860367700724, 0.7504883828755602, 0.4004672082940195), - new Grad4(0.4004672082940195, -0.5029860367700724, 0.7504883828755602, -0.15296486218853164), - new Grad4(0.3239847771997537, -0.5794684678643381, 0.6740059517812944, 0.3239847771997537), - new Grad4(-0.3239847771997537, -0.3239847771997537, 0.5794684678643381, -0.6740059517812944), - new Grad4(-0.4004672082940195, 0.15296486218853164, 0.5029860367700724, -0.7504883828755602), - new Grad4(0.15296486218853164, -0.4004672082940195, 0.5029860367700724, -0.7504883828755602), - new Grad4(0.08164729285680945, 0.08164729285680945, 0.4553054119602712, -0.8828161875373585), - new Grad4(-0.08164729285680945, -0.08164729285680945, 0.8828161875373585, -0.4553054119602712), - new Grad4(-0.15296486218853164, 0.4004672082940195, 0.7504883828755602, -0.5029860367700724), - new Grad4(0.4004672082940195, -0.15296486218853164, 0.7504883828755602, -0.5029860367700724), - new Grad4(0.3239847771997537, 0.3239847771997537, 0.6740059517812944, -0.5794684678643381), - new Grad4(-0.6740059517812944, 0.5794684678643381, -0.3239847771997537, -0.3239847771997537), - new Grad4(-0.7504883828755602, 0.5029860367700724, -0.4004672082940195, 0.15296486218853164), - new Grad4(-0.7504883828755602, 0.5029860367700724, 0.15296486218853164, -0.4004672082940195), - new Grad4(-0.8828161875373585, 0.4553054119602712, 0.08164729285680945, 0.08164729285680945), - new Grad4(-0.4553054119602712, 0.8828161875373585, -0.08164729285680945, -0.08164729285680945), - new Grad4(-0.5029860367700724, 0.7504883828755602, -0.15296486218853164, 0.4004672082940195), - new Grad4(-0.5029860367700724, 0.7504883828755602, 0.4004672082940195, -0.15296486218853164), - new Grad4(-0.5794684678643381, 0.6740059517812944, 0.3239847771997537, 0.3239847771997537), - new Grad4(-0.3239847771997537, 0.5794684678643381, -0.6740059517812944, -0.3239847771997537), - new Grad4(-0.4004672082940195, 0.5029860367700724, -0.7504883828755602, 0.15296486218853164), - new Grad4(0.15296486218853164, 0.5029860367700724, -0.7504883828755602, -0.4004672082940195), - new Grad4(0.08164729285680945, 0.4553054119602712, -0.8828161875373585, 0.08164729285680945), - new Grad4(-0.08164729285680945, 0.8828161875373585, -0.4553054119602712, -0.08164729285680945), - new Grad4(-0.15296486218853164, 0.7504883828755602, -0.5029860367700724, 0.4004672082940195), - new Grad4(0.4004672082940195, 0.7504883828755602, -0.5029860367700724, -0.15296486218853164), - new Grad4(0.3239847771997537, 0.6740059517812944, -0.5794684678643381, 0.3239847771997537), - new Grad4(-0.3239847771997537, 0.5794684678643381, -0.3239847771997537, -0.6740059517812944), - new Grad4(-0.4004672082940195, 0.5029860367700724, 0.15296486218853164, -0.7504883828755602), - new Grad4(0.15296486218853164, 0.5029860367700724, -0.4004672082940195, -0.7504883828755602), - new Grad4(0.08164729285680945, 0.4553054119602712, 0.08164729285680945, -0.8828161875373585), - new Grad4(-0.08164729285680945, 0.8828161875373585, -0.08164729285680945, -0.4553054119602712), - new Grad4(-0.15296486218853164, 0.7504883828755602, 0.4004672082940195, -0.5029860367700724), - new Grad4(0.4004672082940195, 0.7504883828755602, -0.15296486218853164, -0.5029860367700724), - new Grad4(0.3239847771997537, 0.6740059517812944, 0.3239847771997537, -0.5794684678643381), - new Grad4(0.5794684678643381, -0.6740059517812944, -0.3239847771997537, -0.3239847771997537), - new Grad4(0.5029860367700724, -0.7504883828755602, -0.4004672082940195, 0.15296486218853164), - new Grad4(0.5029860367700724, -0.7504883828755602, 0.15296486218853164, -0.4004672082940195), - new Grad4(0.4553054119602712, -0.8828161875373585, 0.08164729285680945, 0.08164729285680945), - new Grad4(0.8828161875373585, -0.4553054119602712, -0.08164729285680945, -0.08164729285680945), - new Grad4(0.7504883828755602, -0.5029860367700724, -0.15296486218853164, 0.4004672082940195), - new Grad4(0.7504883828755602, -0.5029860367700724, 0.4004672082940195, -0.15296486218853164), - new Grad4(0.6740059517812944, -0.5794684678643381, 0.3239847771997537, 0.3239847771997537), - new Grad4(0.5794684678643381, -0.3239847771997537, -0.6740059517812944, -0.3239847771997537), - new Grad4(0.5029860367700724, -0.4004672082940195, -0.7504883828755602, 0.15296486218853164), - new Grad4(0.5029860367700724, 0.15296486218853164, -0.7504883828755602, -0.4004672082940195), - new Grad4(0.4553054119602712, 0.08164729285680945, -0.8828161875373585, 0.08164729285680945), - new Grad4(0.8828161875373585, -0.08164729285680945, -0.4553054119602712, -0.08164729285680945), - new Grad4(0.7504883828755602, -0.15296486218853164, -0.5029860367700724, 0.4004672082940195), - new Grad4(0.7504883828755602, 0.4004672082940195, -0.5029860367700724, -0.15296486218853164), - new Grad4(0.6740059517812944, 0.3239847771997537, -0.5794684678643381, 0.3239847771997537), - new Grad4(0.5794684678643381, -0.3239847771997537, -0.3239847771997537, -0.6740059517812944), - new Grad4(0.5029860367700724, -0.4004672082940195, 0.15296486218853164, -0.7504883828755602), - new Grad4(0.5029860367700724, 0.15296486218853164, -0.4004672082940195, -0.7504883828755602), - new Grad4(0.4553054119602712, 0.08164729285680945, 0.08164729285680945, -0.8828161875373585), - new Grad4(0.8828161875373585, -0.08164729285680945, -0.08164729285680945, -0.4553054119602712), - new Grad4(0.7504883828755602, -0.15296486218853164, 0.4004672082940195, -0.5029860367700724), - new Grad4(0.7504883828755602, 0.4004672082940195, -0.15296486218853164, -0.5029860367700724), - new Grad4(0.6740059517812944, 0.3239847771997537, 0.3239847771997537, -0.5794684678643381), - new Grad4(0.03381941603233842, 0.03381941603233842, 0.03381941603233842, 0.9982828964265062), - new Grad4(-0.044802370851755174, -0.044802370851755174, 0.508629699630796, 0.8586508742123365), - new Grad4(-0.044802370851755174, 0.508629699630796, -0.044802370851755174, 0.8586508742123365), - new Grad4(-0.12128480194602098, 0.4321472685365301, 0.4321472685365301, 0.7821684431180708), - new Grad4(0.508629699630796, -0.044802370851755174, -0.044802370851755174, 0.8586508742123365), - new Grad4(0.4321472685365301, -0.12128480194602098, 0.4321472685365301, 0.7821684431180708), - new Grad4(0.4321472685365301, 0.4321472685365301, -0.12128480194602098, 0.7821684431180708), - new Grad4(0.37968289875261624, 0.37968289875261624, 0.37968289875261624, 0.753341017856078), - new Grad4(0.03381941603233842, 0.03381941603233842, 0.9982828964265062, 0.03381941603233842), - new Grad4(-0.044802370851755174, 0.044802370851755174, 0.8586508742123365, 0.508629699630796), - new Grad4(-0.044802370851755174, 0.508629699630796, 0.8586508742123365, -0.044802370851755174), - new Grad4(-0.12128480194602098, 0.4321472685365301, 0.7821684431180708, 0.4321472685365301), - new Grad4(0.508629699630796, -0.044802370851755174, 0.8586508742123365, -0.044802370851755174), - new Grad4(0.4321472685365301, -0.12128480194602098, 0.7821684431180708, 0.4321472685365301), - new Grad4(0.4321472685365301, 0.4321472685365301, 0.7821684431180708, -0.12128480194602098), - new Grad4(0.37968289875261624, 0.37968289875261624, 0.753341017856078, 0.37968289875261624), - new Grad4(0.03381941603233842, 0.9982828964265062, 0.03381941603233842, 0.03381941603233842), - new Grad4(-0.044802370851755174, 0.8586508742123365, -0.044802370851755174, 0.508629699630796), - new Grad4(-0.044802370851755174, 0.8586508742123365, 0.508629699630796, -0.044802370851755174), - new Grad4(-0.12128480194602098, 0.7821684431180708, 0.4321472685365301, 0.4321472685365301), - new Grad4(0.508629699630796, 0.8586508742123365, -0.044802370851755174, -0.044802370851755174), - new Grad4(0.4321472685365301, 0.7821684431180708, -0.12128480194602098, 0.4321472685365301), - new Grad4(0.4321472685365301, 0.7821684431180708, 0.4321472685365301, -0.12128480194602098), - new Grad4(0.37968289875261624, 0.753341017856078, 0.37968289875261624, 0.37968289875261624), - new Grad4(0.9982828964265062, 0.03381941603233842, 0.03381941603233842, 0.03381941603233842), - new Grad4(0.8586508742123365, -0.044802370851755174, -0.044802370851755174, 0.508629699630796), - new Grad4(0.8586508742123365, -0.044802370851755174, 0.508629699630796, -0.044802370851755174), - new Grad4(0.7821684431180708, -0.12128480194602098, 0.4321472685365301, 0.4321472685365301), - new Grad4(0.8586508742123365, 0.508629699630796, -0.044802370851755174, -0.044802370851755174), - new Grad4(0.7821684431180708, 0.4321472685365301, -0.12128480194602098, 0.4321472685365301), - new Grad4(0.7821684431180708, 0.4321472685365301, 0.4321472685365301, -0.12128480194602098), - new Grad4(0.753341017856078, 0.37968289875261624, 0.37968289875261624, 0.37968289875261624) - }; - for (Grad4 grad41 : grad4) { - grad41.dx /= N4; - grad41.dy /= N4; - grad41.dz /= N4; - grad41.dw /= N4; - } - for (int i = 0; i < PSIZE; i++) { - GRADIENTS_4D[i] = grad4[i % grad4.length]; - } - } + for (int i = 0; i < PSIZE; i++) { + GRADIENTS_4D[i] = grad4[i % grad4.length]; + } + } } diff --git a/src/main/java/monkstone/noise/OpenSimplex2S.java b/src/main/java/monkstone/noise/OpenSimplex2S.java index 4a690b2..44c0499 100644 --- a/src/main/java/monkstone/noise/OpenSimplex2S.java +++ b/src/main/java/monkstone/noise/OpenSimplex2S.java @@ -1,1106 +1,1138 @@ -package monkstone.noise; - -/** - * K.jpg's OpenSimplex 2, smooth variant ("SuperSimplex") - * - * - 2D is standard simplex, modified to support larger kernels. Implemented - * using a lookup table. - 3D is "Re-oriented 8-point BCC noise" which - * constructs a congruent BCC lattice in a much different way than usual. - 4D - * uses a naïve pregenerated lookup table, and averages out to the expected - * performance. - * - * Multiple versions of each function are provided. See the documentation above - * each, for more info. - */ -public class OpenSimplex2S implements Noise { - - private static final int PSIZE = 2048; - private static final int PMASK = 2047; - - private final short[] perm; - private final Grad2[] permGrad2; - private final Grad3[] permGrad3; - private final Grad4[] permGrad4; - - public OpenSimplex2S(long seed) { - perm = new short[PSIZE]; - permGrad2 = new Grad2[PSIZE]; - permGrad3 = new Grad3[PSIZE]; - permGrad4 = new Grad4[PSIZE]; - short[] source = new short[PSIZE]; - for (short i = 0; i < PSIZE; i++) { - source[i] = i; - } - for (int i = PSIZE - 1; i >= 0; i--) { - seed = seed * 6364136223846793005L + 1442695040888963407L; - int r = (int) ((seed + 31) % (i + 1)); - if (r < 0) { - r += (i + 1); - } - perm[i] = source[r]; - permGrad2[i] = GRADIENTS_2D[perm[i]]; - permGrad3[i] = GRADIENTS_3D[perm[i]]; - permGrad4[i] = GRADIENTS_4D[perm[i]]; - source[r] = source[i]; - } - } - - /* - * Noise Evaluators - */ - /** - * 2D SuperSimplex noise, standard lattice orientation. - * - * @param x - * @param y - * @return - */ - public double noise2(double x, double y) { - - // Get points for A2* lattice - double s = 0.366025403784439 * (x + y); - double xs = x + s, ys = y + s; - - return noise2_Base(xs, ys); - } - - /** - * 2D SuperSimplex noise, with Y pointing down the main diagonal.Might be - * better for a 2D sandbox style game, where Y is vertical.Probably slightly - * less optimal for heightmaps or continent maps. - * - * @param x - * @param y - * @return - */ - public double noise2_XBeforeY(double x, double y) { - - // Skew transform and rotation baked into one. - double xx = x * 0.7071067811865476; - double yy = y * 1.224744871380249; - - return noise2_Base(yy + xx, yy - xx); - } - - /** - * 2D SuperSimplex noise base. Lookup table implementation inspired by - * DigitalShadow. - */ - private double noise2_Base(double xs, double ys) { - double value = 0; - - // Get base points and offsets - int xsb = fastFloor(xs), ysb = fastFloor(ys); - double xsi = xs - xsb, ysi = ys - ysb; - - // Index to point list - int a = (int) (xsi + ysi); - int index - = (a << 2) - | (int) (xsi - ysi / 2 + 1 - a / 2.0) << 3 - | (int) (ysi - xsi / 2 + 1 - a / 2.0) << 4; - - double ssi = (xsi + ysi) * -0.211324865405187; - double xi = xsi + ssi, yi = ysi + ssi; - - // Point contributions - for (int i = 0; i < 4; i++) { - LatticePoint2D c = LOOKUP_2D[index + i]; - - double dx = xi + c.dx, dy = yi + c.dy; - double attn = 2.0 / 3.0 - dx * dx - dy * dy; - if (attn <= 0) { - continue; - } - - int pxm = (xsb + c.xsv) & PMASK, pym = (ysb + c.ysv) & PMASK; - Grad2 grad = permGrad2[perm[pxm] ^ pym]; - double extrapolation = grad.dx * dx + grad.dy * dy; - - attn *= attn; - value += attn * attn * extrapolation; - } - - return value; - } - - /** - * 3D Re-oriented 8-point BCC noise, classic orientation Proper substitute - * for what 3D SuperSimplex would be, in light of Forbidden Formulae.Use - * noise3_XYBeforeZ or noise3_XZBeforeY instead, wherever appropriate. - * - * @param x - * @param y - * @param z - * @return - */ - public double noise3_Classic(double x, double y, double z) { - - // Re-orient the cubic lattices via rotation, to produce the expected look on cardinal planar slices. - // If texturing objects that don't tend to have cardinal plane faces, you could even remove this. - // Orthonormal rotation. Not a skew transform. - double r = (2.0 / 3.0) * (x + y + z); - double xr = r - x, yr = r - y, zr = r - z; - - // Evaluate both lattices to form a BCC lattice. - return noise3_BCC(xr, yr, zr); - } - - /** - * 3D Re-oriented 8-point BCC noise, with better visual isotropy in (X, - * Z).Recommended for 3D terrain and time-varied animations.The Y coordinate - * should always be the "different" coordinate in your use case.If Y is - * vertical in world coordinates, call noise3_XZBeforeY(x, Y, z).If Z is - * vertical in world coordinates, call noise3_XZBeforeY(x, Z, y) or use - * noise3_XYBeforeZ. For a time varied animation, call noise3_XZBeforeY(x, - * T, y) or use noise3_XYBeforeZ. - * - * @param x - * @param y - * @param z - * @return - */ - public double noise3_XZBeforeY(double x, double y, double z) { - - // Re-orient the cubic lattices without skewing, to make X and Z triangular like 2D. - // Orthonormal rotation. Not a skew transform. - double xz = x + z; - double s2 = xz * -0.211324865405187; - double yy = y * 0.577350269189626; - double xr = x + s2 - yy; - double zr = z + s2 - yy; - double yr = xz * 0.577350269189626 + yy; - - // Evaluate both lattices to form a BCC lattice. - return noise3_BCC(xr, yr, zr); - } - - /** - * Generate overlapping cubic lattices for 3D Re-oriented BCC noise. Lookup - * table implementation inspired by DigitalShadow. It was actually faster to - * narrow down the points in the loop itself, than to build up the index - * with enough info to isolate 8 points. - */ - private double noise3_BCC(double xr, double yr, double zr) { - - // Get base and offsets inside cube of first lattice. - int xrb = fastFloor(xr), yrb = fastFloor(yr), zrb = fastFloor(zr); - double xri = xr - xrb, yri = yr - yrb, zri = zr - zrb; - - // Identify which octant of the cube we're in. This determines which cell - // in the other cubic lattice we're in, and also narrows down one point on each. - int xht = (int) (xri + 0.5), yht = (int) (yri + 0.5), zht = (int) (zri + 0.5); - int index = (xht) | (yht << 1) | (zht << 2); - - // Point contributions - double value = 0; - LatticePoint3D c = LOOKUP_3D[index]; - while (c != null) { - double dxr = xri + c.dxr, dyr = yri + c.dyr, dzr = zri + c.dzr; - double attn = 0.75 - dxr * dxr - dyr * dyr - dzr * dzr; - if (attn < 0) { - c = c.nextOnFailure; - } else { - int pxm = (xrb + c.xrv) & PMASK, pym = (yrb + c.yrv) & PMASK, pzm = (zrb + c.zrv) & PMASK; - Grad3 grad = permGrad3[perm[perm[pxm] ^ pym] ^ pzm]; - double extrapolation = grad.dx * dxr + grad.dy * dyr + grad.dz * dzr; - - attn *= attn; - value += attn * attn * extrapolation; - c = c.nextOnSuccess; - } - } - return value; - } - - /** - * 4D SuperSimplex noise, classic lattice orientation. - * - * @param x - * @param y - * @param z - * @param w - * @return - */ - public double noise4_Classic(double x, double y, double z, double w) { - - // Get points for A4 lattice - double s = 0.309016994374947 * (x + y + z + w); - double xs = x + s, ys = y + s, zs = z + s, ws = w + s; - - return noise4_Base(xs, ys, zs, ws); - } - - /** - * 4D SuperSimplex noise, with XY and ZW forming orthogonal triangular-based - * planes.Recommended for 3D terrain, where X and Y (or Z and W) are - * horizontal.Recommended for noise(x, y, sin(time), cos(time)) trick. - * - * @param x - * @param y - * @param z - * @param w - * @return - */ - public double noise4_XYBeforeZW(double x, double y, double z, double w) { - - double s2 = (x + y) * -0.28522513987434876941 + (z + w) * 0.83897065470611435718; - double t2 = (z + w) * 0.21939749883706435719 + (x + y) * -0.48214856493302476942; - double xs = x + s2, ys = y + s2, zs = z + t2, ws = w + t2; - - return noise4_Base(xs, ys, zs, ws); - } - - /** - * 4D SuperSimplex noise, with XYZ oriented like noise3_Classic, and W for - * an extra degree of freedom.Recommended for time-varied animations which - * texture a 3D object (W=time) - * - * @param x - * @param y - * @param z - * @param w - * @return - */ - public double noise4_XYZBeforeW(double x, double y, double z, double w) { - - double xyz = x + y + z; - double ww = w * 1.118033988749894; - double s2 = xyz * -0.16666666666666666 + ww; - double xs = x + s2, ys = y + s2, zs = z + s2, ws = -0.5 * xyz + ww; - - return noise4_Base(xs, ys, zs, ws); - } - - /** - * 4D SuperSimplex noise base. Using ultra-simple 4x4x4x4 lookup - * partitioning. This isn't as elegant or SIMD/GPU/etc. portable as other - * approaches, but it does compete performance-wise with optimized - * OpenSimplex1. - */ - private double noise4_Base(double xs, double ys, double zs, double ws) { - double value = 0; - - // Get base points and offsets - int xsb = fastFloor(xs), ysb = fastFloor(ys), zsb = fastFloor(zs), wsb = fastFloor(ws); - double xsi = xs - xsb, ysi = ys - ysb, zsi = zs - zsb, wsi = ws - wsb; - - // Unskewed offsets - double ssi = (xsi + ysi + zsi + wsi) * -0.138196601125011; - double xi = xsi + ssi, yi = ysi + ssi, zi = zsi + ssi, wi = wsi + ssi; - - int index = ((fastFloor(xs * 4) & 3)) - | ((fastFloor(ys * 4) & 3) << 2) - | ((fastFloor(zs * 4) & 3) << 4) - | ((fastFloor(ws * 4) & 3) << 6); - - // Point contributions - for (LatticePoint4D c : LOOKUP_4D[index]) { - double dx = xi + c.dx, dy = yi + c.dy, dz = zi + c.dz, dw = wi + c.dw; - double attn = 0.8 - dx * dx - dy * dy - dz * dz - dw * dw; - if (attn > 0) { - attn *= attn; - - int pxm = (xsb + c.xsv) & PMASK, pym = (ysb + c.ysv) & PMASK; - int pzm = (zsb + c.zsv) & PMASK, pwm = (wsb + c.wsv) & PMASK; - Grad4 grad = permGrad4[perm[perm[perm[pxm] ^ pym] ^ pzm] ^ pwm]; - double extrapolation = grad.dx * dx + grad.dy * dy + grad.dz * dz + grad.dw * dw; - - value += attn * attn * extrapolation; - } - } - return value; - } - - /* - * Utility - */ - private static int fastFloor(double x) { - int xi = (int) x; - return x < xi ? xi - 1 : xi; - } - - /* - * Definitions - */ - private static final LatticePoint2D[] LOOKUP_2D; - private static final LatticePoint3D[] LOOKUP_3D; - private static final LatticePoint4D[][] LOOKUP_4D; - - static { - LOOKUP_2D = new LatticePoint2D[8 * 4]; - LOOKUP_3D = new LatticePoint3D[8]; - LOOKUP_4D = new LatticePoint4D[256][]; - - for (int i = 0; i < 8; i++) { - int i1, j1, i2, j2; - if ((i & 1) == 0) { - if ((i & 2) == 0) { - i1 = -1; - j1 = 0; - } else { - i1 = 1; - j1 = 0; - } - if ((i & 4) == 0) { - i2 = 0; - j2 = -1; - } else { - i2 = 0; - j2 = 1; - } - } else { - if ((i & 2) != 0) { - i1 = 2; - j1 = 1; - } else { - i1 = 0; - j1 = 1; - } - if ((i & 4) != 0) { - i2 = 1; - j2 = 2; - } else { - i2 = 1; - j2 = 0; - } - } - LOOKUP_2D[i * 4 + 0] = new LatticePoint2D(0, 0); - LOOKUP_2D[i * 4 + 1] = new LatticePoint2D(1, 1); - LOOKUP_2D[i * 4 + 2] = new LatticePoint2D(i1, j1); - LOOKUP_2D[i * 4 + 3] = new LatticePoint2D(i2, j2); - } - - for (int i = 0; i < 8; i++) { - int i1, j1, k1, i2, j2, k2; - i1 = (i) & 1; - j1 = (i >> 1) & 1; - k1 = (i >> 2) & 1; - i2 = i1 ^ 1; - j2 = j1 ^ 1; - k2 = k1 ^ 1; - - // The two points within this octant, one from each of the two cubic half-lattices. - LatticePoint3D c0 = new LatticePoint3D(i1, j1, k1, 0); - LatticePoint3D c1 = new LatticePoint3D(i1 + i2, j1 + j2, k1 + k2, 1); - - // (1, 0, 0) vs (0, 1, 1) away from octant. - LatticePoint3D c2 = new LatticePoint3D(i1 ^ 1, j1, k1, 0); - LatticePoint3D c3 = new LatticePoint3D(i1, j1 ^ 1, k1 ^ 1, 0); - - // (1, 0, 0) vs (0, 1, 1) away from octant, on second half-lattice. - LatticePoint3D c4 = new LatticePoint3D(i1 + (i2 ^ 1), j1 + j2, k1 + k2, 1); - LatticePoint3D c5 = new LatticePoint3D(i1 + i2, j1 + (j2 ^ 1), k1 + (k2 ^ 1), 1); - - // (0, 1, 0) vs (1, 0, 1) away from octant. - LatticePoint3D c6 = new LatticePoint3D(i1, j1 ^ 1, k1, 0); - LatticePoint3D c7 = new LatticePoint3D(i1 ^ 1, j1, k1 ^ 1, 0); - - // (0, 1, 0) vs (1, 0, 1) away from octant, on second half-lattice. - LatticePoint3D c8 = new LatticePoint3D(i1 + i2, j1 + (j2 ^ 1), k1 + k2, 1); - LatticePoint3D c9 = new LatticePoint3D(i1 + (i2 ^ 1), j1 + j2, k1 + (k2 ^ 1), 1); - - // (0, 0, 1) vs (1, 1, 0) away from octant. - LatticePoint3D cA = new LatticePoint3D(i1, j1, k1 ^ 1, 0); - LatticePoint3D cB = new LatticePoint3D(i1 ^ 1, j1 ^ 1, k1, 0); - - // (0, 0, 1) vs (1, 1, 0) away from octant, on second half-lattice. - LatticePoint3D cC = new LatticePoint3D(i1 + i2, j1 + j2, k1 + (k2 ^ 1), 1); - LatticePoint3D cD = new LatticePoint3D(i1 + (i2 ^ 1), j1 + (j2 ^ 1), k1 + k2, 1); - - // First two points are guaranteed. - c0.nextOnFailure = c0.nextOnSuccess = c1; - c1.nextOnFailure = c1.nextOnSuccess = c2; - - // If c2 is in range, then we know c3 and c4 are not. - c2.nextOnFailure = c3; - c2.nextOnSuccess = c5; - c3.nextOnFailure = c4; - c3.nextOnSuccess = c4; - - // If c4 is in range, then we know c5 is not. - c4.nextOnFailure = c5; - c4.nextOnSuccess = c6; - c5.nextOnFailure = c5.nextOnSuccess = c6; - - // If c6 is in range, then we know c7 and c8 are not. - c6.nextOnFailure = c7; - c6.nextOnSuccess = c9; - c7.nextOnFailure = c8; - c7.nextOnSuccess = c8; - - // If c8 is in range, then we know c9 is not. - c8.nextOnFailure = c9; - c8.nextOnSuccess = cA; - c9.nextOnFailure = c9.nextOnSuccess = cA; - - // If cA is in range, then we know cB and cC are not. - cA.nextOnFailure = cB; - cA.nextOnSuccess = cD; - cB.nextOnFailure = cC; - cB.nextOnSuccess = cC; - - // If cC is in range, then we know cD is not. - cC.nextOnFailure = cD; - cC.nextOnSuccess = null; - cD.nextOnFailure = cD.nextOnSuccess = null; - - LOOKUP_3D[i] = c0; - } - - int[][] lookup4DPregen = { - {0x15, 0x45, 0x51, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x15, 0x45, 0x51, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA6, 0xAA}, - {0x01, 0x05, 0x11, 0x15, 0x41, 0x45, 0x51, 0x55, 0x56, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xA6, 0xAA}, - {0x01, 0x15, 0x16, 0x45, 0x46, 0x51, 0x52, 0x55, 0x56, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x15, 0x45, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA9, 0xAA}, - {0x05, 0x15, 0x45, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xAA}, - {0x05, 0x15, 0x45, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xAA}, - {0x05, 0x15, 0x16, 0x45, 0x46, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xAA, 0xAB}, - {0x04, 0x05, 0x14, 0x15, 0x44, 0x45, 0x54, 0x55, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA}, - {0x05, 0x15, 0x45, 0x55, 0x56, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xAA}, - {0x05, 0x15, 0x45, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x9A, 0xAA}, - {0x05, 0x15, 0x16, 0x45, 0x46, 0x55, 0x56, 0x59, 0x5A, 0x5B, 0x6A, 0x9A, 0xAA, 0xAB}, - {0x04, 0x15, 0x19, 0x45, 0x49, 0x54, 0x55, 0x58, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x05, 0x15, 0x19, 0x45, 0x49, 0x55, 0x56, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xAA, 0xAE}, - {0x05, 0x15, 0x19, 0x45, 0x49, 0x55, 0x56, 0x59, 0x5A, 0x5E, 0x6A, 0x9A, 0xAA, 0xAE}, - {0x05, 0x15, 0x1A, 0x45, 0x4A, 0x55, 0x56, 0x59, 0x5A, 0x5B, 0x5E, 0x6A, 0x9A, 0xAA, 0xAB, 0xAE, 0xAF}, - {0x15, 0x51, 0x54, 0x55, 0x56, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x95, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x11, 0x15, 0x51, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0xA5, 0xA6, 0xAA}, - {0x11, 0x15, 0x51, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x6A, 0x96, 0xA6, 0xAA}, - {0x11, 0x15, 0x16, 0x51, 0x52, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x6A, 0x96, 0xA6, 0xAA, 0xAB}, - {0x14, 0x15, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x99, 0xA5, 0xA9, 0xAA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x9A, 0xA6, 0xA9, 0xAA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x15, 0x16, 0x55, 0x56, 0x5A, 0x66, 0x6A, 0x6B, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x14, 0x15, 0x54, 0x55, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x99, 0xA9, 0xAA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x9A, 0xAA}, - {0x15, 0x16, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x6A, 0x6B, 0x9A, 0xAA, 0xAB}, - {0x14, 0x15, 0x19, 0x54, 0x55, 0x58, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x99, 0xA9, 0xAA, 0xAE}, - {0x15, 0x19, 0x55, 0x59, 0x5A, 0x69, 0x6A, 0x6E, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x15, 0x19, 0x55, 0x56, 0x59, 0x5A, 0x69, 0x6A, 0x6E, 0x9A, 0xAA, 0xAE}, - {0x15, 0x1A, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x6B, 0x6E, 0x9A, 0xAA, 0xAB, 0xAE, 0xAF}, - {0x10, 0x11, 0x14, 0x15, 0x50, 0x51, 0x54, 0x55, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x11, 0x15, 0x51, 0x55, 0x56, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xAA}, - {0x11, 0x15, 0x51, 0x55, 0x56, 0x65, 0x66, 0x6A, 0xA6, 0xAA}, - {0x11, 0x15, 0x16, 0x51, 0x52, 0x55, 0x56, 0x65, 0x66, 0x67, 0x6A, 0xA6, 0xAA, 0xAB}, - {0x14, 0x15, 0x54, 0x55, 0x59, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA9, 0xAA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xA6, 0xAA}, - {0x15, 0x16, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x6A, 0x6B, 0xA6, 0xAA, 0xAB}, - {0x14, 0x15, 0x54, 0x55, 0x59, 0x65, 0x69, 0x6A, 0xA9, 0xAA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xA9, 0xAA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xAA}, - {0x15, 0x16, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x6B, 0xAA, 0xAB}, - {0x14, 0x15, 0x19, 0x54, 0x55, 0x58, 0x59, 0x65, 0x69, 0x6A, 0x6D, 0xA9, 0xAA, 0xAE}, - {0x15, 0x19, 0x55, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x6E, 0xA9, 0xAA, 0xAE}, - {0x15, 0x19, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x6E, 0xAA, 0xAE}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x69, 0x6A, 0x6B, 0x6E, 0x9A, 0xAA, 0xAB, 0xAE, 0xAF}, - {0x10, 0x15, 0x25, 0x51, 0x54, 0x55, 0x61, 0x64, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x11, 0x15, 0x25, 0x51, 0x55, 0x56, 0x61, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xAA, 0xBA}, - {0x11, 0x15, 0x25, 0x51, 0x55, 0x56, 0x61, 0x65, 0x66, 0x6A, 0x76, 0xA6, 0xAA, 0xBA}, - {0x11, 0x15, 0x26, 0x51, 0x55, 0x56, 0x62, 0x65, 0x66, 0x67, 0x6A, 0x76, 0xA6, 0xAA, 0xAB, 0xBA, 0xBB}, - {0x14, 0x15, 0x25, 0x54, 0x55, 0x59, 0x64, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA9, 0xAA, 0xBA}, - {0x15, 0x25, 0x55, 0x65, 0x66, 0x69, 0x6A, 0x7A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x15, 0x25, 0x55, 0x56, 0x65, 0x66, 0x69, 0x6A, 0x7A, 0xA6, 0xAA, 0xBA}, - {0x15, 0x26, 0x55, 0x56, 0x65, 0x66, 0x6A, 0x6B, 0x7A, 0xA6, 0xAA, 0xAB, 0xBA, 0xBB}, - {0x14, 0x15, 0x25, 0x54, 0x55, 0x59, 0x64, 0x65, 0x69, 0x6A, 0x79, 0xA9, 0xAA, 0xBA}, - {0x15, 0x25, 0x55, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x7A, 0xA9, 0xAA, 0xBA}, - {0x15, 0x25, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x7A, 0xAA, 0xBA}, - {0x15, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x6B, 0x7A, 0xA6, 0xAA, 0xAB, 0xBA, 0xBB}, - {0x14, 0x15, 0x29, 0x54, 0x55, 0x59, 0x65, 0x68, 0x69, 0x6A, 0x6D, 0x79, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, - {0x15, 0x29, 0x55, 0x59, 0x65, 0x69, 0x6A, 0x6E, 0x7A, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, - {0x15, 0x55, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x6E, 0x7A, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x6B, 0x6E, 0x7A, 0xAA, 0xAB, 0xAE, 0xBA, 0xBF}, - {0x45, 0x51, 0x54, 0x55, 0x56, 0x59, 0x65, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x41, 0x45, 0x51, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xAA}, - {0x41, 0x45, 0x51, 0x55, 0x56, 0x5A, 0x66, 0x95, 0x96, 0x9A, 0xA6, 0xAA}, - {0x41, 0x45, 0x46, 0x51, 0x52, 0x55, 0x56, 0x5A, 0x66, 0x95, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x44, 0x45, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x69, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA9, 0xAA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xA9, 0xAA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x45, 0x46, 0x55, 0x56, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0x9B, 0xA6, 0xAA, 0xAB}, - {0x44, 0x45, 0x54, 0x55, 0x59, 0x5A, 0x69, 0x95, 0x99, 0x9A, 0xA9, 0xAA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xAA}, - {0x45, 0x46, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x96, 0x9A, 0x9B, 0xAA, 0xAB}, - {0x44, 0x45, 0x49, 0x54, 0x55, 0x58, 0x59, 0x5A, 0x69, 0x95, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x45, 0x49, 0x55, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0x9E, 0xA9, 0xAA, 0xAE}, - {0x45, 0x49, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x99, 0x9A, 0x9E, 0xAA, 0xAE}, - {0x45, 0x4A, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x9A, 0x9B, 0x9E, 0xAA, 0xAB, 0xAE, 0xAF}, - {0x50, 0x51, 0x54, 0x55, 0x56, 0x59, 0x65, 0x66, 0x69, 0x95, 0x96, 0x99, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x51, 0x55, 0x56, 0x59, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x51, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xAA, 0xAB}, - {0x51, 0x52, 0x55, 0x56, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xA6, 0xA7, 0xAA, 0xAB}, - {0x54, 0x55, 0x56, 0x59, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x15, 0x45, 0x51, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x55, 0x56, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x54, 0x55, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA5, 0xA9, 0xAA, 0xAE}, - {0x15, 0x45, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x15, 0x45, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xA9, 0xAA, 0xAB, 0xAE}, - {0x55, 0x56, 0x59, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x54, 0x55, 0x58, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAD, 0xAE}, - {0x55, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x55, 0x56, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x55, 0x56, 0x59, 0x5A, 0x6A, 0x9A, 0xAA, 0xAB, 0xAE, 0xAF}, - {0x50, 0x51, 0x54, 0x55, 0x65, 0x66, 0x69, 0x95, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x6A, 0x95, 0x96, 0xA5, 0xA6, 0xAA}, - {0x51, 0x52, 0x55, 0x56, 0x65, 0x66, 0x6A, 0x96, 0xA6, 0xA7, 0xAA, 0xAB}, - {0x54, 0x55, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x99, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x15, 0x51, 0x54, 0x55, 0x56, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x15, 0x51, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAB, 0xBA}, - {0x55, 0x56, 0x5A, 0x65, 0x66, 0x6A, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x6A, 0x95, 0x99, 0xA5, 0xA9, 0xAA}, - {0x15, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAE, 0xBA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x9A, 0xA6, 0xA9, 0xAA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x54, 0x55, 0x58, 0x59, 0x65, 0x69, 0x6A, 0x99, 0xA9, 0xAA, 0xAD, 0xAE}, - {0x55, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x69, 0x6A, 0x9A, 0xAA, 0xAB, 0xAE, 0xAF}, - {0x50, 0x51, 0x54, 0x55, 0x61, 0x64, 0x65, 0x66, 0x69, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x51, 0x55, 0x61, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xB6, 0xBA}, - {0x51, 0x55, 0x56, 0x61, 0x65, 0x66, 0x6A, 0xA5, 0xA6, 0xAA, 0xB6, 0xBA}, - {0x51, 0x55, 0x56, 0x62, 0x65, 0x66, 0x6A, 0xA6, 0xA7, 0xAA, 0xAB, 0xB6, 0xBA, 0xBB}, - {0x54, 0x55, 0x64, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xB9, 0xBA}, - {0x55, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x55, 0x56, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x55, 0x56, 0x65, 0x66, 0x6A, 0xA6, 0xAA, 0xAB, 0xBA, 0xBB}, - {0x54, 0x55, 0x59, 0x64, 0x65, 0x69, 0x6A, 0xA5, 0xA9, 0xAA, 0xB9, 0xBA}, - {0x55, 0x59, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x15, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xA6, 0xAA, 0xAB, 0xBA, 0xBB}, - {0x54, 0x55, 0x59, 0x65, 0x68, 0x69, 0x6A, 0xA9, 0xAA, 0xAD, 0xAE, 0xB9, 0xBA, 0xBE}, - {0x55, 0x59, 0x65, 0x69, 0x6A, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, - {0x15, 0x55, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, - {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xAA, 0xAB, 0xAE, 0xBA, 0xBF}, - {0x40, 0x41, 0x44, 0x45, 0x50, 0x51, 0x54, 0x55, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x41, 0x45, 0x51, 0x55, 0x56, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xAA}, - {0x41, 0x45, 0x51, 0x55, 0x56, 0x95, 0x96, 0x9A, 0xA6, 0xAA}, - {0x41, 0x45, 0x46, 0x51, 0x52, 0x55, 0x56, 0x95, 0x96, 0x97, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x44, 0x45, 0x54, 0x55, 0x59, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA9, 0xAA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xAA}, - {0x45, 0x46, 0x55, 0x56, 0x5A, 0x95, 0x96, 0x9A, 0x9B, 0xA6, 0xAA, 0xAB}, - {0x44, 0x45, 0x54, 0x55, 0x59, 0x95, 0x99, 0x9A, 0xA9, 0xAA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xA9, 0xAA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xAA}, - {0x45, 0x46, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0x9B, 0xAA, 0xAB}, - {0x44, 0x45, 0x49, 0x54, 0x55, 0x58, 0x59, 0x95, 0x99, 0x9A, 0x9D, 0xA9, 0xAA, 0xAE}, - {0x45, 0x49, 0x55, 0x59, 0x5A, 0x95, 0x99, 0x9A, 0x9E, 0xA9, 0xAA, 0xAE}, - {0x45, 0x49, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0x9E, 0xAA, 0xAE}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x96, 0x99, 0x9A, 0x9B, 0x9E, 0xAA, 0xAB, 0xAE, 0xAF}, - {0x50, 0x51, 0x54, 0x55, 0x65, 0x95, 0x96, 0x99, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xAA}, - {0x51, 0x52, 0x55, 0x56, 0x66, 0x95, 0x96, 0x9A, 0xA6, 0xA7, 0xAA, 0xAB}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x45, 0x51, 0x54, 0x55, 0x56, 0x59, 0x65, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x45, 0x51, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAB, 0xEA}, - {0x55, 0x56, 0x5A, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x95, 0x99, 0x9A, 0xA5, 0xA9, 0xAA}, - {0x45, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAE, 0xEA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xA9, 0xAA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x54, 0x55, 0x58, 0x59, 0x69, 0x95, 0x99, 0x9A, 0xA9, 0xAA, 0xAD, 0xAE}, - {0x55, 0x59, 0x5A, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x96, 0x99, 0x9A, 0xAA, 0xAB, 0xAE, 0xAF}, - {0x50, 0x51, 0x54, 0x55, 0x65, 0x95, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xAA}, - {0x51, 0x52, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xA7, 0xAA, 0xAB}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x51, 0x54, 0x55, 0x56, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA, 0xEA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x51, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xAA, 0xAB}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA9, 0xAA}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA6, 0xA9, 0xAA, 0xAB}, - {0x54, 0x55, 0x58, 0x59, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA9, 0xAA, 0xAD, 0xAE}, - {0x54, 0x55, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA5, 0xA9, 0xAA, 0xAE}, - {0x55, 0x56, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA6, 0xA9, 0xAA, 0xAE}, - {0x55, 0x56, 0x59, 0x5A, 0x66, 0x69, 0x6A, 0x96, 0x99, 0x9A, 0xA6, 0xA9, 0xAA, 0xAB, 0xAE, 0xAF}, - {0x50, 0x51, 0x54, 0x55, 0x61, 0x64, 0x65, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xB5, 0xBA}, - {0x51, 0x55, 0x61, 0x65, 0x66, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xB6, 0xBA}, - {0x51, 0x55, 0x56, 0x61, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xAA, 0xB6, 0xBA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x6A, 0x96, 0xA5, 0xA6, 0xA7, 0xAA, 0xAB, 0xB6, 0xBA, 0xBB}, - {0x54, 0x55, 0x64, 0x65, 0x69, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xB9, 0xBA}, - {0x55, 0x65, 0x66, 0x69, 0x6A, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x6A, 0x96, 0xA5, 0xA6, 0xAA, 0xAB, 0xBA, 0xBB}, - {0x54, 0x55, 0x59, 0x64, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA9, 0xAA, 0xB9, 0xBA}, - {0x54, 0x55, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x99, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x55, 0x56, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x55, 0x56, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x96, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAB, 0xBA, 0xBB}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x6A, 0x99, 0xA5, 0xA9, 0xAA, 0xAD, 0xAE, 0xB9, 0xBA, 0xBE}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x6A, 0x99, 0xA5, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, - {0x55, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, - {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x9A, 0xA6, 0xA9, 0xAA, 0xAB, 0xAE, 0xBA}, - {0x40, 0x45, 0x51, 0x54, 0x55, 0x85, 0x91, 0x94, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x41, 0x45, 0x51, 0x55, 0x56, 0x85, 0x91, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xAA, 0xEA}, - {0x41, 0x45, 0x51, 0x55, 0x56, 0x85, 0x91, 0x95, 0x96, 0x9A, 0xA6, 0xAA, 0xD6, 0xEA}, - {0x41, 0x45, 0x51, 0x55, 0x56, 0x86, 0x92, 0x95, 0x96, 0x97, 0x9A, 0xA6, 0xAA, 0xAB, 0xD6, 0xEA, 0xEB}, - {0x44, 0x45, 0x54, 0x55, 0x59, 0x85, 0x94, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA9, 0xAA, 0xEA}, - {0x45, 0x55, 0x85, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xDA, 0xEA}, - {0x45, 0x55, 0x56, 0x85, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xAA, 0xDA, 0xEA}, - {0x45, 0x55, 0x56, 0x86, 0x95, 0x96, 0x9A, 0x9B, 0xA6, 0xAA, 0xAB, 0xDA, 0xEA, 0xEB}, - {0x44, 0x45, 0x54, 0x55, 0x59, 0x85, 0x94, 0x95, 0x99, 0x9A, 0xA9, 0xAA, 0xD9, 0xEA}, - {0x45, 0x55, 0x59, 0x85, 0x95, 0x96, 0x99, 0x9A, 0xA9, 0xAA, 0xDA, 0xEA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x85, 0x95, 0x96, 0x99, 0x9A, 0xAA, 0xDA, 0xEA}, - {0x45, 0x55, 0x56, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0x9B, 0xA6, 0xAA, 0xAB, 0xDA, 0xEA, 0xEB}, - {0x44, 0x45, 0x54, 0x55, 0x59, 0x89, 0x95, 0x98, 0x99, 0x9A, 0x9D, 0xA9, 0xAA, 0xAE, 0xD9, 0xEA, 0xEE}, - {0x45, 0x55, 0x59, 0x89, 0x95, 0x99, 0x9A, 0x9E, 0xA9, 0xAA, 0xAE, 0xDA, 0xEA, 0xEE}, - {0x45, 0x55, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0x9E, 0xA9, 0xAA, 0xAE, 0xDA, 0xEA, 0xEE}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0x9B, 0x9E, 0xAA, 0xAB, 0xAE, 0xDA, 0xEA, 0xEF}, - {0x50, 0x51, 0x54, 0x55, 0x65, 0x91, 0x94, 0x95, 0x96, 0x99, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x51, 0x55, 0x91, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xE6, 0xEA}, - {0x51, 0x55, 0x56, 0x91, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xAA, 0xE6, 0xEA}, - {0x51, 0x55, 0x56, 0x92, 0x95, 0x96, 0x9A, 0xA6, 0xA7, 0xAA, 0xAB, 0xE6, 0xEA, 0xEB}, - {0x54, 0x55, 0x94, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xE9, 0xEA}, - {0x55, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x55, 0x56, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x55, 0x56, 0x95, 0x96, 0x9A, 0xA6, 0xAA, 0xAB, 0xEA, 0xEB}, - {0x54, 0x55, 0x59, 0x94, 0x95, 0x99, 0x9A, 0xA5, 0xA9, 0xAA, 0xE9, 0xEA}, - {0x55, 0x59, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x45, 0x55, 0x56, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xAA, 0xAB, 0xEA, 0xEB}, - {0x54, 0x55, 0x59, 0x95, 0x98, 0x99, 0x9A, 0xA9, 0xAA, 0xAD, 0xAE, 0xE9, 0xEA, 0xEE}, - {0x55, 0x59, 0x95, 0x99, 0x9A, 0xA9, 0xAA, 0xAE, 0xEA, 0xEE}, - {0x45, 0x55, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xA9, 0xAA, 0xAE, 0xEA, 0xEE}, - {0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xAA, 0xAB, 0xAE, 0xEA, 0xEF}, - {0x50, 0x51, 0x54, 0x55, 0x65, 0x91, 0x94, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xE5, 0xEA}, - {0x51, 0x55, 0x65, 0x91, 0x95, 0x96, 0xA5, 0xA6, 0xA9, 0xAA, 0xE6, 0xEA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x91, 0x95, 0x96, 0xA5, 0xA6, 0xAA, 0xE6, 0xEA}, - {0x51, 0x55, 0x56, 0x66, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xA7, 0xAA, 0xAB, 0xE6, 0xEA, 0xEB}, - {0x54, 0x55, 0x65, 0x94, 0x95, 0x99, 0xA5, 0xA6, 0xA9, 0xAA, 0xE9, 0xEA}, - {0x55, 0x65, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x51, 0x55, 0x56, 0x66, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xAA, 0xAB, 0xEA, 0xEB}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x94, 0x95, 0x99, 0xA5, 0xA9, 0xAA, 0xE9, 0xEA}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x55, 0x56, 0x59, 0x65, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x55, 0x56, 0x5A, 0x66, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAB, 0xEA, 0xEB}, - {0x54, 0x55, 0x59, 0x69, 0x95, 0x99, 0x9A, 0xA5, 0xA9, 0xAA, 0xAD, 0xAE, 0xE9, 0xEA, 0xEE}, - {0x54, 0x55, 0x59, 0x69, 0x95, 0x99, 0x9A, 0xA5, 0xA9, 0xAA, 0xAE, 0xEA, 0xEE}, - {0x55, 0x59, 0x5A, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAE, 0xEA, 0xEE}, - {0x55, 0x56, 0x59, 0x5A, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xA9, 0xAA, 0xAB, 0xAE, 0xEA}, - {0x50, 0x51, 0x54, 0x55, 0x65, 0x95, 0xA1, 0xA4, 0xA5, 0xA6, 0xA9, 0xAA, 0xB5, 0xBA, 0xE5, 0xEA, 0xFA}, - {0x51, 0x55, 0x65, 0x95, 0xA1, 0xA5, 0xA6, 0xA9, 0xAA, 0xB6, 0xBA, 0xE6, 0xEA, 0xFA}, - {0x51, 0x55, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xA9, 0xAA, 0xB6, 0xBA, 0xE6, 0xEA, 0xFA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xA7, 0xAA, 0xAB, 0xB6, 0xBA, 0xE6, 0xEA, 0xFB}, - {0x54, 0x55, 0x65, 0x95, 0xA4, 0xA5, 0xA6, 0xA9, 0xAA, 0xB9, 0xBA, 0xE9, 0xEA, 0xFA}, - {0x55, 0x65, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA, 0xEA, 0xFA}, - {0x51, 0x55, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA, 0xEA, 0xFA}, - {0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xAA, 0xAB, 0xBA, 0xEA, 0xFB}, - {0x54, 0x55, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA6, 0xA9, 0xAA, 0xB9, 0xBA, 0xE9, 0xEA, 0xFA}, - {0x54, 0x55, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA, 0xEA, 0xFA}, - {0x55, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA, 0xEA, 0xFA}, - {0x55, 0x56, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAB, 0xBA, 0xEA}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA9, 0xAA, 0xAD, 0xAE, 0xB9, 0xBA, 0xE9, 0xEA, 0xFE}, - {0x55, 0x59, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA9, 0xAA, 0xAE, 0xBA, 0xEA, 0xFE}, - {0x55, 0x59, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAE, 0xBA, 0xEA}, - {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAB, 0xAE, 0xBA, 0xEA},}; - LatticePoint4D[] latticePoints = new LatticePoint4D[256]; - for (int i = 0; i < 256; i++) { - int cx = ((i) & 3) - 1; - int cy = ((i >> 2) & 3) - 1; - int cz = ((i >> 4) & 3) - 1; - int cw = ((i >> 6) & 3) - 1; - latticePoints[i] = new LatticePoint4D(cx, cy, cz, cw); - } - for (int i = 0; i < 256; i++) { - LOOKUP_4D[i] = new LatticePoint4D[lookup4DPregen[i].length]; - for (int j = 0; j < lookup4DPregen[i].length; j++) { - LOOKUP_4D[i][j] = latticePoints[lookup4DPregen[i][j]]; - } - } - } - - @Override - public float noise(float x, float y, float z) { - return (float) noise3_Classic(x, y, z); - } - - @Override - public float noise(float x, float y, float z, float w) { - return (float) noise4_Classic(x, y, z, w); - } - - @Override - public void noiseMode(NoiseMode mode) { - - } - - @Override - public void noiseSeed(long seed) { - - } - - private static class LatticePoint2D { - - int xsv, ysv; - double dx, dy; - - public LatticePoint2D(int xsv, int ysv) { - this.xsv = xsv; - this.ysv = ysv; - double ssv = (xsv + ysv) * -0.211324865405187; - this.dx = -xsv - ssv; - this.dy = -ysv - ssv; - } - } - - private static class LatticePoint3D { - - public double dxr, dyr, dzr; - public int xrv, yrv, zrv; - LatticePoint3D nextOnFailure, nextOnSuccess; - - public LatticePoint3D(int xrv, int yrv, int zrv, int lattice) { - this.dxr = -xrv + lattice * 0.5; - this.dyr = -yrv + lattice * 0.5; - this.dzr = -zrv + lattice * 0.5; - this.xrv = xrv + lattice * 1024; - this.yrv = yrv + lattice * 1024; - this.zrv = zrv + lattice * 1024; - } - } - - private static class LatticePoint4D { - - int xsv, ysv, zsv, wsv; - double dx, dy, dz, dw; - - public LatticePoint4D(int xsv, int ysv, int zsv, int wsv) { - this.xsv = xsv; - this.ysv = ysv; - this.zsv = zsv; - this.wsv = wsv; - double ssv = (xsv + ysv + zsv + wsv) * -0.138196601125011; - this.dx = -xsv - ssv; - this.dy = -ysv - ssv; - this.dz = -zsv - ssv; - this.dw = -wsv - ssv; - } - } - - /* - * Gradients - */ - private static class Grad2 { - - double dx, dy; - - public Grad2(double dx, double dy) { - this.dx = dx; - this.dy = dy; - } - } - - private static class Grad3 { - - double dx, dy, dz; - - public Grad3(double dx, double dy, double dz) { - this.dx = dx; - this.dy = dy; - this.dz = dz; - } - } - - private static class Grad4 { - - double dx, dy, dz, dw; - - public Grad4(double dx, double dy, double dz, double dw) { - this.dx = dx; - this.dy = dy; - this.dz = dz; - this.dw = dw; - } - } - - private static final double N2 = 0.05481866495625118; - private static final double N3 = 0.2781926117527186; - private static final double N4 = 0.11127401889945551; - private static final Grad2[] GRADIENTS_2D; - private static final Grad3[] GRADIENTS_3D; - private static final Grad4[] GRADIENTS_4D; - - static { - - GRADIENTS_2D = new Grad2[PSIZE]; - Grad2[] grad2 = { - new Grad2(0.130526192220052, 0.99144486137381), - new Grad2(0.38268343236509, 0.923879532511287), - new Grad2(0.608761429008721, 0.793353340291235), - new Grad2(0.793353340291235, 0.608761429008721), - new Grad2(0.923879532511287, 0.38268343236509), - new Grad2(0.99144486137381, 0.130526192220051), - new Grad2(0.99144486137381, -0.130526192220051), - new Grad2(0.923879532511287, -0.38268343236509), - new Grad2(0.793353340291235, -0.60876142900872), - new Grad2(0.608761429008721, -0.793353340291235), - new Grad2(0.38268343236509, -0.923879532511287), - new Grad2(0.130526192220052, -0.99144486137381), - new Grad2(-0.130526192220052, -0.99144486137381), - new Grad2(-0.38268343236509, -0.923879532511287), - new Grad2(-0.608761429008721, -0.793353340291235), - new Grad2(-0.793353340291235, -0.608761429008721), - new Grad2(-0.923879532511287, -0.38268343236509), - new Grad2(-0.99144486137381, -0.130526192220052), - new Grad2(-0.99144486137381, 0.130526192220051), - new Grad2(-0.923879532511287, 0.38268343236509), - new Grad2(-0.793353340291235, 0.608761429008721), - new Grad2(-0.608761429008721, 0.793353340291235), - new Grad2(-0.38268343236509, 0.923879532511287), - new Grad2(-0.130526192220052, 0.99144486137381) - }; - Grad2[] grad2XBeforeY = new Grad2[grad2.length]; - for (Grad2 grad21 : grad2) { - grad21.dx /= N2; - grad21.dy /= N2; - } - for (int i = 0; i < PSIZE; i++) { - GRADIENTS_2D[i] = grad2[i % grad2.length]; - } - - GRADIENTS_3D = new Grad3[PSIZE]; - Grad3[] grad3 = { - new Grad3(-2.22474487139, -2.22474487139, -1.0), - new Grad3(-2.22474487139, -2.22474487139, 1.0), - new Grad3(-3.0862664687972017, -1.1721513422464978, 0.0), - new Grad3(-1.1721513422464978, -3.0862664687972017, 0.0), - new Grad3(-2.22474487139, -1.0, -2.22474487139), - new Grad3(-2.22474487139, 1.0, -2.22474487139), - new Grad3(-1.1721513422464978, 0.0, -3.0862664687972017), - new Grad3(-3.0862664687972017, 0.0, -1.1721513422464978), - new Grad3(-2.22474487139, -1.0, 2.22474487139), - new Grad3(-2.22474487139, 1.0, 2.22474487139), - new Grad3(-3.0862664687972017, 0.0, 1.1721513422464978), - new Grad3(-1.1721513422464978, 0.0, 3.0862664687972017), - new Grad3(-2.22474487139, 2.22474487139, -1.0), - new Grad3(-2.22474487139, 2.22474487139, 1.0), - new Grad3(-1.1721513422464978, 3.0862664687972017, 0.0), - new Grad3(-3.0862664687972017, 1.1721513422464978, 0.0), - new Grad3(-1.0, -2.22474487139, -2.22474487139), - new Grad3(1.0, -2.22474487139, -2.22474487139), - new Grad3(0.0, -3.0862664687972017, -1.1721513422464978), - new Grad3(0.0, -1.1721513422464978, -3.0862664687972017), - new Grad3(-1.0, -2.22474487139, 2.22474487139), - new Grad3(1.0, -2.22474487139, 2.22474487139), - new Grad3(0.0, -1.1721513422464978, 3.0862664687972017), - new Grad3(0.0, -3.0862664687972017, 1.1721513422464978), - new Grad3(-1.0, 2.22474487139, -2.22474487139), - new Grad3(1.0, 2.22474487139, -2.22474487139), - new Grad3(0.0, 1.1721513422464978, -3.0862664687972017), - new Grad3(0.0, 3.0862664687972017, -1.1721513422464978), - new Grad3(-1.0, 2.22474487139, 2.22474487139), - new Grad3(1.0, 2.22474487139, 2.22474487139), - new Grad3(0.0, 3.0862664687972017, 1.1721513422464978), - new Grad3(0.0, 1.1721513422464978, 3.0862664687972017), - new Grad3(2.22474487139, -2.22474487139, -1.0), - new Grad3(2.22474487139, -2.22474487139, 1.0), - new Grad3(1.1721513422464978, -3.0862664687972017, 0.0), - new Grad3(3.0862664687972017, -1.1721513422464978, 0.0), - new Grad3(2.22474487139, -1.0, -2.22474487139), - new Grad3(2.22474487139, 1.0, -2.22474487139), - new Grad3(3.0862664687972017, 0.0, -1.1721513422464978), - new Grad3(1.1721513422464978, 0.0, -3.0862664687972017), - new Grad3(2.22474487139, -1.0, 2.22474487139), - new Grad3(2.22474487139, 1.0, 2.22474487139), - new Grad3(1.1721513422464978, 0.0, 3.0862664687972017), - new Grad3(3.0862664687972017, 0.0, 1.1721513422464978), - new Grad3(2.22474487139, 2.22474487139, -1.0), - new Grad3(2.22474487139, 2.22474487139, 1.0), - new Grad3(3.0862664687972017, 1.1721513422464978, 0.0), - new Grad3(1.1721513422464978, 3.0862664687972017, 0.0) - }; - for (Grad3 grad31 : grad3) { - grad31.dx /= N3; - grad31.dy /= N3; - grad31.dz /= N3; - } - for (int i = 0; i < PSIZE; i++) { - GRADIENTS_3D[i] = grad3[i % grad3.length]; - } - - GRADIENTS_4D = new Grad4[PSIZE]; - Grad4[] grad4 = { - new Grad4(-0.753341017856078, -0.37968289875261624, -0.37968289875261624, -0.37968289875261624), - new Grad4(-0.7821684431180708, -0.4321472685365301, -0.4321472685365301, 0.12128480194602098), - new Grad4(-0.7821684431180708, -0.4321472685365301, 0.12128480194602098, -0.4321472685365301), - new Grad4(-0.7821684431180708, 0.12128480194602098, -0.4321472685365301, -0.4321472685365301), - new Grad4(-0.8586508742123365, -0.508629699630796, 0.044802370851755174, 0.044802370851755174), - new Grad4(-0.8586508742123365, 0.044802370851755174, -0.508629699630796, 0.044802370851755174), - new Grad4(-0.8586508742123365, 0.044802370851755174, 0.044802370851755174, -0.508629699630796), - new Grad4(-0.9982828964265062, -0.03381941603233842, -0.03381941603233842, -0.03381941603233842), - new Grad4(-0.37968289875261624, -0.753341017856078, -0.37968289875261624, -0.37968289875261624), - new Grad4(-0.4321472685365301, -0.7821684431180708, -0.4321472685365301, 0.12128480194602098), - new Grad4(-0.4321472685365301, -0.7821684431180708, 0.12128480194602098, -0.4321472685365301), - new Grad4(0.12128480194602098, -0.7821684431180708, -0.4321472685365301, -0.4321472685365301), - new Grad4(-0.508629699630796, -0.8586508742123365, 0.044802370851755174, 0.044802370851755174), - new Grad4(0.044802370851755174, -0.8586508742123365, -0.508629699630796, 0.044802370851755174), - new Grad4(0.044802370851755174, -0.8586508742123365, 0.044802370851755174, -0.508629699630796), - new Grad4(-0.03381941603233842, -0.9982828964265062, -0.03381941603233842, -0.03381941603233842), - new Grad4(-0.37968289875261624, -0.37968289875261624, -0.753341017856078, -0.37968289875261624), - new Grad4(-0.4321472685365301, -0.4321472685365301, -0.7821684431180708, 0.12128480194602098), - new Grad4(-0.4321472685365301, 0.12128480194602098, -0.7821684431180708, -0.4321472685365301), - new Grad4(0.12128480194602098, -0.4321472685365301, -0.7821684431180708, -0.4321472685365301), - new Grad4(-0.508629699630796, 0.044802370851755174, -0.8586508742123365, 0.044802370851755174), - new Grad4(0.044802370851755174, -0.508629699630796, -0.8586508742123365, 0.044802370851755174), - new Grad4(0.044802370851755174, 0.044802370851755174, -0.8586508742123365, -0.508629699630796), - new Grad4(-0.03381941603233842, -0.03381941603233842, -0.9982828964265062, -0.03381941603233842), - new Grad4(-0.37968289875261624, -0.37968289875261624, -0.37968289875261624, -0.753341017856078), - new Grad4(-0.4321472685365301, -0.4321472685365301, 0.12128480194602098, -0.7821684431180708), - new Grad4(-0.4321472685365301, 0.12128480194602098, -0.4321472685365301, -0.7821684431180708), - new Grad4(0.12128480194602098, -0.4321472685365301, -0.4321472685365301, -0.7821684431180708), - new Grad4(-0.508629699630796, 0.044802370851755174, 0.044802370851755174, -0.8586508742123365), - new Grad4(0.044802370851755174, -0.508629699630796, 0.044802370851755174, -0.8586508742123365), - new Grad4(0.044802370851755174, 0.044802370851755174, -0.508629699630796, -0.8586508742123365), - new Grad4(-0.03381941603233842, -0.03381941603233842, -0.03381941603233842, -0.9982828964265062), - new Grad4(-0.6740059517812944, -0.3239847771997537, -0.3239847771997537, 0.5794684678643381), - new Grad4(-0.7504883828755602, -0.4004672082940195, 0.15296486218853164, 0.5029860367700724), - new Grad4(-0.7504883828755602, 0.15296486218853164, -0.4004672082940195, 0.5029860367700724), - new Grad4(-0.8828161875373585, 0.08164729285680945, 0.08164729285680945, 0.4553054119602712), - new Grad4(-0.4553054119602712, -0.08164729285680945, -0.08164729285680945, 0.8828161875373585), - new Grad4(-0.5029860367700724, -0.15296486218853164, 0.4004672082940195, 0.7504883828755602), - new Grad4(-0.5029860367700724, 0.4004672082940195, -0.15296486218853164, 0.7504883828755602), - new Grad4(-0.5794684678643381, 0.3239847771997537, 0.3239847771997537, 0.6740059517812944), - new Grad4(-0.3239847771997537, -0.6740059517812944, -0.3239847771997537, 0.5794684678643381), - new Grad4(-0.4004672082940195, -0.7504883828755602, 0.15296486218853164, 0.5029860367700724), - new Grad4(0.15296486218853164, -0.7504883828755602, -0.4004672082940195, 0.5029860367700724), - new Grad4(0.08164729285680945, -0.8828161875373585, 0.08164729285680945, 0.4553054119602712), - new Grad4(-0.08164729285680945, -0.4553054119602712, -0.08164729285680945, 0.8828161875373585), - new Grad4(-0.15296486218853164, -0.5029860367700724, 0.4004672082940195, 0.7504883828755602), - new Grad4(0.4004672082940195, -0.5029860367700724, -0.15296486218853164, 0.7504883828755602), - new Grad4(0.3239847771997537, -0.5794684678643381, 0.3239847771997537, 0.6740059517812944), - new Grad4(-0.3239847771997537, -0.3239847771997537, -0.6740059517812944, 0.5794684678643381), - new Grad4(-0.4004672082940195, 0.15296486218853164, -0.7504883828755602, 0.5029860367700724), - new Grad4(0.15296486218853164, -0.4004672082940195, -0.7504883828755602, 0.5029860367700724), - new Grad4(0.08164729285680945, 0.08164729285680945, -0.8828161875373585, 0.4553054119602712), - new Grad4(-0.08164729285680945, -0.08164729285680945, -0.4553054119602712, 0.8828161875373585), - new Grad4(-0.15296486218853164, 0.4004672082940195, -0.5029860367700724, 0.7504883828755602), - new Grad4(0.4004672082940195, -0.15296486218853164, -0.5029860367700724, 0.7504883828755602), - new Grad4(0.3239847771997537, 0.3239847771997537, -0.5794684678643381, 0.6740059517812944), - new Grad4(-0.6740059517812944, -0.3239847771997537, 0.5794684678643381, -0.3239847771997537), - new Grad4(-0.7504883828755602, -0.4004672082940195, 0.5029860367700724, 0.15296486218853164), - new Grad4(-0.7504883828755602, 0.15296486218853164, 0.5029860367700724, -0.4004672082940195), - new Grad4(-0.8828161875373585, 0.08164729285680945, 0.4553054119602712, 0.08164729285680945), - new Grad4(-0.4553054119602712, -0.08164729285680945, 0.8828161875373585, -0.08164729285680945), - new Grad4(-0.5029860367700724, -0.15296486218853164, 0.7504883828755602, 0.4004672082940195), - new Grad4(-0.5029860367700724, 0.4004672082940195, 0.7504883828755602, -0.15296486218853164), - new Grad4(-0.5794684678643381, 0.3239847771997537, 0.6740059517812944, 0.3239847771997537), - new Grad4(-0.3239847771997537, -0.6740059517812944, 0.5794684678643381, -0.3239847771997537), - new Grad4(-0.4004672082940195, -0.7504883828755602, 0.5029860367700724, 0.15296486218853164), - new Grad4(0.15296486218853164, -0.7504883828755602, 0.5029860367700724, -0.4004672082940195), - new Grad4(0.08164729285680945, -0.8828161875373585, 0.4553054119602712, 0.08164729285680945), - new Grad4(-0.08164729285680945, -0.4553054119602712, 0.8828161875373585, -0.08164729285680945), - new Grad4(-0.15296486218853164, -0.5029860367700724, 0.7504883828755602, 0.4004672082940195), - new Grad4(0.4004672082940195, -0.5029860367700724, 0.7504883828755602, -0.15296486218853164), - new Grad4(0.3239847771997537, -0.5794684678643381, 0.6740059517812944, 0.3239847771997537), - new Grad4(-0.3239847771997537, -0.3239847771997537, 0.5794684678643381, -0.6740059517812944), - new Grad4(-0.4004672082940195, 0.15296486218853164, 0.5029860367700724, -0.7504883828755602), - new Grad4(0.15296486218853164, -0.4004672082940195, 0.5029860367700724, -0.7504883828755602), - new Grad4(0.08164729285680945, 0.08164729285680945, 0.4553054119602712, -0.8828161875373585), - new Grad4(-0.08164729285680945, -0.08164729285680945, 0.8828161875373585, -0.4553054119602712), - new Grad4(-0.15296486218853164, 0.4004672082940195, 0.7504883828755602, -0.5029860367700724), - new Grad4(0.4004672082940195, -0.15296486218853164, 0.7504883828755602, -0.5029860367700724), - new Grad4(0.3239847771997537, 0.3239847771997537, 0.6740059517812944, -0.5794684678643381), - new Grad4(-0.6740059517812944, 0.5794684678643381, -0.3239847771997537, -0.3239847771997537), - new Grad4(-0.7504883828755602, 0.5029860367700724, -0.4004672082940195, 0.15296486218853164), - new Grad4(-0.7504883828755602, 0.5029860367700724, 0.15296486218853164, -0.4004672082940195), - new Grad4(-0.8828161875373585, 0.4553054119602712, 0.08164729285680945, 0.08164729285680945), - new Grad4(-0.4553054119602712, 0.8828161875373585, -0.08164729285680945, -0.08164729285680945), - new Grad4(-0.5029860367700724, 0.7504883828755602, -0.15296486218853164, 0.4004672082940195), - new Grad4(-0.5029860367700724, 0.7504883828755602, 0.4004672082940195, -0.15296486218853164), - new Grad4(-0.5794684678643381, 0.6740059517812944, 0.3239847771997537, 0.3239847771997537), - new Grad4(-0.3239847771997537, 0.5794684678643381, -0.6740059517812944, -0.3239847771997537), - new Grad4(-0.4004672082940195, 0.5029860367700724, -0.7504883828755602, 0.15296486218853164), - new Grad4(0.15296486218853164, 0.5029860367700724, -0.7504883828755602, -0.4004672082940195), - new Grad4(0.08164729285680945, 0.4553054119602712, -0.8828161875373585, 0.08164729285680945), - new Grad4(-0.08164729285680945, 0.8828161875373585, -0.4553054119602712, -0.08164729285680945), - new Grad4(-0.15296486218853164, 0.7504883828755602, -0.5029860367700724, 0.4004672082940195), - new Grad4(0.4004672082940195, 0.7504883828755602, -0.5029860367700724, -0.15296486218853164), - new Grad4(0.3239847771997537, 0.6740059517812944, -0.5794684678643381, 0.3239847771997537), - new Grad4(-0.3239847771997537, 0.5794684678643381, -0.3239847771997537, -0.6740059517812944), - new Grad4(-0.4004672082940195, 0.5029860367700724, 0.15296486218853164, -0.7504883828755602), - new Grad4(0.15296486218853164, 0.5029860367700724, -0.4004672082940195, -0.7504883828755602), - new Grad4(0.08164729285680945, 0.4553054119602712, 0.08164729285680945, -0.8828161875373585), - new Grad4(-0.08164729285680945, 0.8828161875373585, -0.08164729285680945, -0.4553054119602712), - new Grad4(-0.15296486218853164, 0.7504883828755602, 0.4004672082940195, -0.5029860367700724), - new Grad4(0.4004672082940195, 0.7504883828755602, -0.15296486218853164, -0.5029860367700724), - new Grad4(0.3239847771997537, 0.6740059517812944, 0.3239847771997537, -0.5794684678643381), - new Grad4(0.5794684678643381, -0.6740059517812944, -0.3239847771997537, -0.3239847771997537), - new Grad4(0.5029860367700724, -0.7504883828755602, -0.4004672082940195, 0.15296486218853164), - new Grad4(0.5029860367700724, -0.7504883828755602, 0.15296486218853164, -0.4004672082940195), - new Grad4(0.4553054119602712, -0.8828161875373585, 0.08164729285680945, 0.08164729285680945), - new Grad4(0.8828161875373585, -0.4553054119602712, -0.08164729285680945, -0.08164729285680945), - new Grad4(0.7504883828755602, -0.5029860367700724, -0.15296486218853164, 0.4004672082940195), - new Grad4(0.7504883828755602, -0.5029860367700724, 0.4004672082940195, -0.15296486218853164), - new Grad4(0.6740059517812944, -0.5794684678643381, 0.3239847771997537, 0.3239847771997537), - new Grad4(0.5794684678643381, -0.3239847771997537, -0.6740059517812944, -0.3239847771997537), - new Grad4(0.5029860367700724, -0.4004672082940195, -0.7504883828755602, 0.15296486218853164), - new Grad4(0.5029860367700724, 0.15296486218853164, -0.7504883828755602, -0.4004672082940195), - new Grad4(0.4553054119602712, 0.08164729285680945, -0.8828161875373585, 0.08164729285680945), - new Grad4(0.8828161875373585, -0.08164729285680945, -0.4553054119602712, -0.08164729285680945), - new Grad4(0.7504883828755602, -0.15296486218853164, -0.5029860367700724, 0.4004672082940195), - new Grad4(0.7504883828755602, 0.4004672082940195, -0.5029860367700724, -0.15296486218853164), - new Grad4(0.6740059517812944, 0.3239847771997537, -0.5794684678643381, 0.3239847771997537), - new Grad4(0.5794684678643381, -0.3239847771997537, -0.3239847771997537, -0.6740059517812944), - new Grad4(0.5029860367700724, -0.4004672082940195, 0.15296486218853164, -0.7504883828755602), - new Grad4(0.5029860367700724, 0.15296486218853164, -0.4004672082940195, -0.7504883828755602), - new Grad4(0.4553054119602712, 0.08164729285680945, 0.08164729285680945, -0.8828161875373585), - new Grad4(0.8828161875373585, -0.08164729285680945, -0.08164729285680945, -0.4553054119602712), - new Grad4(0.7504883828755602, -0.15296486218853164, 0.4004672082940195, -0.5029860367700724), - new Grad4(0.7504883828755602, 0.4004672082940195, -0.15296486218853164, -0.5029860367700724), - new Grad4(0.6740059517812944, 0.3239847771997537, 0.3239847771997537, -0.5794684678643381), - new Grad4(0.03381941603233842, 0.03381941603233842, 0.03381941603233842, 0.9982828964265062), - new Grad4(-0.044802370851755174, -0.044802370851755174, 0.508629699630796, 0.8586508742123365), - new Grad4(-0.044802370851755174, 0.508629699630796, -0.044802370851755174, 0.8586508742123365), - new Grad4(-0.12128480194602098, 0.4321472685365301, 0.4321472685365301, 0.7821684431180708), - new Grad4(0.508629699630796, -0.044802370851755174, -0.044802370851755174, 0.8586508742123365), - new Grad4(0.4321472685365301, -0.12128480194602098, 0.4321472685365301, 0.7821684431180708), - new Grad4(0.4321472685365301, 0.4321472685365301, -0.12128480194602098, 0.7821684431180708), - new Grad4(0.37968289875261624, 0.37968289875261624, 0.37968289875261624, 0.753341017856078), - new Grad4(0.03381941603233842, 0.03381941603233842, 0.9982828964265062, 0.03381941603233842), - new Grad4(-0.044802370851755174, 0.044802370851755174, 0.8586508742123365, 0.508629699630796), - new Grad4(-0.044802370851755174, 0.508629699630796, 0.8586508742123365, -0.044802370851755174), - new Grad4(-0.12128480194602098, 0.4321472685365301, 0.7821684431180708, 0.4321472685365301), - new Grad4(0.508629699630796, -0.044802370851755174, 0.8586508742123365, -0.044802370851755174), - new Grad4(0.4321472685365301, -0.12128480194602098, 0.7821684431180708, 0.4321472685365301), - new Grad4(0.4321472685365301, 0.4321472685365301, 0.7821684431180708, -0.12128480194602098), - new Grad4(0.37968289875261624, 0.37968289875261624, 0.753341017856078, 0.37968289875261624), - new Grad4(0.03381941603233842, 0.9982828964265062, 0.03381941603233842, 0.03381941603233842), - new Grad4(-0.044802370851755174, 0.8586508742123365, -0.044802370851755174, 0.508629699630796), - new Grad4(-0.044802370851755174, 0.8586508742123365, 0.508629699630796, -0.044802370851755174), - new Grad4(-0.12128480194602098, 0.7821684431180708, 0.4321472685365301, 0.4321472685365301), - new Grad4(0.508629699630796, 0.8586508742123365, -0.044802370851755174, -0.044802370851755174), - new Grad4(0.4321472685365301, 0.7821684431180708, -0.12128480194602098, 0.4321472685365301), - new Grad4(0.4321472685365301, 0.7821684431180708, 0.4321472685365301, -0.12128480194602098), - new Grad4(0.37968289875261624, 0.753341017856078, 0.37968289875261624, 0.37968289875261624), - new Grad4(0.9982828964265062, 0.03381941603233842, 0.03381941603233842, 0.03381941603233842), - new Grad4(0.8586508742123365, -0.044802370851755174, -0.044802370851755174, 0.508629699630796), - new Grad4(0.8586508742123365, -0.044802370851755174, 0.508629699630796, -0.044802370851755174), - new Grad4(0.7821684431180708, -0.12128480194602098, 0.4321472685365301, 0.4321472685365301), - new Grad4(0.8586508742123365, 0.508629699630796, -0.044802370851755174, -0.044802370851755174), - new Grad4(0.7821684431180708, 0.4321472685365301, -0.12128480194602098, 0.4321472685365301), - new Grad4(0.7821684431180708, 0.4321472685365301, 0.4321472685365301, -0.12128480194602098), - new Grad4(0.753341017856078, 0.37968289875261624, 0.37968289875261624, 0.37968289875261624) - }; - for (Grad4 grad41 : grad4) { - grad41.dx /= N4; - grad41.dy /= N4; - grad41.dz /= N4; - grad41.dw /= N4; - } - for (int i = 0; i < PSIZE; i++) { - GRADIENTS_4D[i] = grad4[i % grad4.length]; - } - } -} +package monkstone.noise; + +/** + * K.jpg's OpenSimplex 2, smooth variant ("SuperSimplex") + * + * - 2D is standard simplex, modified to support larger kernels. Implemented + * using a lookup table. - 3D is "Re-oriented 8-point BCC noise" which + * constructs a congruent BCC lattice in a much different way than usual. - 4D + * uses a naïve pregenerated lookup table, and averages out to the expected + * performance. + * + * Multiple versions of each function are provided. See the documentation above + * each, for more info. + */ +public class OpenSimplex2S { + + private static final int PSIZE = 2048; + private static final int PMASK = 2047; + + private final short[] perm; + private final Grad2[] permGrad2; + private final Grad3[] permGrad3; + private final Grad4[] permGrad4; + + /** + * + * @param seed + */ + public OpenSimplex2S(long seed) { + perm = new short[PSIZE]; + permGrad2 = new Grad2[PSIZE]; + permGrad3 = new Grad3[PSIZE]; + permGrad4 = new Grad4[PSIZE]; + short[] source = new short[PSIZE]; + for (short i = 0; i < PSIZE; i++) { + source[i] = i; + } + for (int i = PSIZE - 1; i >= 0; i--) { + seed = seed * 6364136223846793005L + 1442695040888963407L; + int r = (int) ((seed + 31) % (i + 1)); + if (r < 0) { + r += (i + 1); + } + perm[i] = source[r]; + permGrad2[i] = GRADIENTS_2D[perm[i]]; + permGrad3[i] = GRADIENTS_3D[perm[i]]; + permGrad4[i] = GRADIENTS_4D[perm[i]]; + source[r] = source[i]; + } + } + + /* + * Noise Evaluators + */ + /** + * 2D SuperSimplex noise, standard lattice orientation. + * + * @param x + * @param y + * @return + */ + public double noise2(double x, double y) { + + // Get points for A2* lattice + double s = 0.366025403784439 * (x + y); + double xs = x + s, ys = y + s; + + return noise2_Base(xs, ys); + } + + /** + * 2D SuperSimplex noise, with Y pointing down the main diagonal.Might be + * better for a 2D sandbox style game, where Y is vertical.Probably slightly + * less optimal for heightmaps or continent maps. + * + * @param x + * @param y + * @return + */ + public double noise2_XBeforeY(double x, double y) { + + // Skew transform and rotation baked into one. + double xx = x * 0.7071067811865476; + double yy = y * 1.224744871380249; + + return noise2_Base(yy + xx, yy - xx); + } + + /** + * 2D SuperSimplex noise base. Lookup table implementation inspired by + * DigitalShadow. + */ + private double noise2_Base(double xs, double ys) { + double value = 0; + + // Get base points and offsets + int xsb = fastFloor(xs), ysb = fastFloor(ys); + double xsi = xs - xsb, ysi = ys - ysb; + + // Index to point list + int a = (int) (xsi + ysi); + int index + = (a << 2) + | (int) (xsi - ysi / 2 + 1 - a / 2.0) << 3 + | (int) (ysi - xsi / 2 + 1 - a / 2.0) << 4; + + double ssi = (xsi + ysi) * -0.211324865405187; + double xi = xsi + ssi, yi = ysi + ssi; + + // Point contributions + for (int i = 0; i < 4; i++) { + LatticePoint2D c = LOOKUP_2D[index + i]; + + double dx = xi + c.dx, dy = yi + c.dy; + double attn = 2.0 / 3.0 - dx * dx - dy * dy; + if (attn <= 0) { + continue; + } + + int pxm = (xsb + c.xsv) & PMASK, pym = (ysb + c.ysv) & PMASK; + Grad2 grad = permGrad2[perm[pxm] ^ pym]; + double extrapolation = grad.dx * dx + grad.dy * dy; + + attn *= attn; + value += attn * attn * extrapolation; + } + + return value; + } + + /** + * 3D Re-oriented 8-point BCC noise, classic orientation Proper substitute + * for what 3D SuperSimplex would be, in light of Forbidden Formulae.Use + * noise3_XYBeforeZ or noise3_XZBeforeY instead, wherever appropriate. + * + * @param x + * @param y + * @param z + * @return + */ + public double noise3_Classic(double x, double y, double z) { + + // Re-orient the cubic lattices via rotation, to produce the expected look on cardinal planar slices. + // If texturing objects that don't tend to have cardinal plane faces, you could even remove this. + // Orthonormal rotation. Not a skew transform. + double r = (2.0 / 3.0) * (x + y + z); + double xr = r - x, yr = r - y, zr = r - z; + + // Evaluate both lattices to form a BCC lattice. + return noise3_BCC(xr, yr, zr); + } + + /** + * 3D Re-oriented 8-point BCC noise, with better visual isotropy in (X, + * Y).Recommended for 3D terrain and time-varied animations.The Z coordinate + * should always be the "different" coordinate in your use case.If Y is + * vertical in world coordinates, call noise3_XYBeforeZ(x, z, Y) or use + * noise3_XZBeforeY.If Z is vertical in world coordinates, call + * noise3_XYBeforeZ(x, y, Z). For a time varied animation, call + * noise3_XYBeforeZ(x, y, T). + * + * @param x + * @param z + * @param y + * @return + */ + public double noise3_XYBeforeZ(double x, double y, double z) { + + // Re-orient the cubic lattices without skewing, to make X and Y triangular like 2D. + // Orthonormal rotation. Not a skew transform. + double xy = x + y; + double s2 = xy * -0.211324865405187; + double zz = z * 0.577350269189626; + double xr = x + s2 - zz, yr = y + s2 - zz; + double zr = xy * 0.577350269189626 + zz; + + // Evaluate both lattices to form a BCC lattice. + return noise3_BCC(xr, yr, zr); + } + + /** + * 3D Re-oriented 8-point BCC noise, with better visual isotropy in (X, + * Z).Recommended for 3D terrain and time-varied animations.The Y coordinate + * should always be the "different" coordinate in your use case.If Y is + * vertical in world coordinates, call noise3_XZBeforeY(x, Y, z).If Z is + * vertical in world coordinates, call noise3_XZBeforeY(x, Z, y) or use + * noise3_XYBeforeZ. For a time varied animation, call noise3_XZBeforeY(x, + * T, y) or use noise3_XYBeforeZ. + * + * @param x + * @param y + * @param z + * @return + */ + public double noise3_XZBeforeY(double x, double y, double z) { + + // Re-orient the cubic lattices without skewing, to make X and Z triangular like 2D. + // Orthonormal rotation. Not a skew transform. + double xz = x + z; + double s2 = xz * -0.211324865405187; + double yy = y * 0.577350269189626; + double xr = x + s2 - yy; + double zr = z + s2 - yy; + double yr = xz * 0.577350269189626 + yy; + + // Evaluate both lattices to form a BCC lattice. + return noise3_BCC(xr, yr, zr); + } + + /** + * Generate overlapping cubic lattices for 3D Re-oriented BCC noise. Lookup + * table implementation inspired by DigitalShadow. It was actually faster to + * narrow down the points in the loop itself, than to build up the index + * with enough info to isolate 8 points. + */ + private double noise3_BCC(double xr, double yr, double zr) { + + // Get base and offsets inside cube of first lattice. + int xrb = fastFloor(xr), yrb = fastFloor(yr), zrb = fastFloor(zr); + double xri = xr - xrb, yri = yr - yrb, zri = zr - zrb; + + // Identify which octant of the cube we're in. This determines which cell + // in the other cubic lattice we're in, and also narrows down one point on each. + int xht = (int) (xri + 0.5), yht = (int) (yri + 0.5), zht = (int) (zri + 0.5); + int index = (xht) | (yht << 1) | (zht << 2); + + // Point contributions + double value = 0; + LatticePoint3D c = LOOKUP_3D[index]; + while (c != null) { + double dxr = xri + c.dxr, dyr = yri + c.dyr, dzr = zri + c.dzr; + double attn = 0.75 - dxr * dxr - dyr * dyr - dzr * dzr; + if (attn < 0) { + c = c.nextOnFailure; + } else { + int pxm = (xrb + c.xrv) & PMASK, pym = (yrb + c.yrv) & PMASK, pzm = (zrb + c.zrv) & PMASK; + Grad3 grad = permGrad3[perm[perm[pxm] ^ pym] ^ pzm]; + double extrapolation = grad.dx * dxr + grad.dy * dyr + grad.dz * dzr; + + attn *= attn; + value += attn * attn * extrapolation; + c = c.nextOnSuccess; + } + } + return value; + } + + /** + * 4D SuperSimplex noise, classic lattice orientation. + * + * @param x + * @param y + * @param z + * @param w + * @return + */ + public double noise4_Classic(double x, double y, double z, double w) { + + // Get points for A4 lattice + double s = 0.309016994374947 * (x + y + z + w); + double xs = x + s, ys = y + s, zs = z + s, ws = w + s; + + return noise4_Base(xs, ys, zs, ws); + } + + /** + * 4D SuperSimplex noise, with XY and ZW forming orthogonal triangular-based + * planes.Recommended for 3D terrain, where X and Y (or Z and W) are + * horizontal.Recommended for noise(x, y, sin(time), cos(time)) trick. + * + * @param x + * @param y + * @param z + * @param w + * @return + */ + public double noise4_XYBeforeZW(double x, double y, double z, double w) { + + double s2 = (x + y) * -0.28522513987434876941 + (z + w) * 0.83897065470611435718; + double t2 = (z + w) * 0.21939749883706435719 + (x + y) * -0.48214856493302476942; + double xs = x + s2, ys = y + s2, zs = z + t2, ws = w + t2; + + return noise4_Base(xs, ys, zs, ws); + } + + /** + * 4D SuperSimplex noise, with XZ and YW forming orthogonal triangular-based + * planes.Recommended for 3D terrain, where X and Z (or Y and W) are + * horizontal. + * + * @param x + * @param y + * @param z + * @param w + * @return + */ + public double noise4_XZBeforeYW(double x, double y, double z, double w) { + + double s2 = (x + z) * -0.28522513987434876941 + (y + w) * 0.83897065470611435718; + double t2 = (y + w) * 0.21939749883706435719 + (x + z) * -0.48214856493302476942; + double xs = x + s2, ys = y + t2, zs = z + s2, ws = w + t2; + + return noise4_Base(xs, ys, zs, ws); + } + + /** + * 4D SuperSimplex noise, with XYZ oriented like noise3_Classic, and W for + * an extra degree of freedom.Recommended for time-varied animations which + * texture a 3D object (W=time) + * + * @param x + * @param y + * @param z + * @param w + * @return + */ + public double noise4_XYZBeforeW(double x, double y, double z, double w) { + + double xyz = x + y + z; + double ww = w * 1.118033988749894; + double s2 = xyz * -0.16666666666666666 + ww; + double xs = x + s2, ys = y + s2, zs = z + s2, ws = -0.5 * xyz + ww; + + return noise4_Base(xs, ys, zs, ws); + } + + /** + * 4D SuperSimplex noise base. Using ultra-simple 4x4x4x4 lookup + * partitioning. This isn't as elegant or SIMD/GPU/etc. portable as other + * approaches, but it does compete performance-wise with optimized + * OpenSimplex1. + */ + private double noise4_Base(double xs, double ys, double zs, double ws) { + double value = 0; + + // Get base points and offsets + int xsb = fastFloor(xs), ysb = fastFloor(ys), zsb = fastFloor(zs), wsb = fastFloor(ws); + double xsi = xs - xsb, ysi = ys - ysb, zsi = zs - zsb, wsi = ws - wsb; + + // Unskewed offsets + double ssi = (xsi + ysi + zsi + wsi) * -0.138196601125011; + double xi = xsi + ssi, yi = ysi + ssi, zi = zsi + ssi, wi = wsi + ssi; + + int index = ((fastFloor(xs * 4) & 3)) + | ((fastFloor(ys * 4) & 3) << 2) + | ((fastFloor(zs * 4) & 3) << 4) + | ((fastFloor(ws * 4) & 3) << 6); + + // Point contributions + for (LatticePoint4D c : LOOKUP_4D[index]) { + double dx = xi + c.dx, dy = yi + c.dy, dz = zi + c.dz, dw = wi + c.dw; + double attn = 0.8 - dx * dx - dy * dy - dz * dz - dw * dw; + if (attn > 0) { + attn *= attn; + + int pxm = (xsb + c.xsv) & PMASK, pym = (ysb + c.ysv) & PMASK; + int pzm = (zsb + c.zsv) & PMASK, pwm = (wsb + c.wsv) & PMASK; + Grad4 grad = permGrad4[perm[perm[perm[pxm] ^ pym] ^ pzm] ^ pwm]; + double extrapolation = grad.dx * dx + grad.dy * dy + grad.dz * dz + grad.dw * dw; + + value += attn * attn * extrapolation; + } + } + return value; + } + + /* + * Utility + */ + private static int fastFloor(double x) { + int xi = (int) x; + return x < xi ? xi - 1 : xi; + } + + /* + * Definitions + */ + private static final LatticePoint2D[] LOOKUP_2D; + private static final LatticePoint3D[] LOOKUP_3D; + private static final LatticePoint4D[][] LOOKUP_4D; + + static { + LOOKUP_2D = new LatticePoint2D[8 * 4]; + LOOKUP_3D = new LatticePoint3D[8]; + LOOKUP_4D = new LatticePoint4D[256][]; + + for (int i = 0; i < 8; i++) { + int i1, j1, i2, j2; + if ((i & 1) == 0) { + if ((i & 2) == 0) { + i1 = -1; + j1 = 0; + } else { + i1 = 1; + j1 = 0; + } + if ((i & 4) == 0) { + i2 = 0; + j2 = -1; + } else { + i2 = 0; + j2 = 1; + } + } else { + if ((i & 2) != 0) { + i1 = 2; + j1 = 1; + } else { + i1 = 0; + j1 = 1; + } + if ((i & 4) != 0) { + i2 = 1; + j2 = 2; + } else { + i2 = 1; + j2 = 0; + } + } + LOOKUP_2D[i * 4 + 0] = new LatticePoint2D(0, 0); + LOOKUP_2D[i * 4 + 1] = new LatticePoint2D(1, 1); + LOOKUP_2D[i * 4 + 2] = new LatticePoint2D(i1, j1); + LOOKUP_2D[i * 4 + 3] = new LatticePoint2D(i2, j2); + } + + for (int i = 0; i < 8; i++) { + int i1, j1, k1, i2, j2, k2; + i1 = (i) & 1; + j1 = (i >> 1) & 1; + k1 = (i >> 2) & 1; + i2 = i1 ^ 1; + j2 = j1 ^ 1; + k2 = k1 ^ 1; + + // The two points within this octant, one from each of the two cubic half-lattices. + LatticePoint3D c0 = new LatticePoint3D(i1, j1, k1, 0); + LatticePoint3D c1 = new LatticePoint3D(i1 + i2, j1 + j2, k1 + k2, 1); + + // (1, 0, 0) vs (0, 1, 1) away from octant. + LatticePoint3D c2 = new LatticePoint3D(i1 ^ 1, j1, k1, 0); + LatticePoint3D c3 = new LatticePoint3D(i1, j1 ^ 1, k1 ^ 1, 0); + + // (1, 0, 0) vs (0, 1, 1) away from octant, on second half-lattice. + LatticePoint3D c4 = new LatticePoint3D(i1 + (i2 ^ 1), j1 + j2, k1 + k2, 1); + LatticePoint3D c5 = new LatticePoint3D(i1 + i2, j1 + (j2 ^ 1), k1 + (k2 ^ 1), 1); + + // (0, 1, 0) vs (1, 0, 1) away from octant. + LatticePoint3D c6 = new LatticePoint3D(i1, j1 ^ 1, k1, 0); + LatticePoint3D c7 = new LatticePoint3D(i1 ^ 1, j1, k1 ^ 1, 0); + + // (0, 1, 0) vs (1, 0, 1) away from octant, on second half-lattice. + LatticePoint3D c8 = new LatticePoint3D(i1 + i2, j1 + (j2 ^ 1), k1 + k2, 1); + LatticePoint3D c9 = new LatticePoint3D(i1 + (i2 ^ 1), j1 + j2, k1 + (k2 ^ 1), 1); + + // (0, 0, 1) vs (1, 1, 0) away from octant. + LatticePoint3D cA = new LatticePoint3D(i1, j1, k1 ^ 1, 0); + LatticePoint3D cB = new LatticePoint3D(i1 ^ 1, j1 ^ 1, k1, 0); + + // (0, 0, 1) vs (1, 1, 0) away from octant, on second half-lattice. + LatticePoint3D cC = new LatticePoint3D(i1 + i2, j1 + j2, k1 + (k2 ^ 1), 1); + LatticePoint3D cD = new LatticePoint3D(i1 + (i2 ^ 1), j1 + (j2 ^ 1), k1 + k2, 1); + + // First two points are guaranteed. + c0.nextOnFailure = c0.nextOnSuccess = c1; + c1.nextOnFailure = c1.nextOnSuccess = c2; + + // If c2 is in range, then we know c3 and c4 are not. + c2.nextOnFailure = c3; + c2.nextOnSuccess = c5; + c3.nextOnFailure = c4; + c3.nextOnSuccess = c4; + + // If c4 is in range, then we know c5 is not. + c4.nextOnFailure = c5; + c4.nextOnSuccess = c6; + c5.nextOnFailure = c5.nextOnSuccess = c6; + + // If c6 is in range, then we know c7 and c8 are not. + c6.nextOnFailure = c7; + c6.nextOnSuccess = c9; + c7.nextOnFailure = c8; + c7.nextOnSuccess = c8; + + // If c8 is in range, then we know c9 is not. + c8.nextOnFailure = c9; + c8.nextOnSuccess = cA; + c9.nextOnFailure = c9.nextOnSuccess = cA; + + // If cA is in range, then we know cB and cC are not. + cA.nextOnFailure = cB; + cA.nextOnSuccess = cD; + cB.nextOnFailure = cC; + cB.nextOnSuccess = cC; + + // If cC is in range, then we know cD is not. + cC.nextOnFailure = cD; + cC.nextOnSuccess = null; + cD.nextOnFailure = cD.nextOnSuccess = null; + + LOOKUP_3D[i] = c0; + } + + int[][] lookup4DPregen = { + {0x15, 0x45, 0x51, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, + {0x15, 0x45, 0x51, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA6, 0xAA}, + {0x01, 0x05, 0x11, 0x15, 0x41, 0x45, 0x51, 0x55, 0x56, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xA6, 0xAA}, + {0x01, 0x15, 0x16, 0x45, 0x46, 0x51, 0x52, 0x55, 0x56, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, + {0x15, 0x45, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA9, 0xAA}, + {0x05, 0x15, 0x45, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xAA}, + {0x05, 0x15, 0x45, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xAA}, + {0x05, 0x15, 0x16, 0x45, 0x46, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xAA, 0xAB}, + {0x04, 0x05, 0x14, 0x15, 0x44, 0x45, 0x54, 0x55, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA}, + {0x05, 0x15, 0x45, 0x55, 0x56, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xAA}, + {0x05, 0x15, 0x45, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x9A, 0xAA}, + {0x05, 0x15, 0x16, 0x45, 0x46, 0x55, 0x56, 0x59, 0x5A, 0x5B, 0x6A, 0x9A, 0xAA, 0xAB}, + {0x04, 0x15, 0x19, 0x45, 0x49, 0x54, 0x55, 0x58, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, + {0x05, 0x15, 0x19, 0x45, 0x49, 0x55, 0x56, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xAA, 0xAE}, + {0x05, 0x15, 0x19, 0x45, 0x49, 0x55, 0x56, 0x59, 0x5A, 0x5E, 0x6A, 0x9A, 0xAA, 0xAE}, + {0x05, 0x15, 0x1A, 0x45, 0x4A, 0x55, 0x56, 0x59, 0x5A, 0x5B, 0x5E, 0x6A, 0x9A, 0xAA, 0xAB, 0xAE, 0xAF}, + {0x15, 0x51, 0x54, 0x55, 0x56, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x95, 0xA5, 0xA6, 0xA9, 0xAA}, + {0x11, 0x15, 0x51, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0xA5, 0xA6, 0xAA}, + {0x11, 0x15, 0x51, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x6A, 0x96, 0xA6, 0xAA}, + {0x11, 0x15, 0x16, 0x51, 0x52, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x6A, 0x96, 0xA6, 0xAA, 0xAB}, + {0x14, 0x15, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x99, 0xA5, 0xA9, 0xAA}, + {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x9A, 0xA6, 0xA9, 0xAA}, + {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, + {0x15, 0x16, 0x55, 0x56, 0x5A, 0x66, 0x6A, 0x6B, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, + {0x14, 0x15, 0x54, 0x55, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x99, 0xA9, 0xAA}, + {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, + {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x9A, 0xAA}, + {0x15, 0x16, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x6A, 0x6B, 0x9A, 0xAA, 0xAB}, + {0x14, 0x15, 0x19, 0x54, 0x55, 0x58, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x99, 0xA9, 0xAA, 0xAE}, + {0x15, 0x19, 0x55, 0x59, 0x5A, 0x69, 0x6A, 0x6E, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, + {0x15, 0x19, 0x55, 0x56, 0x59, 0x5A, 0x69, 0x6A, 0x6E, 0x9A, 0xAA, 0xAE}, + {0x15, 0x1A, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x6B, 0x6E, 0x9A, 0xAA, 0xAB, 0xAE, 0xAF}, + {0x10, 0x11, 0x14, 0x15, 0x50, 0x51, 0x54, 0x55, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA}, + {0x11, 0x15, 0x51, 0x55, 0x56, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xAA}, + {0x11, 0x15, 0x51, 0x55, 0x56, 0x65, 0x66, 0x6A, 0xA6, 0xAA}, + {0x11, 0x15, 0x16, 0x51, 0x52, 0x55, 0x56, 0x65, 0x66, 0x67, 0x6A, 0xA6, 0xAA, 0xAB}, + {0x14, 0x15, 0x54, 0x55, 0x59, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA9, 0xAA}, + {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, + {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xA6, 0xAA}, + {0x15, 0x16, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x6A, 0x6B, 0xA6, 0xAA, 0xAB}, + {0x14, 0x15, 0x54, 0x55, 0x59, 0x65, 0x69, 0x6A, 0xA9, 0xAA}, + {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xA9, 0xAA}, + {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xAA}, + {0x15, 0x16, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x6B, 0xAA, 0xAB}, + {0x14, 0x15, 0x19, 0x54, 0x55, 0x58, 0x59, 0x65, 0x69, 0x6A, 0x6D, 0xA9, 0xAA, 0xAE}, + {0x15, 0x19, 0x55, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x6E, 0xA9, 0xAA, 0xAE}, + {0x15, 0x19, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x6E, 0xAA, 0xAE}, + {0x15, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x69, 0x6A, 0x6B, 0x6E, 0x9A, 0xAA, 0xAB, 0xAE, 0xAF}, + {0x10, 0x15, 0x25, 0x51, 0x54, 0x55, 0x61, 0x64, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, + {0x11, 0x15, 0x25, 0x51, 0x55, 0x56, 0x61, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xAA, 0xBA}, + {0x11, 0x15, 0x25, 0x51, 0x55, 0x56, 0x61, 0x65, 0x66, 0x6A, 0x76, 0xA6, 0xAA, 0xBA}, + {0x11, 0x15, 0x26, 0x51, 0x55, 0x56, 0x62, 0x65, 0x66, 0x67, 0x6A, 0x76, 0xA6, 0xAA, 0xAB, 0xBA, 0xBB}, + {0x14, 0x15, 0x25, 0x54, 0x55, 0x59, 0x64, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA9, 0xAA, 0xBA}, + {0x15, 0x25, 0x55, 0x65, 0x66, 0x69, 0x6A, 0x7A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, + {0x15, 0x25, 0x55, 0x56, 0x65, 0x66, 0x69, 0x6A, 0x7A, 0xA6, 0xAA, 0xBA}, + {0x15, 0x26, 0x55, 0x56, 0x65, 0x66, 0x6A, 0x6B, 0x7A, 0xA6, 0xAA, 0xAB, 0xBA, 0xBB}, + {0x14, 0x15, 0x25, 0x54, 0x55, 0x59, 0x64, 0x65, 0x69, 0x6A, 0x79, 0xA9, 0xAA, 0xBA}, + {0x15, 0x25, 0x55, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x7A, 0xA9, 0xAA, 0xBA}, + {0x15, 0x25, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x7A, 0xAA, 0xBA}, + {0x15, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x6B, 0x7A, 0xA6, 0xAA, 0xAB, 0xBA, 0xBB}, + {0x14, 0x15, 0x29, 0x54, 0x55, 0x59, 0x65, 0x68, 0x69, 0x6A, 0x6D, 0x79, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, + {0x15, 0x29, 0x55, 0x59, 0x65, 0x69, 0x6A, 0x6E, 0x7A, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, + {0x15, 0x55, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x6E, 0x7A, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, + {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x6B, 0x6E, 0x7A, 0xAA, 0xAB, 0xAE, 0xBA, 0xBF}, + {0x45, 0x51, 0x54, 0x55, 0x56, 0x59, 0x65, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, + {0x41, 0x45, 0x51, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xAA}, + {0x41, 0x45, 0x51, 0x55, 0x56, 0x5A, 0x66, 0x95, 0x96, 0x9A, 0xA6, 0xAA}, + {0x41, 0x45, 0x46, 0x51, 0x52, 0x55, 0x56, 0x5A, 0x66, 0x95, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, + {0x44, 0x45, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x69, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA9, 0xAA}, + {0x45, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xA9, 0xAA}, + {0x45, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xAA, 0xAB}, + {0x45, 0x46, 0x55, 0x56, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0x9B, 0xA6, 0xAA, 0xAB}, + {0x44, 0x45, 0x54, 0x55, 0x59, 0x5A, 0x69, 0x95, 0x99, 0x9A, 0xA9, 0xAA}, + {0x45, 0x55, 0x56, 0x59, 0x5A, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, + {0x45, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xAA}, + {0x45, 0x46, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x96, 0x9A, 0x9B, 0xAA, 0xAB}, + {0x44, 0x45, 0x49, 0x54, 0x55, 0x58, 0x59, 0x5A, 0x69, 0x95, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, + {0x45, 0x49, 0x55, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0x9E, 0xA9, 0xAA, 0xAE}, + {0x45, 0x49, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x99, 0x9A, 0x9E, 0xAA, 0xAE}, + {0x45, 0x4A, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x9A, 0x9B, 0x9E, 0xAA, 0xAB, 0xAE, 0xAF}, + {0x50, 0x51, 0x54, 0x55, 0x56, 0x59, 0x65, 0x66, 0x69, 0x95, 0x96, 0x99, 0xA5, 0xA6, 0xA9, 0xAA}, + {0x51, 0x55, 0x56, 0x59, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, + {0x51, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xAA, 0xAB}, + {0x51, 0x52, 0x55, 0x56, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xA6, 0xA7, 0xAA, 0xAB}, + {0x54, 0x55, 0x56, 0x59, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, + {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, + {0x15, 0x45, 0x51, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, + {0x55, 0x56, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, + {0x54, 0x55, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA5, 0xA9, 0xAA, 0xAE}, + {0x15, 0x45, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, + {0x15, 0x45, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xA9, 0xAA, 0xAB, 0xAE}, + {0x55, 0x56, 0x59, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, + {0x54, 0x55, 0x58, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAD, 0xAE}, + {0x55, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, + {0x55, 0x56, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, + {0x55, 0x56, 0x59, 0x5A, 0x6A, 0x9A, 0xAA, 0xAB, 0xAE, 0xAF}, + {0x50, 0x51, 0x54, 0x55, 0x65, 0x66, 0x69, 0x95, 0xA5, 0xA6, 0xA9, 0xAA}, + {0x51, 0x55, 0x56, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, + {0x51, 0x55, 0x56, 0x65, 0x66, 0x6A, 0x95, 0x96, 0xA5, 0xA6, 0xAA}, + {0x51, 0x52, 0x55, 0x56, 0x65, 0x66, 0x6A, 0x96, 0xA6, 0xA7, 0xAA, 0xAB}, + {0x54, 0x55, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x99, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, + {0x15, 0x51, 0x54, 0x55, 0x56, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, + {0x15, 0x51, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAB, 0xBA}, + {0x55, 0x56, 0x5A, 0x65, 0x66, 0x6A, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, + {0x54, 0x55, 0x59, 0x65, 0x69, 0x6A, 0x95, 0x99, 0xA5, 0xA9, 0xAA}, + {0x15, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAE, 0xBA}, + {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x9A, 0xA6, 0xA9, 0xAA}, + {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, + {0x54, 0x55, 0x58, 0x59, 0x65, 0x69, 0x6A, 0x99, 0xA9, 0xAA, 0xAD, 0xAE}, + {0x55, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, + {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, + {0x15, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x69, 0x6A, 0x9A, 0xAA, 0xAB, 0xAE, 0xAF}, + {0x50, 0x51, 0x54, 0x55, 0x61, 0x64, 0x65, 0x66, 0x69, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, + {0x51, 0x55, 0x61, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xB6, 0xBA}, + {0x51, 0x55, 0x56, 0x61, 0x65, 0x66, 0x6A, 0xA5, 0xA6, 0xAA, 0xB6, 0xBA}, + {0x51, 0x55, 0x56, 0x62, 0x65, 0x66, 0x6A, 0xA6, 0xA7, 0xAA, 0xAB, 0xB6, 0xBA, 0xBB}, + {0x54, 0x55, 0x64, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xB9, 0xBA}, + {0x55, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, + {0x55, 0x56, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, + {0x55, 0x56, 0x65, 0x66, 0x6A, 0xA6, 0xAA, 0xAB, 0xBA, 0xBB}, + {0x54, 0x55, 0x59, 0x64, 0x65, 0x69, 0x6A, 0xA5, 0xA9, 0xAA, 0xB9, 0xBA}, + {0x55, 0x59, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, + {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, + {0x15, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xA6, 0xAA, 0xAB, 0xBA, 0xBB}, + {0x54, 0x55, 0x59, 0x65, 0x68, 0x69, 0x6A, 0xA9, 0xAA, 0xAD, 0xAE, 0xB9, 0xBA, 0xBE}, + {0x55, 0x59, 0x65, 0x69, 0x6A, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, + {0x15, 0x55, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, + {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xAA, 0xAB, 0xAE, 0xBA, 0xBF}, + {0x40, 0x41, 0x44, 0x45, 0x50, 0x51, 0x54, 0x55, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, + {0x41, 0x45, 0x51, 0x55, 0x56, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xAA}, + {0x41, 0x45, 0x51, 0x55, 0x56, 0x95, 0x96, 0x9A, 0xA6, 0xAA}, + {0x41, 0x45, 0x46, 0x51, 0x52, 0x55, 0x56, 0x95, 0x96, 0x97, 0x9A, 0xA6, 0xAA, 0xAB}, + {0x44, 0x45, 0x54, 0x55, 0x59, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA9, 0xAA}, + {0x45, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, + {0x45, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xAA}, + {0x45, 0x46, 0x55, 0x56, 0x5A, 0x95, 0x96, 0x9A, 0x9B, 0xA6, 0xAA, 0xAB}, + {0x44, 0x45, 0x54, 0x55, 0x59, 0x95, 0x99, 0x9A, 0xA9, 0xAA}, + {0x45, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xA9, 0xAA}, + {0x45, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xAA}, + {0x45, 0x46, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0x9B, 0xAA, 0xAB}, + {0x44, 0x45, 0x49, 0x54, 0x55, 0x58, 0x59, 0x95, 0x99, 0x9A, 0x9D, 0xA9, 0xAA, 0xAE}, + {0x45, 0x49, 0x55, 0x59, 0x5A, 0x95, 0x99, 0x9A, 0x9E, 0xA9, 0xAA, 0xAE}, + {0x45, 0x49, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0x9E, 0xAA, 0xAE}, + {0x45, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x96, 0x99, 0x9A, 0x9B, 0x9E, 0xAA, 0xAB, 0xAE, 0xAF}, + {0x50, 0x51, 0x54, 0x55, 0x65, 0x95, 0x96, 0x99, 0xA5, 0xA6, 0xA9, 0xAA}, + {0x51, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, + {0x51, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xAA}, + {0x51, 0x52, 0x55, 0x56, 0x66, 0x95, 0x96, 0x9A, 0xA6, 0xA7, 0xAA, 0xAB}, + {0x54, 0x55, 0x59, 0x65, 0x69, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, + {0x45, 0x51, 0x54, 0x55, 0x56, 0x59, 0x65, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, + {0x45, 0x51, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAB, 0xEA}, + {0x55, 0x56, 0x5A, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, + {0x54, 0x55, 0x59, 0x65, 0x69, 0x95, 0x99, 0x9A, 0xA5, 0xA9, 0xAA}, + {0x45, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAE, 0xEA}, + {0x45, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xA9, 0xAA}, + {0x45, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xAA, 0xAB}, + {0x54, 0x55, 0x58, 0x59, 0x69, 0x95, 0x99, 0x9A, 0xA9, 0xAA, 0xAD, 0xAE}, + {0x55, 0x59, 0x5A, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, + {0x45, 0x55, 0x56, 0x59, 0x5A, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, + {0x45, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x96, 0x99, 0x9A, 0xAA, 0xAB, 0xAE, 0xAF}, + {0x50, 0x51, 0x54, 0x55, 0x65, 0x95, 0xA5, 0xA6, 0xA9, 0xAA}, + {0x51, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xA9, 0xAA}, + {0x51, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xAA}, + {0x51, 0x52, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xA7, 0xAA, 0xAB}, + {0x54, 0x55, 0x59, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA6, 0xA9, 0xAA}, + {0x51, 0x54, 0x55, 0x56, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA, 0xEA}, + {0x51, 0x55, 0x56, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, + {0x51, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xAA, 0xAB}, + {0x54, 0x55, 0x59, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA9, 0xAA}, + {0x54, 0x55, 0x59, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, + {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, + {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA6, 0xA9, 0xAA, 0xAB}, + {0x54, 0x55, 0x58, 0x59, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA9, 0xAA, 0xAD, 0xAE}, + {0x54, 0x55, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA5, 0xA9, 0xAA, 0xAE}, + {0x55, 0x56, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA6, 0xA9, 0xAA, 0xAE}, + {0x55, 0x56, 0x59, 0x5A, 0x66, 0x69, 0x6A, 0x96, 0x99, 0x9A, 0xA6, 0xA9, 0xAA, 0xAB, 0xAE, 0xAF}, + {0x50, 0x51, 0x54, 0x55, 0x61, 0x64, 0x65, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xB5, 0xBA}, + {0x51, 0x55, 0x61, 0x65, 0x66, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xB6, 0xBA}, + {0x51, 0x55, 0x56, 0x61, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xAA, 0xB6, 0xBA}, + {0x51, 0x55, 0x56, 0x65, 0x66, 0x6A, 0x96, 0xA5, 0xA6, 0xA7, 0xAA, 0xAB, 0xB6, 0xBA, 0xBB}, + {0x54, 0x55, 0x64, 0x65, 0x69, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xB9, 0xBA}, + {0x55, 0x65, 0x66, 0x69, 0x6A, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, + {0x51, 0x55, 0x56, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, + {0x51, 0x55, 0x56, 0x65, 0x66, 0x6A, 0x96, 0xA5, 0xA6, 0xAA, 0xAB, 0xBA, 0xBB}, + {0x54, 0x55, 0x59, 0x64, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA9, 0xAA, 0xB9, 0xBA}, + {0x54, 0x55, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x99, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, + {0x55, 0x56, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, + {0x55, 0x56, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x96, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAB, 0xBA, 0xBB}, + {0x54, 0x55, 0x59, 0x65, 0x69, 0x6A, 0x99, 0xA5, 0xA9, 0xAA, 0xAD, 0xAE, 0xB9, 0xBA, 0xBE}, + {0x54, 0x55, 0x59, 0x65, 0x69, 0x6A, 0x99, 0xA5, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, + {0x55, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, + {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x9A, 0xA6, 0xA9, 0xAA, 0xAB, 0xAE, 0xBA}, + {0x40, 0x45, 0x51, 0x54, 0x55, 0x85, 0x91, 0x94, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, + {0x41, 0x45, 0x51, 0x55, 0x56, 0x85, 0x91, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xAA, 0xEA}, + {0x41, 0x45, 0x51, 0x55, 0x56, 0x85, 0x91, 0x95, 0x96, 0x9A, 0xA6, 0xAA, 0xD6, 0xEA}, + {0x41, 0x45, 0x51, 0x55, 0x56, 0x86, 0x92, 0x95, 0x96, 0x97, 0x9A, 0xA6, 0xAA, 0xAB, 0xD6, 0xEA, 0xEB}, + {0x44, 0x45, 0x54, 0x55, 0x59, 0x85, 0x94, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA9, 0xAA, 0xEA}, + {0x45, 0x55, 0x85, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xDA, 0xEA}, + {0x45, 0x55, 0x56, 0x85, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xAA, 0xDA, 0xEA}, + {0x45, 0x55, 0x56, 0x86, 0x95, 0x96, 0x9A, 0x9B, 0xA6, 0xAA, 0xAB, 0xDA, 0xEA, 0xEB}, + {0x44, 0x45, 0x54, 0x55, 0x59, 0x85, 0x94, 0x95, 0x99, 0x9A, 0xA9, 0xAA, 0xD9, 0xEA}, + {0x45, 0x55, 0x59, 0x85, 0x95, 0x96, 0x99, 0x9A, 0xA9, 0xAA, 0xDA, 0xEA}, + {0x45, 0x55, 0x56, 0x59, 0x5A, 0x85, 0x95, 0x96, 0x99, 0x9A, 0xAA, 0xDA, 0xEA}, + {0x45, 0x55, 0x56, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0x9B, 0xA6, 0xAA, 0xAB, 0xDA, 0xEA, 0xEB}, + {0x44, 0x45, 0x54, 0x55, 0x59, 0x89, 0x95, 0x98, 0x99, 0x9A, 0x9D, 0xA9, 0xAA, 0xAE, 0xD9, 0xEA, 0xEE}, + {0x45, 0x55, 0x59, 0x89, 0x95, 0x99, 0x9A, 0x9E, 0xA9, 0xAA, 0xAE, 0xDA, 0xEA, 0xEE}, + {0x45, 0x55, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0x9E, 0xA9, 0xAA, 0xAE, 0xDA, 0xEA, 0xEE}, + {0x45, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0x9B, 0x9E, 0xAA, 0xAB, 0xAE, 0xDA, 0xEA, 0xEF}, + {0x50, 0x51, 0x54, 0x55, 0x65, 0x91, 0x94, 0x95, 0x96, 0x99, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, + {0x51, 0x55, 0x91, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xE6, 0xEA}, + {0x51, 0x55, 0x56, 0x91, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xAA, 0xE6, 0xEA}, + {0x51, 0x55, 0x56, 0x92, 0x95, 0x96, 0x9A, 0xA6, 0xA7, 0xAA, 0xAB, 0xE6, 0xEA, 0xEB}, + {0x54, 0x55, 0x94, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xE9, 0xEA}, + {0x55, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, + {0x55, 0x56, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, + {0x55, 0x56, 0x95, 0x96, 0x9A, 0xA6, 0xAA, 0xAB, 0xEA, 0xEB}, + {0x54, 0x55, 0x59, 0x94, 0x95, 0x99, 0x9A, 0xA5, 0xA9, 0xAA, 0xE9, 0xEA}, + {0x55, 0x59, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, + {0x45, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, + {0x45, 0x55, 0x56, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xAA, 0xAB, 0xEA, 0xEB}, + {0x54, 0x55, 0x59, 0x95, 0x98, 0x99, 0x9A, 0xA9, 0xAA, 0xAD, 0xAE, 0xE9, 0xEA, 0xEE}, + {0x55, 0x59, 0x95, 0x99, 0x9A, 0xA9, 0xAA, 0xAE, 0xEA, 0xEE}, + {0x45, 0x55, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xA9, 0xAA, 0xAE, 0xEA, 0xEE}, + {0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xAA, 0xAB, 0xAE, 0xEA, 0xEF}, + {0x50, 0x51, 0x54, 0x55, 0x65, 0x91, 0x94, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xE5, 0xEA}, + {0x51, 0x55, 0x65, 0x91, 0x95, 0x96, 0xA5, 0xA6, 0xA9, 0xAA, 0xE6, 0xEA}, + {0x51, 0x55, 0x56, 0x65, 0x66, 0x91, 0x95, 0x96, 0xA5, 0xA6, 0xAA, 0xE6, 0xEA}, + {0x51, 0x55, 0x56, 0x66, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xA7, 0xAA, 0xAB, 0xE6, 0xEA, 0xEB}, + {0x54, 0x55, 0x65, 0x94, 0x95, 0x99, 0xA5, 0xA6, 0xA9, 0xAA, 0xE9, 0xEA}, + {0x55, 0x65, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, + {0x51, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, + {0x51, 0x55, 0x56, 0x66, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xAA, 0xAB, 0xEA, 0xEB}, + {0x54, 0x55, 0x59, 0x65, 0x69, 0x94, 0x95, 0x99, 0xA5, 0xA9, 0xAA, 0xE9, 0xEA}, + {0x54, 0x55, 0x59, 0x65, 0x69, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, + {0x55, 0x56, 0x59, 0x65, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, + {0x55, 0x56, 0x5A, 0x66, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAB, 0xEA, 0xEB}, + {0x54, 0x55, 0x59, 0x69, 0x95, 0x99, 0x9A, 0xA5, 0xA9, 0xAA, 0xAD, 0xAE, 0xE9, 0xEA, 0xEE}, + {0x54, 0x55, 0x59, 0x69, 0x95, 0x99, 0x9A, 0xA5, 0xA9, 0xAA, 0xAE, 0xEA, 0xEE}, + {0x55, 0x59, 0x5A, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAE, 0xEA, 0xEE}, + {0x55, 0x56, 0x59, 0x5A, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xA9, 0xAA, 0xAB, 0xAE, 0xEA}, + {0x50, 0x51, 0x54, 0x55, 0x65, 0x95, 0xA1, 0xA4, 0xA5, 0xA6, 0xA9, 0xAA, 0xB5, 0xBA, 0xE5, 0xEA, 0xFA}, + {0x51, 0x55, 0x65, 0x95, 0xA1, 0xA5, 0xA6, 0xA9, 0xAA, 0xB6, 0xBA, 0xE6, 0xEA, 0xFA}, + {0x51, 0x55, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xA9, 0xAA, 0xB6, 0xBA, 0xE6, 0xEA, 0xFA}, + {0x51, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xA7, 0xAA, 0xAB, 0xB6, 0xBA, 0xE6, 0xEA, 0xFB}, + {0x54, 0x55, 0x65, 0x95, 0xA4, 0xA5, 0xA6, 0xA9, 0xAA, 0xB9, 0xBA, 0xE9, 0xEA, 0xFA}, + {0x55, 0x65, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA, 0xEA, 0xFA}, + {0x51, 0x55, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA, 0xEA, 0xFA}, + {0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xAA, 0xAB, 0xBA, 0xEA, 0xFB}, + {0x54, 0x55, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA6, 0xA9, 0xAA, 0xB9, 0xBA, 0xE9, 0xEA, 0xFA}, + {0x54, 0x55, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA, 0xEA, 0xFA}, + {0x55, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA, 0xEA, 0xFA}, + {0x55, 0x56, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAB, 0xBA, 0xEA}, + {0x54, 0x55, 0x59, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA9, 0xAA, 0xAD, 0xAE, 0xB9, 0xBA, 0xE9, 0xEA, 0xFE}, + {0x55, 0x59, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA9, 0xAA, 0xAE, 0xBA, 0xEA, 0xFE}, + {0x55, 0x59, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAE, 0xBA, 0xEA}, + {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAB, 0xAE, 0xBA, 0xEA},}; + LatticePoint4D[] latticePoints = new LatticePoint4D[256]; + for (int i = 0; i < 256; i++) { + int cx = ((i) & 3) - 1; + int cy = ((i >> 2) & 3) - 1; + int cz = ((i >> 4) & 3) - 1; + int cw = ((i >> 6) & 3) - 1; + latticePoints[i] = new LatticePoint4D(cx, cy, cz, cw); + } + for (int i = 0; i < 256; i++) { + LOOKUP_4D[i] = new LatticePoint4D[lookup4DPregen[i].length]; + for (int j = 0; j < lookup4DPregen[i].length; j++) { + LOOKUP_4D[i][j] = latticePoints[lookup4DPregen[i][j]]; + } + } + } + + private static class LatticePoint2D { + + int xsv, ysv; + double dx, dy; + + public LatticePoint2D(int xsv, int ysv) { + this.xsv = xsv; + this.ysv = ysv; + double ssv = (xsv + ysv) * -0.211324865405187; + this.dx = -xsv - ssv; + this.dy = -ysv - ssv; + } + } + + private static class LatticePoint3D { + + public double dxr, dyr, dzr; + public int xrv, yrv, zrv; + LatticePoint3D nextOnFailure, nextOnSuccess; + + public LatticePoint3D(int xrv, int yrv, int zrv, int lattice) { + this.dxr = -xrv + lattice * 0.5; + this.dyr = -yrv + lattice * 0.5; + this.dzr = -zrv + lattice * 0.5; + this.xrv = xrv + lattice * 1024; + this.yrv = yrv + lattice * 1024; + this.zrv = zrv + lattice * 1024; + } + } + + private static class LatticePoint4D { + + int xsv, ysv, zsv, wsv; + double dx, dy, dz, dw; + + public LatticePoint4D(int xsv, int ysv, int zsv, int wsv) { + this.xsv = xsv; + this.ysv = ysv; + this.zsv = zsv; + this.wsv = wsv; + double ssv = (xsv + ysv + zsv + wsv) * -0.138196601125011; + this.dx = -xsv - ssv; + this.dy = -ysv - ssv; + this.dz = -zsv - ssv; + this.dw = -wsv - ssv; + } + } + + /* + * Gradients + */ + private static class Grad2 { + + double dx, dy; + + public Grad2(double dx, double dy) { + this.dx = dx; + this.dy = dy; + } + } + + private static class Grad3 { + + double dx, dy, dz; + + public Grad3(double dx, double dy, double dz) { + this.dx = dx; + this.dy = dy; + this.dz = dz; + } + } + + private static class Grad4 { + + double dx, dy, dz, dw; + + public Grad4(double dx, double dy, double dz, double dw) { + this.dx = dx; + this.dy = dy; + this.dz = dz; + this.dw = dw; + } + } + + private static final double N2 = 0.05481866495625118; + private static final double N3 = 0.2781926117527186; + private static final double N4 = 0.11127401889945551; + private static final Grad2[] GRADIENTS_2D; + private static final Grad3[] GRADIENTS_3D; + private static final Grad4[] GRADIENTS_4D; + + static { + + GRADIENTS_2D = new Grad2[PSIZE]; + Grad2[] grad2 = { + new Grad2(0.130526192220052, 0.99144486137381), + new Grad2(0.38268343236509, 0.923879532511287), + new Grad2(0.608761429008721, 0.793353340291235), + new Grad2(0.793353340291235, 0.608761429008721), + new Grad2(0.923879532511287, 0.38268343236509), + new Grad2(0.99144486137381, 0.130526192220051), + new Grad2(0.99144486137381, -0.130526192220051), + new Grad2(0.923879532511287, -0.38268343236509), + new Grad2(0.793353340291235, -0.60876142900872), + new Grad2(0.608761429008721, -0.793353340291235), + new Grad2(0.38268343236509, -0.923879532511287), + new Grad2(0.130526192220052, -0.99144486137381), + new Grad2(-0.130526192220052, -0.99144486137381), + new Grad2(-0.38268343236509, -0.923879532511287), + new Grad2(-0.608761429008721, -0.793353340291235), + new Grad2(-0.793353340291235, -0.608761429008721), + new Grad2(-0.923879532511287, -0.38268343236509), + new Grad2(-0.99144486137381, -0.130526192220052), + new Grad2(-0.99144486137381, 0.130526192220051), + new Grad2(-0.923879532511287, 0.38268343236509), + new Grad2(-0.793353340291235, 0.608761429008721), + new Grad2(-0.608761429008721, 0.793353340291235), + new Grad2(-0.38268343236509, 0.923879532511287), + new Grad2(-0.130526192220052, 0.99144486137381) + }; + Grad2[] grad2XBeforeY = new Grad2[grad2.length]; + for (Grad2 grad21 : grad2) { + grad21.dx /= N2; + grad21.dy /= N2; + } + for (int i = 0; i < PSIZE; i++) { + GRADIENTS_2D[i] = grad2[i % grad2.length]; + } + + GRADIENTS_3D = new Grad3[PSIZE]; + Grad3[] grad3 = { + new Grad3(-2.22474487139, -2.22474487139, -1.0), + new Grad3(-2.22474487139, -2.22474487139, 1.0), + new Grad3(-3.0862664687972017, -1.1721513422464978, 0.0), + new Grad3(-1.1721513422464978, -3.0862664687972017, 0.0), + new Grad3(-2.22474487139, -1.0, -2.22474487139), + new Grad3(-2.22474487139, 1.0, -2.22474487139), + new Grad3(-1.1721513422464978, 0.0, -3.0862664687972017), + new Grad3(-3.0862664687972017, 0.0, -1.1721513422464978), + new Grad3(-2.22474487139, -1.0, 2.22474487139), + new Grad3(-2.22474487139, 1.0, 2.22474487139), + new Grad3(-3.0862664687972017, 0.0, 1.1721513422464978), + new Grad3(-1.1721513422464978, 0.0, 3.0862664687972017), + new Grad3(-2.22474487139, 2.22474487139, -1.0), + new Grad3(-2.22474487139, 2.22474487139, 1.0), + new Grad3(-1.1721513422464978, 3.0862664687972017, 0.0), + new Grad3(-3.0862664687972017, 1.1721513422464978, 0.0), + new Grad3(-1.0, -2.22474487139, -2.22474487139), + new Grad3(1.0, -2.22474487139, -2.22474487139), + new Grad3(0.0, -3.0862664687972017, -1.1721513422464978), + new Grad3(0.0, -1.1721513422464978, -3.0862664687972017), + new Grad3(-1.0, -2.22474487139, 2.22474487139), + new Grad3(1.0, -2.22474487139, 2.22474487139), + new Grad3(0.0, -1.1721513422464978, 3.0862664687972017), + new Grad3(0.0, -3.0862664687972017, 1.1721513422464978), + new Grad3(-1.0, 2.22474487139, -2.22474487139), + new Grad3(1.0, 2.22474487139, -2.22474487139), + new Grad3(0.0, 1.1721513422464978, -3.0862664687972017), + new Grad3(0.0, 3.0862664687972017, -1.1721513422464978), + new Grad3(-1.0, 2.22474487139, 2.22474487139), + new Grad3(1.0, 2.22474487139, 2.22474487139), + new Grad3(0.0, 3.0862664687972017, 1.1721513422464978), + new Grad3(0.0, 1.1721513422464978, 3.0862664687972017), + new Grad3(2.22474487139, -2.22474487139, -1.0), + new Grad3(2.22474487139, -2.22474487139, 1.0), + new Grad3(1.1721513422464978, -3.0862664687972017, 0.0), + new Grad3(3.0862664687972017, -1.1721513422464978, 0.0), + new Grad3(2.22474487139, -1.0, -2.22474487139), + new Grad3(2.22474487139, 1.0, -2.22474487139), + new Grad3(3.0862664687972017, 0.0, -1.1721513422464978), + new Grad3(1.1721513422464978, 0.0, -3.0862664687972017), + new Grad3(2.22474487139, -1.0, 2.22474487139), + new Grad3(2.22474487139, 1.0, 2.22474487139), + new Grad3(1.1721513422464978, 0.0, 3.0862664687972017), + new Grad3(3.0862664687972017, 0.0, 1.1721513422464978), + new Grad3(2.22474487139, 2.22474487139, -1.0), + new Grad3(2.22474487139, 2.22474487139, 1.0), + new Grad3(3.0862664687972017, 1.1721513422464978, 0.0), + new Grad3(1.1721513422464978, 3.0862664687972017, 0.0) + }; + for (Grad3 grad31 : grad3) { + grad31.dx /= N3; + grad31.dy /= N3; + grad31.dz /= N3; + } + for (int i = 0; i < PSIZE; i++) { + GRADIENTS_3D[i] = grad3[i % grad3.length]; + } + + GRADIENTS_4D = new Grad4[PSIZE]; + Grad4[] grad4 = { + new Grad4(-0.753341017856078, -0.37968289875261624, -0.37968289875261624, -0.37968289875261624), + new Grad4(-0.7821684431180708, -0.4321472685365301, -0.4321472685365301, 0.12128480194602098), + new Grad4(-0.7821684431180708, -0.4321472685365301, 0.12128480194602098, -0.4321472685365301), + new Grad4(-0.7821684431180708, 0.12128480194602098, -0.4321472685365301, -0.4321472685365301), + new Grad4(-0.8586508742123365, -0.508629699630796, 0.044802370851755174, 0.044802370851755174), + new Grad4(-0.8586508742123365, 0.044802370851755174, -0.508629699630796, 0.044802370851755174), + new Grad4(-0.8586508742123365, 0.044802370851755174, 0.044802370851755174, -0.508629699630796), + new Grad4(-0.9982828964265062, -0.03381941603233842, -0.03381941603233842, -0.03381941603233842), + new Grad4(-0.37968289875261624, -0.753341017856078, -0.37968289875261624, -0.37968289875261624), + new Grad4(-0.4321472685365301, -0.7821684431180708, -0.4321472685365301, 0.12128480194602098), + new Grad4(-0.4321472685365301, -0.7821684431180708, 0.12128480194602098, -0.4321472685365301), + new Grad4(0.12128480194602098, -0.7821684431180708, -0.4321472685365301, -0.4321472685365301), + new Grad4(-0.508629699630796, -0.8586508742123365, 0.044802370851755174, 0.044802370851755174), + new Grad4(0.044802370851755174, -0.8586508742123365, -0.508629699630796, 0.044802370851755174), + new Grad4(0.044802370851755174, -0.8586508742123365, 0.044802370851755174, -0.508629699630796), + new Grad4(-0.03381941603233842, -0.9982828964265062, -0.03381941603233842, -0.03381941603233842), + new Grad4(-0.37968289875261624, -0.37968289875261624, -0.753341017856078, -0.37968289875261624), + new Grad4(-0.4321472685365301, -0.4321472685365301, -0.7821684431180708, 0.12128480194602098), + new Grad4(-0.4321472685365301, 0.12128480194602098, -0.7821684431180708, -0.4321472685365301), + new Grad4(0.12128480194602098, -0.4321472685365301, -0.7821684431180708, -0.4321472685365301), + new Grad4(-0.508629699630796, 0.044802370851755174, -0.8586508742123365, 0.044802370851755174), + new Grad4(0.044802370851755174, -0.508629699630796, -0.8586508742123365, 0.044802370851755174), + new Grad4(0.044802370851755174, 0.044802370851755174, -0.8586508742123365, -0.508629699630796), + new Grad4(-0.03381941603233842, -0.03381941603233842, -0.9982828964265062, -0.03381941603233842), + new Grad4(-0.37968289875261624, -0.37968289875261624, -0.37968289875261624, -0.753341017856078), + new Grad4(-0.4321472685365301, -0.4321472685365301, 0.12128480194602098, -0.7821684431180708), + new Grad4(-0.4321472685365301, 0.12128480194602098, -0.4321472685365301, -0.7821684431180708), + new Grad4(0.12128480194602098, -0.4321472685365301, -0.4321472685365301, -0.7821684431180708), + new Grad4(-0.508629699630796, 0.044802370851755174, 0.044802370851755174, -0.8586508742123365), + new Grad4(0.044802370851755174, -0.508629699630796, 0.044802370851755174, -0.8586508742123365), + new Grad4(0.044802370851755174, 0.044802370851755174, -0.508629699630796, -0.8586508742123365), + new Grad4(-0.03381941603233842, -0.03381941603233842, -0.03381941603233842, -0.9982828964265062), + new Grad4(-0.6740059517812944, -0.3239847771997537, -0.3239847771997537, 0.5794684678643381), + new Grad4(-0.7504883828755602, -0.4004672082940195, 0.15296486218853164, 0.5029860367700724), + new Grad4(-0.7504883828755602, 0.15296486218853164, -0.4004672082940195, 0.5029860367700724), + new Grad4(-0.8828161875373585, 0.08164729285680945, 0.08164729285680945, 0.4553054119602712), + new Grad4(-0.4553054119602712, -0.08164729285680945, -0.08164729285680945, 0.8828161875373585), + new Grad4(-0.5029860367700724, -0.15296486218853164, 0.4004672082940195, 0.7504883828755602), + new Grad4(-0.5029860367700724, 0.4004672082940195, -0.15296486218853164, 0.7504883828755602), + new Grad4(-0.5794684678643381, 0.3239847771997537, 0.3239847771997537, 0.6740059517812944), + new Grad4(-0.3239847771997537, -0.6740059517812944, -0.3239847771997537, 0.5794684678643381), + new Grad4(-0.4004672082940195, -0.7504883828755602, 0.15296486218853164, 0.5029860367700724), + new Grad4(0.15296486218853164, -0.7504883828755602, -0.4004672082940195, 0.5029860367700724), + new Grad4(0.08164729285680945, -0.8828161875373585, 0.08164729285680945, 0.4553054119602712), + new Grad4(-0.08164729285680945, -0.4553054119602712, -0.08164729285680945, 0.8828161875373585), + new Grad4(-0.15296486218853164, -0.5029860367700724, 0.4004672082940195, 0.7504883828755602), + new Grad4(0.4004672082940195, -0.5029860367700724, -0.15296486218853164, 0.7504883828755602), + new Grad4(0.3239847771997537, -0.5794684678643381, 0.3239847771997537, 0.6740059517812944), + new Grad4(-0.3239847771997537, -0.3239847771997537, -0.6740059517812944, 0.5794684678643381), + new Grad4(-0.4004672082940195, 0.15296486218853164, -0.7504883828755602, 0.5029860367700724), + new Grad4(0.15296486218853164, -0.4004672082940195, -0.7504883828755602, 0.5029860367700724), + new Grad4(0.08164729285680945, 0.08164729285680945, -0.8828161875373585, 0.4553054119602712), + new Grad4(-0.08164729285680945, -0.08164729285680945, -0.4553054119602712, 0.8828161875373585), + new Grad4(-0.15296486218853164, 0.4004672082940195, -0.5029860367700724, 0.7504883828755602), + new Grad4(0.4004672082940195, -0.15296486218853164, -0.5029860367700724, 0.7504883828755602), + new Grad4(0.3239847771997537, 0.3239847771997537, -0.5794684678643381, 0.6740059517812944), + new Grad4(-0.6740059517812944, -0.3239847771997537, 0.5794684678643381, -0.3239847771997537), + new Grad4(-0.7504883828755602, -0.4004672082940195, 0.5029860367700724, 0.15296486218853164), + new Grad4(-0.7504883828755602, 0.15296486218853164, 0.5029860367700724, -0.4004672082940195), + new Grad4(-0.8828161875373585, 0.08164729285680945, 0.4553054119602712, 0.08164729285680945), + new Grad4(-0.4553054119602712, -0.08164729285680945, 0.8828161875373585, -0.08164729285680945), + new Grad4(-0.5029860367700724, -0.15296486218853164, 0.7504883828755602, 0.4004672082940195), + new Grad4(-0.5029860367700724, 0.4004672082940195, 0.7504883828755602, -0.15296486218853164), + new Grad4(-0.5794684678643381, 0.3239847771997537, 0.6740059517812944, 0.3239847771997537), + new Grad4(-0.3239847771997537, -0.6740059517812944, 0.5794684678643381, -0.3239847771997537), + new Grad4(-0.4004672082940195, -0.7504883828755602, 0.5029860367700724, 0.15296486218853164), + new Grad4(0.15296486218853164, -0.7504883828755602, 0.5029860367700724, -0.4004672082940195), + new Grad4(0.08164729285680945, -0.8828161875373585, 0.4553054119602712, 0.08164729285680945), + new Grad4(-0.08164729285680945, -0.4553054119602712, 0.8828161875373585, -0.08164729285680945), + new Grad4(-0.15296486218853164, -0.5029860367700724, 0.7504883828755602, 0.4004672082940195), + new Grad4(0.4004672082940195, -0.5029860367700724, 0.7504883828755602, -0.15296486218853164), + new Grad4(0.3239847771997537, -0.5794684678643381, 0.6740059517812944, 0.3239847771997537), + new Grad4(-0.3239847771997537, -0.3239847771997537, 0.5794684678643381, -0.6740059517812944), + new Grad4(-0.4004672082940195, 0.15296486218853164, 0.5029860367700724, -0.7504883828755602), + new Grad4(0.15296486218853164, -0.4004672082940195, 0.5029860367700724, -0.7504883828755602), + new Grad4(0.08164729285680945, 0.08164729285680945, 0.4553054119602712, -0.8828161875373585), + new Grad4(-0.08164729285680945, -0.08164729285680945, 0.8828161875373585, -0.4553054119602712), + new Grad4(-0.15296486218853164, 0.4004672082940195, 0.7504883828755602, -0.5029860367700724), + new Grad4(0.4004672082940195, -0.15296486218853164, 0.7504883828755602, -0.5029860367700724), + new Grad4(0.3239847771997537, 0.3239847771997537, 0.6740059517812944, -0.5794684678643381), + new Grad4(-0.6740059517812944, 0.5794684678643381, -0.3239847771997537, -0.3239847771997537), + new Grad4(-0.7504883828755602, 0.5029860367700724, -0.4004672082940195, 0.15296486218853164), + new Grad4(-0.7504883828755602, 0.5029860367700724, 0.15296486218853164, -0.4004672082940195), + new Grad4(-0.8828161875373585, 0.4553054119602712, 0.08164729285680945, 0.08164729285680945), + new Grad4(-0.4553054119602712, 0.8828161875373585, -0.08164729285680945, -0.08164729285680945), + new Grad4(-0.5029860367700724, 0.7504883828755602, -0.15296486218853164, 0.4004672082940195), + new Grad4(-0.5029860367700724, 0.7504883828755602, 0.4004672082940195, -0.15296486218853164), + new Grad4(-0.5794684678643381, 0.6740059517812944, 0.3239847771997537, 0.3239847771997537), + new Grad4(-0.3239847771997537, 0.5794684678643381, -0.6740059517812944, -0.3239847771997537), + new Grad4(-0.4004672082940195, 0.5029860367700724, -0.7504883828755602, 0.15296486218853164), + new Grad4(0.15296486218853164, 0.5029860367700724, -0.7504883828755602, -0.4004672082940195), + new Grad4(0.08164729285680945, 0.4553054119602712, -0.8828161875373585, 0.08164729285680945), + new Grad4(-0.08164729285680945, 0.8828161875373585, -0.4553054119602712, -0.08164729285680945), + new Grad4(-0.15296486218853164, 0.7504883828755602, -0.5029860367700724, 0.4004672082940195), + new Grad4(0.4004672082940195, 0.7504883828755602, -0.5029860367700724, -0.15296486218853164), + new Grad4(0.3239847771997537, 0.6740059517812944, -0.5794684678643381, 0.3239847771997537), + new Grad4(-0.3239847771997537, 0.5794684678643381, -0.3239847771997537, -0.6740059517812944), + new Grad4(-0.4004672082940195, 0.5029860367700724, 0.15296486218853164, -0.7504883828755602), + new Grad4(0.15296486218853164, 0.5029860367700724, -0.4004672082940195, -0.7504883828755602), + new Grad4(0.08164729285680945, 0.4553054119602712, 0.08164729285680945, -0.8828161875373585), + new Grad4(-0.08164729285680945, 0.8828161875373585, -0.08164729285680945, -0.4553054119602712), + new Grad4(-0.15296486218853164, 0.7504883828755602, 0.4004672082940195, -0.5029860367700724), + new Grad4(0.4004672082940195, 0.7504883828755602, -0.15296486218853164, -0.5029860367700724), + new Grad4(0.3239847771997537, 0.6740059517812944, 0.3239847771997537, -0.5794684678643381), + new Grad4(0.5794684678643381, -0.6740059517812944, -0.3239847771997537, -0.3239847771997537), + new Grad4(0.5029860367700724, -0.7504883828755602, -0.4004672082940195, 0.15296486218853164), + new Grad4(0.5029860367700724, -0.7504883828755602, 0.15296486218853164, -0.4004672082940195), + new Grad4(0.4553054119602712, -0.8828161875373585, 0.08164729285680945, 0.08164729285680945), + new Grad4(0.8828161875373585, -0.4553054119602712, -0.08164729285680945, -0.08164729285680945), + new Grad4(0.7504883828755602, -0.5029860367700724, -0.15296486218853164, 0.4004672082940195), + new Grad4(0.7504883828755602, -0.5029860367700724, 0.4004672082940195, -0.15296486218853164), + new Grad4(0.6740059517812944, -0.5794684678643381, 0.3239847771997537, 0.3239847771997537), + new Grad4(0.5794684678643381, -0.3239847771997537, -0.6740059517812944, -0.3239847771997537), + new Grad4(0.5029860367700724, -0.4004672082940195, -0.7504883828755602, 0.15296486218853164), + new Grad4(0.5029860367700724, 0.15296486218853164, -0.7504883828755602, -0.4004672082940195), + new Grad4(0.4553054119602712, 0.08164729285680945, -0.8828161875373585, 0.08164729285680945), + new Grad4(0.8828161875373585, -0.08164729285680945, -0.4553054119602712, -0.08164729285680945), + new Grad4(0.7504883828755602, -0.15296486218853164, -0.5029860367700724, 0.4004672082940195), + new Grad4(0.7504883828755602, 0.4004672082940195, -0.5029860367700724, -0.15296486218853164), + new Grad4(0.6740059517812944, 0.3239847771997537, -0.5794684678643381, 0.3239847771997537), + new Grad4(0.5794684678643381, -0.3239847771997537, -0.3239847771997537, -0.6740059517812944), + new Grad4(0.5029860367700724, -0.4004672082940195, 0.15296486218853164, -0.7504883828755602), + new Grad4(0.5029860367700724, 0.15296486218853164, -0.4004672082940195, -0.7504883828755602), + new Grad4(0.4553054119602712, 0.08164729285680945, 0.08164729285680945, -0.8828161875373585), + new Grad4(0.8828161875373585, -0.08164729285680945, -0.08164729285680945, -0.4553054119602712), + new Grad4(0.7504883828755602, -0.15296486218853164, 0.4004672082940195, -0.5029860367700724), + new Grad4(0.7504883828755602, 0.4004672082940195, -0.15296486218853164, -0.5029860367700724), + new Grad4(0.6740059517812944, 0.3239847771997537, 0.3239847771997537, -0.5794684678643381), + new Grad4(0.03381941603233842, 0.03381941603233842, 0.03381941603233842, 0.9982828964265062), + new Grad4(-0.044802370851755174, -0.044802370851755174, 0.508629699630796, 0.8586508742123365), + new Grad4(-0.044802370851755174, 0.508629699630796, -0.044802370851755174, 0.8586508742123365), + new Grad4(-0.12128480194602098, 0.4321472685365301, 0.4321472685365301, 0.7821684431180708), + new Grad4(0.508629699630796, -0.044802370851755174, -0.044802370851755174, 0.8586508742123365), + new Grad4(0.4321472685365301, -0.12128480194602098, 0.4321472685365301, 0.7821684431180708), + new Grad4(0.4321472685365301, 0.4321472685365301, -0.12128480194602098, 0.7821684431180708), + new Grad4(0.37968289875261624, 0.37968289875261624, 0.37968289875261624, 0.753341017856078), + new Grad4(0.03381941603233842, 0.03381941603233842, 0.9982828964265062, 0.03381941603233842), + new Grad4(-0.044802370851755174, 0.044802370851755174, 0.8586508742123365, 0.508629699630796), + new Grad4(-0.044802370851755174, 0.508629699630796, 0.8586508742123365, -0.044802370851755174), + new Grad4(-0.12128480194602098, 0.4321472685365301, 0.7821684431180708, 0.4321472685365301), + new Grad4(0.508629699630796, -0.044802370851755174, 0.8586508742123365, -0.044802370851755174), + new Grad4(0.4321472685365301, -0.12128480194602098, 0.7821684431180708, 0.4321472685365301), + new Grad4(0.4321472685365301, 0.4321472685365301, 0.7821684431180708, -0.12128480194602098), + new Grad4(0.37968289875261624, 0.37968289875261624, 0.753341017856078, 0.37968289875261624), + new Grad4(0.03381941603233842, 0.9982828964265062, 0.03381941603233842, 0.03381941603233842), + new Grad4(-0.044802370851755174, 0.8586508742123365, -0.044802370851755174, 0.508629699630796), + new Grad4(-0.044802370851755174, 0.8586508742123365, 0.508629699630796, -0.044802370851755174), + new Grad4(-0.12128480194602098, 0.7821684431180708, 0.4321472685365301, 0.4321472685365301), + new Grad4(0.508629699630796, 0.8586508742123365, -0.044802370851755174, -0.044802370851755174), + new Grad4(0.4321472685365301, 0.7821684431180708, -0.12128480194602098, 0.4321472685365301), + new Grad4(0.4321472685365301, 0.7821684431180708, 0.4321472685365301, -0.12128480194602098), + new Grad4(0.37968289875261624, 0.753341017856078, 0.37968289875261624, 0.37968289875261624), + new Grad4(0.9982828964265062, 0.03381941603233842, 0.03381941603233842, 0.03381941603233842), + new Grad4(0.8586508742123365, -0.044802370851755174, -0.044802370851755174, 0.508629699630796), + new Grad4(0.8586508742123365, -0.044802370851755174, 0.508629699630796, -0.044802370851755174), + new Grad4(0.7821684431180708, -0.12128480194602098, 0.4321472685365301, 0.4321472685365301), + new Grad4(0.8586508742123365, 0.508629699630796, -0.044802370851755174, -0.044802370851755174), + new Grad4(0.7821684431180708, 0.4321472685365301, -0.12128480194602098, 0.4321472685365301), + new Grad4(0.7821684431180708, 0.4321472685365301, 0.4321472685365301, -0.12128480194602098), + new Grad4(0.753341017856078, 0.37968289875261624, 0.37968289875261624, 0.37968289875261624) + }; + for (Grad4 grad41 : grad4) { + grad41.dx /= N4; + grad41.dy /= N4; + grad41.dz /= N4; + grad41.dw /= N4; + } + for (int i = 0; i < PSIZE; i++) { + GRADIENTS_4D[i] = grad4[i % grad4.length]; + } + } +} diff --git a/src/main/java/monkstone/noise/SmoothTerrain.java b/src/main/java/monkstone/noise/SmoothTerrain.java deleted file mode 100644 index 08e87be..0000000 --- a/src/main/java/monkstone/noise/SmoothTerrain.java +++ /dev/null @@ -1,1099 +0,0 @@ -package monkstone.noise; - -/** - * K.jpg's OpenSimplex 2, smooth variant ("SuperSimplex") - * - * - 2D is standard simplex, modified to support larger kernels. Implemented - * using a lookup table. - 3D is "Re-oriented 8-point BCC noise" which - * constructs a congruent BCC lattice in a much different way than usual. - 4D - * uses a naïve pregenerated lookup table, and averages out to the expected - * performance. - * - * Multiple versions of each function are provided. See the documentation above - * each, for more info. - */ -public class SmoothTerrain implements Noise { - - private static final int PSIZE = 2048; - private static final int PMASK = 2047; - - private final short[] perm; - private final Grad2[] permGrad2; - private final Grad3[] permGrad3; - private final Grad4[] permGrad4; - - public SmoothTerrain(long seed) { - perm = new short[PSIZE]; - permGrad2 = new Grad2[PSIZE]; - permGrad3 = new Grad3[PSIZE]; - permGrad4 = new Grad4[PSIZE]; - short[] source = new short[PSIZE]; - for (short i = 0; i < PSIZE; i++) { - source[i] = i; - } - for (int i = PSIZE - 1; i >= 0; i--) { - seed = seed * 6364136223846793005L + 1442695040888963407L; - int r = (int) ((seed + 31) % (i + 1)); - if (r < 0) { - r += (i + 1); - } - perm[i] = source[r]; - permGrad2[i] = GRADIENTS_2D[perm[i]]; - permGrad3[i] = GRADIENTS_3D[perm[i]]; - permGrad4[i] = GRADIENTS_4D[perm[i]]; - source[r] = source[i]; - } - } - - /* - * Noise Evaluators - */ - /** - * 2D SuperSimplex noise, standard lattice orientation. - * - * @param x - * @param y - * @return - */ - public double noise2(double x, double y) { - - // Get points for A2* lattice - double s = 0.366025403784439 * (x + y); - double xs = x + s, ys = y + s; - - return noise2_Base(xs, ys); - } - - /** - * 2D SuperSimplex noise, with Y pointing down the main diagonal.Might be - * better for a 2D sandbox style game, where Y is vertical.Probably slightly - * less optimal for heightmaps or continent maps. - * - * @param x - * @param y - * @return - */ - public double noise2_XBeforeY(double x, double y) { - - // Skew transform and rotation baked into one. - double xx = x * 0.7071067811865476; - double yy = y * 1.224744871380249; - - return noise2_Base(yy + xx, yy - xx); - } - - /** - * 2D SuperSimplex noise base. Lookup table implementation inspired by - * DigitalShadow. - */ - private double noise2_Base(double xs, double ys) { - double value = 0; - - // Get base points and offsets - int xsb = fastFloor(xs), ysb = fastFloor(ys); - double xsi = xs - xsb, ysi = ys - ysb; - - // Index to point list - int a = (int) (xsi + ysi); - int index - = (a << 2) - | (int) (xsi - ysi / 2 + 1 - a / 2.0) << 3 - | (int) (ysi - xsi / 2 + 1 - a / 2.0) << 4; - - double ssi = (xsi + ysi) * -0.211324865405187; - double xi = xsi + ssi, yi = ysi + ssi; - - // Point contributions - for (int i = 0; i < 4; i++) { - LatticePoint2D c = LOOKUP_2D[index + i]; - - double dx = xi + c.dx, dy = yi + c.dy; - double attn = 2.0 / 3.0 - dx * dx - dy * dy; - if (attn <= 0) { - continue; - } - - int pxm = (xsb + c.xsv) & PMASK, pym = (ysb + c.ysv) & PMASK; - Grad2 grad = permGrad2[perm[pxm] ^ pym]; - double extrapolation = grad.dx * dx + grad.dy * dy; - - attn *= attn; - value += attn * attn * extrapolation; - } - - return value; - } - - /** - * 3D Re-oriented 8-point BCC noise, with better visual isotropy in (X, - * Y).Recommended for 3D terrain and time-varied animations.The Z coordinate - * should always be the "different" coordinate in your use case.If Y is - * vertical in world coordinates, call noise3_XYBeforeZ(x, z, Y) or use - * noise3_XZBeforeY.If Z is vertical in world coordinates, call - * noise3_XYBeforeZ(x, y, Z). For a time varied animation, call - * noise3_XYBeforeZ(x, y, T). - * - * @param x - * @param y - * @param z - * @return - */ - public double noise3_XYBeforeZ(double x, double y, double z) { - - // Re-orient the cubic lattices without skewing, to make X and Y triangular like 2D. - // Orthonormal rotation. Not a skew transform. - double xy = x + y; - double s2 = xy * -0.211324865405187; - double zz = z * 0.577350269189626; - double xr = x + s2 - zz, yr = y + s2 - zz; - double zr = xy * 0.577350269189626 + zz; - - // Evaluate both lattices to form a BCC lattice. - return noise3_BCC(xr, yr, zr); - } - - /** - * 3D Re-oriented 8-point BCC noise, with better visual isotropy in (X, - * Z).Recommended for 3D terrain and time-varied animations.The Y coordinate - * should always be the "different" coordinate in your use case.If Y is - * vertical in world coordinates, call noise3_XZBeforeY(x, Y, z).If Z is - * vertical in world coordinates, call noise3_XZBeforeY(x, Z, y) or use - * noise3_XYBeforeZ. For a time varied animation, call noise3_XZBeforeY(x, - * T, y) or use noise3_XYBeforeZ. - * - * @param x - * @param y - * @param z - * @return - */ - public double noise3_XZBeforeY(double x, double y, double z) { - - // Re-orient the cubic lattices without skewing, to make X and Z triangular like 2D. - // Orthonormal rotation. Not a skew transform. - double xz = x + z; - double s2 = xz * -0.211324865405187; - double yy = y * 0.577350269189626; - double xr = x + s2 - yy; - double zr = z + s2 - yy; - double yr = xz * 0.577350269189626 + yy; - - // Evaluate both lattices to form a BCC lattice. - return noise3_BCC(xr, yr, zr); - } - - /** - * Generate overlapping cubic lattices for 3D Re-oriented BCC noise. Lookup - * table implementation inspired by DigitalShadow. It was actually faster to - * narrow down the points in the loop itself, than to build up the index - * with enough info to isolate 8 points. - */ - private double noise3_BCC(double xr, double yr, double zr) { - - // Get base and offsets inside cube of first lattice. - int xrb = fastFloor(xr), yrb = fastFloor(yr), zrb = fastFloor(zr); - double xri = xr - xrb, yri = yr - yrb, zri = zr - zrb; - - // Identify which octant of the cube we're in. This determines which cell - // in the other cubic lattice we're in, and also narrows down one point on each. - int xht = (int) (xri + 0.5), yht = (int) (yri + 0.5), zht = (int) (zri + 0.5); - int index = (xht) | (yht << 1) | (zht << 2); - - // Point contributions - double value = 0; - LatticePoint3D c = LOOKUP_3D[index]; - while (c != null) { - double dxr = xri + c.dxr, dyr = yri + c.dyr, dzr = zri + c.dzr; - double attn = 0.75 - dxr * dxr - dyr * dyr - dzr * dzr; - if (attn < 0) { - c = c.nextOnFailure; - } else { - int pxm = (xrb + c.xrv) & PMASK, pym = (yrb + c.yrv) & PMASK, pzm = (zrb + c.zrv) & PMASK; - Grad3 grad = permGrad3[perm[perm[pxm] ^ pym] ^ pzm]; - double extrapolation = grad.dx * dxr + grad.dy * dyr + grad.dz * dzr; - - attn *= attn; - value += attn * attn * extrapolation; - c = c.nextOnSuccess; - } - } - return value; - } - - /** - * 4D SuperSimplex noise, with XY and ZW forming orthogonal triangular-based - * planes.Recommended for 3D terrain, where X and Y (or Z and W) are - * horizontal.Recommended for noise(x, y, sin(time), cos(time)) trick. - * - * @param x - * @param y - * @param z - * @param w - * @return - */ - public double noise4_XYBeforeZW(double x, double y, double z, double w) { - - double s2 = (x + y) * -0.28522513987434876941 + (z + w) * 0.83897065470611435718; - double t2 = (z + w) * 0.21939749883706435719 + (x + y) * -0.48214856493302476942; - double xs = x + s2, ys = y + s2, zs = z + t2, ws = w + t2; - - return noise4_Base(xs, ys, zs, ws); - } - - /** - * 4D SuperSimplex noise, with XZ and YW forming orthogonal triangular-based - * planes.Recommended for 3D terrain, where X and Z (or Y and W) are - * horizontal. - * - * @param x - * @param y - * @param z - * @param w - * @return - */ - public double noise4_XZBeforeYW(double x, double y, double z, double w) { - - double s2 = (x + z) * -0.28522513987434876941 + (y + w) * 0.83897065470611435718; - double t2 = (y + w) * 0.21939749883706435719 + (x + z) * -0.48214856493302476942; - double xs = x + s2, ys = y + t2, zs = z + s2, ws = w + t2; - - return noise4_Base(xs, ys, zs, ws); - } - - - /** - * 4D SuperSimplex noise base. Using ultra-simple 4x4x4x4 lookup - * partitioning. This isn't as elegant or SIMD/GPU/etc. portable as other - * approaches, but it does compete performance-wise with optimized - * OpenSimplex1. - */ - private double noise4_Base(double xs, double ys, double zs, double ws) { - double value = 0; - - // Get base points and offsets - int xsb = fastFloor(xs), ysb = fastFloor(ys), zsb = fastFloor(zs), wsb = fastFloor(ws); - double xsi = xs - xsb, ysi = ys - ysb, zsi = zs - zsb, wsi = ws - wsb; - - // Unskewed offsets - double ssi = (xsi + ysi + zsi + wsi) * -0.138196601125011; - double xi = xsi + ssi, yi = ysi + ssi, zi = zsi + ssi, wi = wsi + ssi; - - int index = ((fastFloor(xs * 4) & 3)) - | ((fastFloor(ys * 4) & 3) << 2) - | ((fastFloor(zs * 4) & 3) << 4) - | ((fastFloor(ws * 4) & 3) << 6); - - // Point contributions - for (LatticePoint4D c : LOOKUP_4D[index]) { - double dx = xi + c.dx, dy = yi + c.dy, dz = zi + c.dz, dw = wi + c.dw; - double attn = 0.8 - dx * dx - dy * dy - dz * dz - dw * dw; - if (attn > 0) { - attn *= attn; - - int pxm = (xsb + c.xsv) & PMASK, pym = (ysb + c.ysv) & PMASK; - int pzm = (zsb + c.zsv) & PMASK, pwm = (wsb + c.wsv) & PMASK; - Grad4 grad = permGrad4[perm[perm[perm[pxm] ^ pym] ^ pzm] ^ pwm]; - double extrapolation = grad.dx * dx + grad.dy * dy + grad.dz * dz + grad.dw * dw; - - value += attn * attn * extrapolation; - } - } - return value; - } - - /* - * Utility - */ - private static int fastFloor(double x) { - int xi = (int) x; - return x < xi ? xi - 1 : xi; - } - - /* - * Definitions - */ - private static final LatticePoint2D[] LOOKUP_2D; - private static final LatticePoint3D[] LOOKUP_3D; - private static final LatticePoint4D[][] LOOKUP_4D; - - static { - LOOKUP_2D = new LatticePoint2D[8 * 4]; - LOOKUP_3D = new LatticePoint3D[8]; - LOOKUP_4D = new LatticePoint4D[256][]; - - for (int i = 0; i < 8; i++) { - int i1, j1, i2, j2; - if ((i & 1) == 0) { - if ((i & 2) == 0) { - i1 = -1; - j1 = 0; - } else { - i1 = 1; - j1 = 0; - } - if ((i & 4) == 0) { - i2 = 0; - j2 = -1; - } else { - i2 = 0; - j2 = 1; - } - } else { - if ((i & 2) != 0) { - i1 = 2; - j1 = 1; - } else { - i1 = 0; - j1 = 1; - } - if ((i & 4) != 0) { - i2 = 1; - j2 = 2; - } else { - i2 = 1; - j2 = 0; - } - } - LOOKUP_2D[i * 4 + 0] = new LatticePoint2D(0, 0); - LOOKUP_2D[i * 4 + 1] = new LatticePoint2D(1, 1); - LOOKUP_2D[i * 4 + 2] = new LatticePoint2D(i1, j1); - LOOKUP_2D[i * 4 + 3] = new LatticePoint2D(i2, j2); - } - - for (int i = 0; i < 8; i++) { - int i1, j1, k1, i2, j2, k2; - i1 = (i) & 1; - j1 = (i >> 1) & 1; - k1 = (i >> 2) & 1; - i2 = i1 ^ 1; - j2 = j1 ^ 1; - k2 = k1 ^ 1; - - // The two points within this octant, one from each of the two cubic half-lattices. - LatticePoint3D c0 = new LatticePoint3D(i1, j1, k1, 0); - LatticePoint3D c1 = new LatticePoint3D(i1 + i2, j1 + j2, k1 + k2, 1); - - // (1, 0, 0) vs (0, 1, 1) away from octant. - LatticePoint3D c2 = new LatticePoint3D(i1 ^ 1, j1, k1, 0); - LatticePoint3D c3 = new LatticePoint3D(i1, j1 ^ 1, k1 ^ 1, 0); - - // (1, 0, 0) vs (0, 1, 1) away from octant, on second half-lattice. - LatticePoint3D c4 = new LatticePoint3D(i1 + (i2 ^ 1), j1 + j2, k1 + k2, 1); - LatticePoint3D c5 = new LatticePoint3D(i1 + i2, j1 + (j2 ^ 1), k1 + (k2 ^ 1), 1); - - // (0, 1, 0) vs (1, 0, 1) away from octant. - LatticePoint3D c6 = new LatticePoint3D(i1, j1 ^ 1, k1, 0); - LatticePoint3D c7 = new LatticePoint3D(i1 ^ 1, j1, k1 ^ 1, 0); - - // (0, 1, 0) vs (1, 0, 1) away from octant, on second half-lattice. - LatticePoint3D c8 = new LatticePoint3D(i1 + i2, j1 + (j2 ^ 1), k1 + k2, 1); - LatticePoint3D c9 = new LatticePoint3D(i1 + (i2 ^ 1), j1 + j2, k1 + (k2 ^ 1), 1); - - // (0, 0, 1) vs (1, 1, 0) away from octant. - LatticePoint3D cA = new LatticePoint3D(i1, j1, k1 ^ 1, 0); - LatticePoint3D cB = new LatticePoint3D(i1 ^ 1, j1 ^ 1, k1, 0); - - // (0, 0, 1) vs (1, 1, 0) away from octant, on second half-lattice. - LatticePoint3D cC = new LatticePoint3D(i1 + i2, j1 + j2, k1 + (k2 ^ 1), 1); - LatticePoint3D cD = new LatticePoint3D(i1 + (i2 ^ 1), j1 + (j2 ^ 1), k1 + k2, 1); - - // First two points are guaranteed. - c0.nextOnFailure = c0.nextOnSuccess = c1; - c1.nextOnFailure = c1.nextOnSuccess = c2; - - // If c2 is in range, then we know c3 and c4 are not. - c2.nextOnFailure = c3; - c2.nextOnSuccess = c5; - c3.nextOnFailure = c4; - c3.nextOnSuccess = c4; - - // If c4 is in range, then we know c5 is not. - c4.nextOnFailure = c5; - c4.nextOnSuccess = c6; - c5.nextOnFailure = c5.nextOnSuccess = c6; - - // If c6 is in range, then we know c7 and c8 are not. - c6.nextOnFailure = c7; - c6.nextOnSuccess = c9; - c7.nextOnFailure = c8; - c7.nextOnSuccess = c8; - - // If c8 is in range, then we know c9 is not. - c8.nextOnFailure = c9; - c8.nextOnSuccess = cA; - c9.nextOnFailure = c9.nextOnSuccess = cA; - - // If cA is in range, then we know cB and cC are not. - cA.nextOnFailure = cB; - cA.nextOnSuccess = cD; - cB.nextOnFailure = cC; - cB.nextOnSuccess = cC; - - // If cC is in range, then we know cD is not. - cC.nextOnFailure = cD; - cC.nextOnSuccess = null; - cD.nextOnFailure = cD.nextOnSuccess = null; - - LOOKUP_3D[i] = c0; - } - - int[][] lookup4DPregen = { - {0x15, 0x45, 0x51, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x15, 0x45, 0x51, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA6, 0xAA}, - {0x01, 0x05, 0x11, 0x15, 0x41, 0x45, 0x51, 0x55, 0x56, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xA6, 0xAA}, - {0x01, 0x15, 0x16, 0x45, 0x46, 0x51, 0x52, 0x55, 0x56, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x15, 0x45, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA9, 0xAA}, - {0x05, 0x15, 0x45, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xAA}, - {0x05, 0x15, 0x45, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xAA}, - {0x05, 0x15, 0x16, 0x45, 0x46, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xAA, 0xAB}, - {0x04, 0x05, 0x14, 0x15, 0x44, 0x45, 0x54, 0x55, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA}, - {0x05, 0x15, 0x45, 0x55, 0x56, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xAA}, - {0x05, 0x15, 0x45, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x9A, 0xAA}, - {0x05, 0x15, 0x16, 0x45, 0x46, 0x55, 0x56, 0x59, 0x5A, 0x5B, 0x6A, 0x9A, 0xAA, 0xAB}, - {0x04, 0x15, 0x19, 0x45, 0x49, 0x54, 0x55, 0x58, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x05, 0x15, 0x19, 0x45, 0x49, 0x55, 0x56, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xAA, 0xAE}, - {0x05, 0x15, 0x19, 0x45, 0x49, 0x55, 0x56, 0x59, 0x5A, 0x5E, 0x6A, 0x9A, 0xAA, 0xAE}, - {0x05, 0x15, 0x1A, 0x45, 0x4A, 0x55, 0x56, 0x59, 0x5A, 0x5B, 0x5E, 0x6A, 0x9A, 0xAA, 0xAB, 0xAE, 0xAF}, - {0x15, 0x51, 0x54, 0x55, 0x56, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x95, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x11, 0x15, 0x51, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0xA5, 0xA6, 0xAA}, - {0x11, 0x15, 0x51, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x6A, 0x96, 0xA6, 0xAA}, - {0x11, 0x15, 0x16, 0x51, 0x52, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x6A, 0x96, 0xA6, 0xAA, 0xAB}, - {0x14, 0x15, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x99, 0xA5, 0xA9, 0xAA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x9A, 0xA6, 0xA9, 0xAA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x15, 0x16, 0x55, 0x56, 0x5A, 0x66, 0x6A, 0x6B, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x14, 0x15, 0x54, 0x55, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x99, 0xA9, 0xAA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x9A, 0xAA}, - {0x15, 0x16, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x6A, 0x6B, 0x9A, 0xAA, 0xAB}, - {0x14, 0x15, 0x19, 0x54, 0x55, 0x58, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x99, 0xA9, 0xAA, 0xAE}, - {0x15, 0x19, 0x55, 0x59, 0x5A, 0x69, 0x6A, 0x6E, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x15, 0x19, 0x55, 0x56, 0x59, 0x5A, 0x69, 0x6A, 0x6E, 0x9A, 0xAA, 0xAE}, - {0x15, 0x1A, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x6B, 0x6E, 0x9A, 0xAA, 0xAB, 0xAE, 0xAF}, - {0x10, 0x11, 0x14, 0x15, 0x50, 0x51, 0x54, 0x55, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x11, 0x15, 0x51, 0x55, 0x56, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xAA}, - {0x11, 0x15, 0x51, 0x55, 0x56, 0x65, 0x66, 0x6A, 0xA6, 0xAA}, - {0x11, 0x15, 0x16, 0x51, 0x52, 0x55, 0x56, 0x65, 0x66, 0x67, 0x6A, 0xA6, 0xAA, 0xAB}, - {0x14, 0x15, 0x54, 0x55, 0x59, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA9, 0xAA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xA6, 0xAA}, - {0x15, 0x16, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x6A, 0x6B, 0xA6, 0xAA, 0xAB}, - {0x14, 0x15, 0x54, 0x55, 0x59, 0x65, 0x69, 0x6A, 0xA9, 0xAA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xA9, 0xAA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xAA}, - {0x15, 0x16, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x6B, 0xAA, 0xAB}, - {0x14, 0x15, 0x19, 0x54, 0x55, 0x58, 0x59, 0x65, 0x69, 0x6A, 0x6D, 0xA9, 0xAA, 0xAE}, - {0x15, 0x19, 0x55, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x6E, 0xA9, 0xAA, 0xAE}, - {0x15, 0x19, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x6E, 0xAA, 0xAE}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x69, 0x6A, 0x6B, 0x6E, 0x9A, 0xAA, 0xAB, 0xAE, 0xAF}, - {0x10, 0x15, 0x25, 0x51, 0x54, 0x55, 0x61, 0x64, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x11, 0x15, 0x25, 0x51, 0x55, 0x56, 0x61, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xAA, 0xBA}, - {0x11, 0x15, 0x25, 0x51, 0x55, 0x56, 0x61, 0x65, 0x66, 0x6A, 0x76, 0xA6, 0xAA, 0xBA}, - {0x11, 0x15, 0x26, 0x51, 0x55, 0x56, 0x62, 0x65, 0x66, 0x67, 0x6A, 0x76, 0xA6, 0xAA, 0xAB, 0xBA, 0xBB}, - {0x14, 0x15, 0x25, 0x54, 0x55, 0x59, 0x64, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA9, 0xAA, 0xBA}, - {0x15, 0x25, 0x55, 0x65, 0x66, 0x69, 0x6A, 0x7A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x15, 0x25, 0x55, 0x56, 0x65, 0x66, 0x69, 0x6A, 0x7A, 0xA6, 0xAA, 0xBA}, - {0x15, 0x26, 0x55, 0x56, 0x65, 0x66, 0x6A, 0x6B, 0x7A, 0xA6, 0xAA, 0xAB, 0xBA, 0xBB}, - {0x14, 0x15, 0x25, 0x54, 0x55, 0x59, 0x64, 0x65, 0x69, 0x6A, 0x79, 0xA9, 0xAA, 0xBA}, - {0x15, 0x25, 0x55, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x7A, 0xA9, 0xAA, 0xBA}, - {0x15, 0x25, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x7A, 0xAA, 0xBA}, - {0x15, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x6B, 0x7A, 0xA6, 0xAA, 0xAB, 0xBA, 0xBB}, - {0x14, 0x15, 0x29, 0x54, 0x55, 0x59, 0x65, 0x68, 0x69, 0x6A, 0x6D, 0x79, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, - {0x15, 0x29, 0x55, 0x59, 0x65, 0x69, 0x6A, 0x6E, 0x7A, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, - {0x15, 0x55, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x6E, 0x7A, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x6B, 0x6E, 0x7A, 0xAA, 0xAB, 0xAE, 0xBA, 0xBF}, - {0x45, 0x51, 0x54, 0x55, 0x56, 0x59, 0x65, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x41, 0x45, 0x51, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xAA}, - {0x41, 0x45, 0x51, 0x55, 0x56, 0x5A, 0x66, 0x95, 0x96, 0x9A, 0xA6, 0xAA}, - {0x41, 0x45, 0x46, 0x51, 0x52, 0x55, 0x56, 0x5A, 0x66, 0x95, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x44, 0x45, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x69, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA9, 0xAA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xA9, 0xAA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x45, 0x46, 0x55, 0x56, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0x9B, 0xA6, 0xAA, 0xAB}, - {0x44, 0x45, 0x54, 0x55, 0x59, 0x5A, 0x69, 0x95, 0x99, 0x9A, 0xA9, 0xAA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xAA}, - {0x45, 0x46, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x96, 0x9A, 0x9B, 0xAA, 0xAB}, - {0x44, 0x45, 0x49, 0x54, 0x55, 0x58, 0x59, 0x5A, 0x69, 0x95, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x45, 0x49, 0x55, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0x9E, 0xA9, 0xAA, 0xAE}, - {0x45, 0x49, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x99, 0x9A, 0x9E, 0xAA, 0xAE}, - {0x45, 0x4A, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x9A, 0x9B, 0x9E, 0xAA, 0xAB, 0xAE, 0xAF}, - {0x50, 0x51, 0x54, 0x55, 0x56, 0x59, 0x65, 0x66, 0x69, 0x95, 0x96, 0x99, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x51, 0x55, 0x56, 0x59, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x51, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xAA, 0xAB}, - {0x51, 0x52, 0x55, 0x56, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xA6, 0xA7, 0xAA, 0xAB}, - {0x54, 0x55, 0x56, 0x59, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x15, 0x45, 0x51, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x55, 0x56, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x54, 0x55, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA5, 0xA9, 0xAA, 0xAE}, - {0x15, 0x45, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x15, 0x45, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xA9, 0xAA, 0xAB, 0xAE}, - {0x55, 0x56, 0x59, 0x5A, 0x66, 0x6A, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x54, 0x55, 0x58, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAD, 0xAE}, - {0x55, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x55, 0x56, 0x59, 0x5A, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x55, 0x56, 0x59, 0x5A, 0x6A, 0x9A, 0xAA, 0xAB, 0xAE, 0xAF}, - {0x50, 0x51, 0x54, 0x55, 0x65, 0x66, 0x69, 0x95, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x6A, 0x95, 0x96, 0xA5, 0xA6, 0xAA}, - {0x51, 0x52, 0x55, 0x56, 0x65, 0x66, 0x6A, 0x96, 0xA6, 0xA7, 0xAA, 0xAB}, - {0x54, 0x55, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x99, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x15, 0x51, 0x54, 0x55, 0x56, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x15, 0x51, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAB, 0xBA}, - {0x55, 0x56, 0x5A, 0x65, 0x66, 0x6A, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x6A, 0x95, 0x99, 0xA5, 0xA9, 0xAA}, - {0x15, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAE, 0xBA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x9A, 0xA6, 0xA9, 0xAA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x54, 0x55, 0x58, 0x59, 0x65, 0x69, 0x6A, 0x99, 0xA9, 0xAA, 0xAD, 0xAE}, - {0x55, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x69, 0x6A, 0x9A, 0xAA, 0xAB, 0xAE, 0xAF}, - {0x50, 0x51, 0x54, 0x55, 0x61, 0x64, 0x65, 0x66, 0x69, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x51, 0x55, 0x61, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xB6, 0xBA}, - {0x51, 0x55, 0x56, 0x61, 0x65, 0x66, 0x6A, 0xA5, 0xA6, 0xAA, 0xB6, 0xBA}, - {0x51, 0x55, 0x56, 0x62, 0x65, 0x66, 0x6A, 0xA6, 0xA7, 0xAA, 0xAB, 0xB6, 0xBA, 0xBB}, - {0x54, 0x55, 0x64, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xB9, 0xBA}, - {0x55, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x55, 0x56, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x55, 0x56, 0x65, 0x66, 0x6A, 0xA6, 0xAA, 0xAB, 0xBA, 0xBB}, - {0x54, 0x55, 0x59, 0x64, 0x65, 0x69, 0x6A, 0xA5, 0xA9, 0xAA, 0xB9, 0xBA}, - {0x55, 0x59, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x15, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x15, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xA6, 0xAA, 0xAB, 0xBA, 0xBB}, - {0x54, 0x55, 0x59, 0x65, 0x68, 0x69, 0x6A, 0xA9, 0xAA, 0xAD, 0xAE, 0xB9, 0xBA, 0xBE}, - {0x55, 0x59, 0x65, 0x69, 0x6A, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, - {0x15, 0x55, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, - {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0xAA, 0xAB, 0xAE, 0xBA, 0xBF}, - {0x40, 0x41, 0x44, 0x45, 0x50, 0x51, 0x54, 0x55, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x41, 0x45, 0x51, 0x55, 0x56, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xAA}, - {0x41, 0x45, 0x51, 0x55, 0x56, 0x95, 0x96, 0x9A, 0xA6, 0xAA}, - {0x41, 0x45, 0x46, 0x51, 0x52, 0x55, 0x56, 0x95, 0x96, 0x97, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x44, 0x45, 0x54, 0x55, 0x59, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA9, 0xAA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xAA}, - {0x45, 0x46, 0x55, 0x56, 0x5A, 0x95, 0x96, 0x9A, 0x9B, 0xA6, 0xAA, 0xAB}, - {0x44, 0x45, 0x54, 0x55, 0x59, 0x95, 0x99, 0x9A, 0xA9, 0xAA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xA9, 0xAA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xAA}, - {0x45, 0x46, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0x9B, 0xAA, 0xAB}, - {0x44, 0x45, 0x49, 0x54, 0x55, 0x58, 0x59, 0x95, 0x99, 0x9A, 0x9D, 0xA9, 0xAA, 0xAE}, - {0x45, 0x49, 0x55, 0x59, 0x5A, 0x95, 0x99, 0x9A, 0x9E, 0xA9, 0xAA, 0xAE}, - {0x45, 0x49, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0x9E, 0xAA, 0xAE}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x96, 0x99, 0x9A, 0x9B, 0x9E, 0xAA, 0xAB, 0xAE, 0xAF}, - {0x50, 0x51, 0x54, 0x55, 0x65, 0x95, 0x96, 0x99, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xAA}, - {0x51, 0x52, 0x55, 0x56, 0x66, 0x95, 0x96, 0x9A, 0xA6, 0xA7, 0xAA, 0xAB}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x45, 0x51, 0x54, 0x55, 0x56, 0x59, 0x65, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x45, 0x51, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAB, 0xEA}, - {0x55, 0x56, 0x5A, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x95, 0x99, 0x9A, 0xA5, 0xA9, 0xAA}, - {0x45, 0x54, 0x55, 0x56, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAE, 0xEA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xA9, 0xAA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x66, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xAA, 0xAB}, - {0x54, 0x55, 0x58, 0x59, 0x69, 0x95, 0x99, 0x9A, 0xA9, 0xAA, 0xAD, 0xAE}, - {0x55, 0x59, 0x5A, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA9, 0xAA, 0xAE}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x6A, 0x96, 0x99, 0x9A, 0xAA, 0xAB, 0xAE, 0xAF}, - {0x50, 0x51, 0x54, 0x55, 0x65, 0x95, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xAA}, - {0x51, 0x52, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xA7, 0xAA, 0xAB}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x51, 0x54, 0x55, 0x56, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA, 0xEA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x51, 0x55, 0x56, 0x5A, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xAA, 0xAB}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA9, 0xAA}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA}, - {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA6, 0xA9, 0xAA, 0xAB}, - {0x54, 0x55, 0x58, 0x59, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA9, 0xAA, 0xAD, 0xAE}, - {0x54, 0x55, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA5, 0xA9, 0xAA, 0xAE}, - {0x55, 0x56, 0x59, 0x5A, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA6, 0xA9, 0xAA, 0xAE}, - {0x55, 0x56, 0x59, 0x5A, 0x66, 0x69, 0x6A, 0x96, 0x99, 0x9A, 0xA6, 0xA9, 0xAA, 0xAB, 0xAE, 0xAF}, - {0x50, 0x51, 0x54, 0x55, 0x61, 0x64, 0x65, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xB5, 0xBA}, - {0x51, 0x55, 0x61, 0x65, 0x66, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xB6, 0xBA}, - {0x51, 0x55, 0x56, 0x61, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xAA, 0xB6, 0xBA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x6A, 0x96, 0xA5, 0xA6, 0xA7, 0xAA, 0xAB, 0xB6, 0xBA, 0xBB}, - {0x54, 0x55, 0x64, 0x65, 0x69, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xB9, 0xBA}, - {0x55, 0x65, 0x66, 0x69, 0x6A, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x6A, 0x96, 0xA5, 0xA6, 0xAA, 0xAB, 0xBA, 0xBB}, - {0x54, 0x55, 0x59, 0x64, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA9, 0xAA, 0xB9, 0xBA}, - {0x54, 0x55, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x99, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x55, 0x56, 0x59, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA}, - {0x55, 0x56, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x96, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAB, 0xBA, 0xBB}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x6A, 0x99, 0xA5, 0xA9, 0xAA, 0xAD, 0xAE, 0xB9, 0xBA, 0xBE}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x6A, 0x99, 0xA5, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, - {0x55, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAE, 0xBA, 0xBE}, - {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x9A, 0xA6, 0xA9, 0xAA, 0xAB, 0xAE, 0xBA}, - {0x40, 0x45, 0x51, 0x54, 0x55, 0x85, 0x91, 0x94, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x41, 0x45, 0x51, 0x55, 0x56, 0x85, 0x91, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xAA, 0xEA}, - {0x41, 0x45, 0x51, 0x55, 0x56, 0x85, 0x91, 0x95, 0x96, 0x9A, 0xA6, 0xAA, 0xD6, 0xEA}, - {0x41, 0x45, 0x51, 0x55, 0x56, 0x86, 0x92, 0x95, 0x96, 0x97, 0x9A, 0xA6, 0xAA, 0xAB, 0xD6, 0xEA, 0xEB}, - {0x44, 0x45, 0x54, 0x55, 0x59, 0x85, 0x94, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA9, 0xAA, 0xEA}, - {0x45, 0x55, 0x85, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xDA, 0xEA}, - {0x45, 0x55, 0x56, 0x85, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xAA, 0xDA, 0xEA}, - {0x45, 0x55, 0x56, 0x86, 0x95, 0x96, 0x9A, 0x9B, 0xA6, 0xAA, 0xAB, 0xDA, 0xEA, 0xEB}, - {0x44, 0x45, 0x54, 0x55, 0x59, 0x85, 0x94, 0x95, 0x99, 0x9A, 0xA9, 0xAA, 0xD9, 0xEA}, - {0x45, 0x55, 0x59, 0x85, 0x95, 0x96, 0x99, 0x9A, 0xA9, 0xAA, 0xDA, 0xEA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x85, 0x95, 0x96, 0x99, 0x9A, 0xAA, 0xDA, 0xEA}, - {0x45, 0x55, 0x56, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0x9B, 0xA6, 0xAA, 0xAB, 0xDA, 0xEA, 0xEB}, - {0x44, 0x45, 0x54, 0x55, 0x59, 0x89, 0x95, 0x98, 0x99, 0x9A, 0x9D, 0xA9, 0xAA, 0xAE, 0xD9, 0xEA, 0xEE}, - {0x45, 0x55, 0x59, 0x89, 0x95, 0x99, 0x9A, 0x9E, 0xA9, 0xAA, 0xAE, 0xDA, 0xEA, 0xEE}, - {0x45, 0x55, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0x9E, 0xA9, 0xAA, 0xAE, 0xDA, 0xEA, 0xEE}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0x9B, 0x9E, 0xAA, 0xAB, 0xAE, 0xDA, 0xEA, 0xEF}, - {0x50, 0x51, 0x54, 0x55, 0x65, 0x91, 0x94, 0x95, 0x96, 0x99, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x51, 0x55, 0x91, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xE6, 0xEA}, - {0x51, 0x55, 0x56, 0x91, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xAA, 0xE6, 0xEA}, - {0x51, 0x55, 0x56, 0x92, 0x95, 0x96, 0x9A, 0xA6, 0xA7, 0xAA, 0xAB, 0xE6, 0xEA, 0xEB}, - {0x54, 0x55, 0x94, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xE9, 0xEA}, - {0x55, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x55, 0x56, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x55, 0x56, 0x95, 0x96, 0x9A, 0xA6, 0xAA, 0xAB, 0xEA, 0xEB}, - {0x54, 0x55, 0x59, 0x94, 0x95, 0x99, 0x9A, 0xA5, 0xA9, 0xAA, 0xE9, 0xEA}, - {0x55, 0x59, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x45, 0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x45, 0x55, 0x56, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xAA, 0xAB, 0xEA, 0xEB}, - {0x54, 0x55, 0x59, 0x95, 0x98, 0x99, 0x9A, 0xA9, 0xAA, 0xAD, 0xAE, 0xE9, 0xEA, 0xEE}, - {0x55, 0x59, 0x95, 0x99, 0x9A, 0xA9, 0xAA, 0xAE, 0xEA, 0xEE}, - {0x45, 0x55, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xA9, 0xAA, 0xAE, 0xEA, 0xEE}, - {0x55, 0x56, 0x59, 0x5A, 0x95, 0x96, 0x99, 0x9A, 0xAA, 0xAB, 0xAE, 0xEA, 0xEF}, - {0x50, 0x51, 0x54, 0x55, 0x65, 0x91, 0x94, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xE5, 0xEA}, - {0x51, 0x55, 0x65, 0x91, 0x95, 0x96, 0xA5, 0xA6, 0xA9, 0xAA, 0xE6, 0xEA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x91, 0x95, 0x96, 0xA5, 0xA6, 0xAA, 0xE6, 0xEA}, - {0x51, 0x55, 0x56, 0x66, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xA7, 0xAA, 0xAB, 0xE6, 0xEA, 0xEB}, - {0x54, 0x55, 0x65, 0x94, 0x95, 0x99, 0xA5, 0xA6, 0xA9, 0xAA, 0xE9, 0xEA}, - {0x55, 0x65, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x51, 0x55, 0x56, 0x66, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xAA, 0xAB, 0xEA, 0xEB}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x94, 0x95, 0x99, 0xA5, 0xA9, 0xAA, 0xE9, 0xEA}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x55, 0x56, 0x59, 0x65, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xEA}, - {0x55, 0x56, 0x5A, 0x66, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAB, 0xEA, 0xEB}, - {0x54, 0x55, 0x59, 0x69, 0x95, 0x99, 0x9A, 0xA5, 0xA9, 0xAA, 0xAD, 0xAE, 0xE9, 0xEA, 0xEE}, - {0x54, 0x55, 0x59, 0x69, 0x95, 0x99, 0x9A, 0xA5, 0xA9, 0xAA, 0xAE, 0xEA, 0xEE}, - {0x55, 0x59, 0x5A, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAE, 0xEA, 0xEE}, - {0x55, 0x56, 0x59, 0x5A, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA6, 0xA9, 0xAA, 0xAB, 0xAE, 0xEA}, - {0x50, 0x51, 0x54, 0x55, 0x65, 0x95, 0xA1, 0xA4, 0xA5, 0xA6, 0xA9, 0xAA, 0xB5, 0xBA, 0xE5, 0xEA, 0xFA}, - {0x51, 0x55, 0x65, 0x95, 0xA1, 0xA5, 0xA6, 0xA9, 0xAA, 0xB6, 0xBA, 0xE6, 0xEA, 0xFA}, - {0x51, 0x55, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xA9, 0xAA, 0xB6, 0xBA, 0xE6, 0xEA, 0xFA}, - {0x51, 0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xA7, 0xAA, 0xAB, 0xB6, 0xBA, 0xE6, 0xEA, 0xFB}, - {0x54, 0x55, 0x65, 0x95, 0xA4, 0xA5, 0xA6, 0xA9, 0xAA, 0xB9, 0xBA, 0xE9, 0xEA, 0xFA}, - {0x55, 0x65, 0x95, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA, 0xEA, 0xFA}, - {0x51, 0x55, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA, 0xEA, 0xFA}, - {0x55, 0x56, 0x65, 0x66, 0x95, 0x96, 0xA5, 0xA6, 0xAA, 0xAB, 0xBA, 0xEA, 0xFB}, - {0x54, 0x55, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA6, 0xA9, 0xAA, 0xB9, 0xBA, 0xE9, 0xEA, 0xFA}, - {0x54, 0x55, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA, 0xEA, 0xFA}, - {0x55, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xBA, 0xEA, 0xFA}, - {0x55, 0x56, 0x65, 0x66, 0x6A, 0x95, 0x96, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAB, 0xBA, 0xEA}, - {0x54, 0x55, 0x59, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA9, 0xAA, 0xAD, 0xAE, 0xB9, 0xBA, 0xE9, 0xEA, 0xFE}, - {0x55, 0x59, 0x65, 0x69, 0x95, 0x99, 0xA5, 0xA9, 0xAA, 0xAE, 0xBA, 0xEA, 0xFE}, - {0x55, 0x59, 0x65, 0x69, 0x6A, 0x95, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAE, 0xBA, 0xEA}, - {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA, 0xAB, 0xAE, 0xBA, 0xEA},}; - LatticePoint4D[] latticePoints = new LatticePoint4D[256]; - for (int i = 0; i < 256; i++) { - int cx = ((i) & 3) - 1; - int cy = ((i >> 2) & 3) - 1; - int cz = ((i >> 4) & 3) - 1; - int cw = ((i >> 6) & 3) - 1; - latticePoints[i] = new LatticePoint4D(cx, cy, cz, cw); - } - for (int i = 0; i < 256; i++) { - LOOKUP_4D[i] = new LatticePoint4D[lookup4DPregen[i].length]; - for (int j = 0; j < lookup4DPregen[i].length; j++) { - LOOKUP_4D[i][j] = latticePoints[lookup4DPregen[i][j]]; - } - } - } - - @Override - public float noise(float x, float y){ - return (float)noise2_XBeforeY(x, y); - } - - @Override - public float noise(float x, float y, float z) { - return (float)noise3_XYBeforeZ(x, y, z); - } - - @Override - public float noise(float x, float y, float z, float w) { - return (float)noise4_XZBeforeYW(x, y, z, w); - } - - @Override - public void noiseMode(NoiseMode mode) { - - } - - @Override - public void noiseSeed(long seed) { - - } - - private static class LatticePoint2D { - - int xsv, ysv; - double dx, dy; - - public LatticePoint2D(int xsv, int ysv) { - this.xsv = xsv; - this.ysv = ysv; - double ssv = (xsv + ysv) * -0.211324865405187; - this.dx = -xsv - ssv; - this.dy = -ysv - ssv; - } - } - - private static class LatticePoint3D { - - public double dxr, dyr, dzr; - public int xrv, yrv, zrv; - LatticePoint3D nextOnFailure, nextOnSuccess; - - public LatticePoint3D(int xrv, int yrv, int zrv, int lattice) { - this.dxr = -xrv + lattice * 0.5; - this.dyr = -yrv + lattice * 0.5; - this.dzr = -zrv + lattice * 0.5; - this.xrv = xrv + lattice * 1024; - this.yrv = yrv + lattice * 1024; - this.zrv = zrv + lattice * 1024; - } - } - - private static class LatticePoint4D { - - int xsv, ysv, zsv, wsv; - double dx, dy, dz, dw; - - public LatticePoint4D(int xsv, int ysv, int zsv, int wsv) { - this.xsv = xsv; - this.ysv = ysv; - this.zsv = zsv; - this.wsv = wsv; - double ssv = (xsv + ysv + zsv + wsv) * -0.138196601125011; - this.dx = -xsv - ssv; - this.dy = -ysv - ssv; - this.dz = -zsv - ssv; - this.dw = -wsv - ssv; - } - } - - /* - * Gradients - */ - private static class Grad2 { - - double dx, dy; - - public Grad2(double dx, double dy) { - this.dx = dx; - this.dy = dy; - } - } - - private static class Grad3 { - - double dx, dy, dz; - - public Grad3(double dx, double dy, double dz) { - this.dx = dx; - this.dy = dy; - this.dz = dz; - } - } - - private static class Grad4 { - - double dx, dy, dz, dw; - - public Grad4(double dx, double dy, double dz, double dw) { - this.dx = dx; - this.dy = dy; - this.dz = dz; - this.dw = dw; - } - } - - private static final double N2 = 0.05481866495625118; - private static final double N3 = 0.2781926117527186; - private static final double N4 = 0.11127401889945551; - private static final Grad2[] GRADIENTS_2D; - private static final Grad3[] GRADIENTS_3D; - private static final Grad4[] GRADIENTS_4D; - - static { - - GRADIENTS_2D = new Grad2[PSIZE]; - Grad2[] grad2 = { - new Grad2(0.130526192220052, 0.99144486137381), - new Grad2(0.38268343236509, 0.923879532511287), - new Grad2(0.608761429008721, 0.793353340291235), - new Grad2(0.793353340291235, 0.608761429008721), - new Grad2(0.923879532511287, 0.38268343236509), - new Grad2(0.99144486137381, 0.130526192220051), - new Grad2(0.99144486137381, -0.130526192220051), - new Grad2(0.923879532511287, -0.38268343236509), - new Grad2(0.793353340291235, -0.60876142900872), - new Grad2(0.608761429008721, -0.793353340291235), - new Grad2(0.38268343236509, -0.923879532511287), - new Grad2(0.130526192220052, -0.99144486137381), - new Grad2(-0.130526192220052, -0.99144486137381), - new Grad2(-0.38268343236509, -0.923879532511287), - new Grad2(-0.608761429008721, -0.793353340291235), - new Grad2(-0.793353340291235, -0.608761429008721), - new Grad2(-0.923879532511287, -0.38268343236509), - new Grad2(-0.99144486137381, -0.130526192220052), - new Grad2(-0.99144486137381, 0.130526192220051), - new Grad2(-0.923879532511287, 0.38268343236509), - new Grad2(-0.793353340291235, 0.608761429008721), - new Grad2(-0.608761429008721, 0.793353340291235), - new Grad2(-0.38268343236509, 0.923879532511287), - new Grad2(-0.130526192220052, 0.99144486137381) - }; - Grad2[] grad2XBeforeY = new Grad2[grad2.length]; - for (Grad2 grad21 : grad2) { - grad21.dx /= N2; - grad21.dy /= N2; - } - for (int i = 0; i < PSIZE; i++) { - GRADIENTS_2D[i] = grad2[i % grad2.length]; - } - - GRADIENTS_3D = new Grad3[PSIZE]; - Grad3[] grad3 = { - new Grad3(-2.22474487139, -2.22474487139, -1.0), - new Grad3(-2.22474487139, -2.22474487139, 1.0), - new Grad3(-3.0862664687972017, -1.1721513422464978, 0.0), - new Grad3(-1.1721513422464978, -3.0862664687972017, 0.0), - new Grad3(-2.22474487139, -1.0, -2.22474487139), - new Grad3(-2.22474487139, 1.0, -2.22474487139), - new Grad3(-1.1721513422464978, 0.0, -3.0862664687972017), - new Grad3(-3.0862664687972017, 0.0, -1.1721513422464978), - new Grad3(-2.22474487139, -1.0, 2.22474487139), - new Grad3(-2.22474487139, 1.0, 2.22474487139), - new Grad3(-3.0862664687972017, 0.0, 1.1721513422464978), - new Grad3(-1.1721513422464978, 0.0, 3.0862664687972017), - new Grad3(-2.22474487139, 2.22474487139, -1.0), - new Grad3(-2.22474487139, 2.22474487139, 1.0), - new Grad3(-1.1721513422464978, 3.0862664687972017, 0.0), - new Grad3(-3.0862664687972017, 1.1721513422464978, 0.0), - new Grad3(-1.0, -2.22474487139, -2.22474487139), - new Grad3(1.0, -2.22474487139, -2.22474487139), - new Grad3(0.0, -3.0862664687972017, -1.1721513422464978), - new Grad3(0.0, -1.1721513422464978, -3.0862664687972017), - new Grad3(-1.0, -2.22474487139, 2.22474487139), - new Grad3(1.0, -2.22474487139, 2.22474487139), - new Grad3(0.0, -1.1721513422464978, 3.0862664687972017), - new Grad3(0.0, -3.0862664687972017, 1.1721513422464978), - new Grad3(-1.0, 2.22474487139, -2.22474487139), - new Grad3(1.0, 2.22474487139, -2.22474487139), - new Grad3(0.0, 1.1721513422464978, -3.0862664687972017), - new Grad3(0.0, 3.0862664687972017, -1.1721513422464978), - new Grad3(-1.0, 2.22474487139, 2.22474487139), - new Grad3(1.0, 2.22474487139, 2.22474487139), - new Grad3(0.0, 3.0862664687972017, 1.1721513422464978), - new Grad3(0.0, 1.1721513422464978, 3.0862664687972017), - new Grad3(2.22474487139, -2.22474487139, -1.0), - new Grad3(2.22474487139, -2.22474487139, 1.0), - new Grad3(1.1721513422464978, -3.0862664687972017, 0.0), - new Grad3(3.0862664687972017, -1.1721513422464978, 0.0), - new Grad3(2.22474487139, -1.0, -2.22474487139), - new Grad3(2.22474487139, 1.0, -2.22474487139), - new Grad3(3.0862664687972017, 0.0, -1.1721513422464978), - new Grad3(1.1721513422464978, 0.0, -3.0862664687972017), - new Grad3(2.22474487139, -1.0, 2.22474487139), - new Grad3(2.22474487139, 1.0, 2.22474487139), - new Grad3(1.1721513422464978, 0.0, 3.0862664687972017), - new Grad3(3.0862664687972017, 0.0, 1.1721513422464978), - new Grad3(2.22474487139, 2.22474487139, -1.0), - new Grad3(2.22474487139, 2.22474487139, 1.0), - new Grad3(3.0862664687972017, 1.1721513422464978, 0.0), - new Grad3(1.1721513422464978, 3.0862664687972017, 0.0) - }; - for (Grad3 grad31 : grad3) { - grad31.dx /= N3; - grad31.dy /= N3; - grad31.dz /= N3; - } - for (int i = 0; i < PSIZE; i++) { - GRADIENTS_3D[i] = grad3[i % grad3.length]; - } - - GRADIENTS_4D = new Grad4[PSIZE]; - Grad4[] grad4 = { - new Grad4(-0.753341017856078, -0.37968289875261624, -0.37968289875261624, -0.37968289875261624), - new Grad4(-0.7821684431180708, -0.4321472685365301, -0.4321472685365301, 0.12128480194602098), - new Grad4(-0.7821684431180708, -0.4321472685365301, 0.12128480194602098, -0.4321472685365301), - new Grad4(-0.7821684431180708, 0.12128480194602098, -0.4321472685365301, -0.4321472685365301), - new Grad4(-0.8586508742123365, -0.508629699630796, 0.044802370851755174, 0.044802370851755174), - new Grad4(-0.8586508742123365, 0.044802370851755174, -0.508629699630796, 0.044802370851755174), - new Grad4(-0.8586508742123365, 0.044802370851755174, 0.044802370851755174, -0.508629699630796), - new Grad4(-0.9982828964265062, -0.03381941603233842, -0.03381941603233842, -0.03381941603233842), - new Grad4(-0.37968289875261624, -0.753341017856078, -0.37968289875261624, -0.37968289875261624), - new Grad4(-0.4321472685365301, -0.7821684431180708, -0.4321472685365301, 0.12128480194602098), - new Grad4(-0.4321472685365301, -0.7821684431180708, 0.12128480194602098, -0.4321472685365301), - new Grad4(0.12128480194602098, -0.7821684431180708, -0.4321472685365301, -0.4321472685365301), - new Grad4(-0.508629699630796, -0.8586508742123365, 0.044802370851755174, 0.044802370851755174), - new Grad4(0.044802370851755174, -0.8586508742123365, -0.508629699630796, 0.044802370851755174), - new Grad4(0.044802370851755174, -0.8586508742123365, 0.044802370851755174, -0.508629699630796), - new Grad4(-0.03381941603233842, -0.9982828964265062, -0.03381941603233842, -0.03381941603233842), - new Grad4(-0.37968289875261624, -0.37968289875261624, -0.753341017856078, -0.37968289875261624), - new Grad4(-0.4321472685365301, -0.4321472685365301, -0.7821684431180708, 0.12128480194602098), - new Grad4(-0.4321472685365301, 0.12128480194602098, -0.7821684431180708, -0.4321472685365301), - new Grad4(0.12128480194602098, -0.4321472685365301, -0.7821684431180708, -0.4321472685365301), - new Grad4(-0.508629699630796, 0.044802370851755174, -0.8586508742123365, 0.044802370851755174), - new Grad4(0.044802370851755174, -0.508629699630796, -0.8586508742123365, 0.044802370851755174), - new Grad4(0.044802370851755174, 0.044802370851755174, -0.8586508742123365, -0.508629699630796), - new Grad4(-0.03381941603233842, -0.03381941603233842, -0.9982828964265062, -0.03381941603233842), - new Grad4(-0.37968289875261624, -0.37968289875261624, -0.37968289875261624, -0.753341017856078), - new Grad4(-0.4321472685365301, -0.4321472685365301, 0.12128480194602098, -0.7821684431180708), - new Grad4(-0.4321472685365301, 0.12128480194602098, -0.4321472685365301, -0.7821684431180708), - new Grad4(0.12128480194602098, -0.4321472685365301, -0.4321472685365301, -0.7821684431180708), - new Grad4(-0.508629699630796, 0.044802370851755174, 0.044802370851755174, -0.8586508742123365), - new Grad4(0.044802370851755174, -0.508629699630796, 0.044802370851755174, -0.8586508742123365), - new Grad4(0.044802370851755174, 0.044802370851755174, -0.508629699630796, -0.8586508742123365), - new Grad4(-0.03381941603233842, -0.03381941603233842, -0.03381941603233842, -0.9982828964265062), - new Grad4(-0.6740059517812944, -0.3239847771997537, -0.3239847771997537, 0.5794684678643381), - new Grad4(-0.7504883828755602, -0.4004672082940195, 0.15296486218853164, 0.5029860367700724), - new Grad4(-0.7504883828755602, 0.15296486218853164, -0.4004672082940195, 0.5029860367700724), - new Grad4(-0.8828161875373585, 0.08164729285680945, 0.08164729285680945, 0.4553054119602712), - new Grad4(-0.4553054119602712, -0.08164729285680945, -0.08164729285680945, 0.8828161875373585), - new Grad4(-0.5029860367700724, -0.15296486218853164, 0.4004672082940195, 0.7504883828755602), - new Grad4(-0.5029860367700724, 0.4004672082940195, -0.15296486218853164, 0.7504883828755602), - new Grad4(-0.5794684678643381, 0.3239847771997537, 0.3239847771997537, 0.6740059517812944), - new Grad4(-0.3239847771997537, -0.6740059517812944, -0.3239847771997537, 0.5794684678643381), - new Grad4(-0.4004672082940195, -0.7504883828755602, 0.15296486218853164, 0.5029860367700724), - new Grad4(0.15296486218853164, -0.7504883828755602, -0.4004672082940195, 0.5029860367700724), - new Grad4(0.08164729285680945, -0.8828161875373585, 0.08164729285680945, 0.4553054119602712), - new Grad4(-0.08164729285680945, -0.4553054119602712, -0.08164729285680945, 0.8828161875373585), - new Grad4(-0.15296486218853164, -0.5029860367700724, 0.4004672082940195, 0.7504883828755602), - new Grad4(0.4004672082940195, -0.5029860367700724, -0.15296486218853164, 0.7504883828755602), - new Grad4(0.3239847771997537, -0.5794684678643381, 0.3239847771997537, 0.6740059517812944), - new Grad4(-0.3239847771997537, -0.3239847771997537, -0.6740059517812944, 0.5794684678643381), - new Grad4(-0.4004672082940195, 0.15296486218853164, -0.7504883828755602, 0.5029860367700724), - new Grad4(0.15296486218853164, -0.4004672082940195, -0.7504883828755602, 0.5029860367700724), - new Grad4(0.08164729285680945, 0.08164729285680945, -0.8828161875373585, 0.4553054119602712), - new Grad4(-0.08164729285680945, -0.08164729285680945, -0.4553054119602712, 0.8828161875373585), - new Grad4(-0.15296486218853164, 0.4004672082940195, -0.5029860367700724, 0.7504883828755602), - new Grad4(0.4004672082940195, -0.15296486218853164, -0.5029860367700724, 0.7504883828755602), - new Grad4(0.3239847771997537, 0.3239847771997537, -0.5794684678643381, 0.6740059517812944), - new Grad4(-0.6740059517812944, -0.3239847771997537, 0.5794684678643381, -0.3239847771997537), - new Grad4(-0.7504883828755602, -0.4004672082940195, 0.5029860367700724, 0.15296486218853164), - new Grad4(-0.7504883828755602, 0.15296486218853164, 0.5029860367700724, -0.4004672082940195), - new Grad4(-0.8828161875373585, 0.08164729285680945, 0.4553054119602712, 0.08164729285680945), - new Grad4(-0.4553054119602712, -0.08164729285680945, 0.8828161875373585, -0.08164729285680945), - new Grad4(-0.5029860367700724, -0.15296486218853164, 0.7504883828755602, 0.4004672082940195), - new Grad4(-0.5029860367700724, 0.4004672082940195, 0.7504883828755602, -0.15296486218853164), - new Grad4(-0.5794684678643381, 0.3239847771997537, 0.6740059517812944, 0.3239847771997537), - new Grad4(-0.3239847771997537, -0.6740059517812944, 0.5794684678643381, -0.3239847771997537), - new Grad4(-0.4004672082940195, -0.7504883828755602, 0.5029860367700724, 0.15296486218853164), - new Grad4(0.15296486218853164, -0.7504883828755602, 0.5029860367700724, -0.4004672082940195), - new Grad4(0.08164729285680945, -0.8828161875373585, 0.4553054119602712, 0.08164729285680945), - new Grad4(-0.08164729285680945, -0.4553054119602712, 0.8828161875373585, -0.08164729285680945), - new Grad4(-0.15296486218853164, -0.5029860367700724, 0.7504883828755602, 0.4004672082940195), - new Grad4(0.4004672082940195, -0.5029860367700724, 0.7504883828755602, -0.15296486218853164), - new Grad4(0.3239847771997537, -0.5794684678643381, 0.6740059517812944, 0.3239847771997537), - new Grad4(-0.3239847771997537, -0.3239847771997537, 0.5794684678643381, -0.6740059517812944), - new Grad4(-0.4004672082940195, 0.15296486218853164, 0.5029860367700724, -0.7504883828755602), - new Grad4(0.15296486218853164, -0.4004672082940195, 0.5029860367700724, -0.7504883828755602), - new Grad4(0.08164729285680945, 0.08164729285680945, 0.4553054119602712, -0.8828161875373585), - new Grad4(-0.08164729285680945, -0.08164729285680945, 0.8828161875373585, -0.4553054119602712), - new Grad4(-0.15296486218853164, 0.4004672082940195, 0.7504883828755602, -0.5029860367700724), - new Grad4(0.4004672082940195, -0.15296486218853164, 0.7504883828755602, -0.5029860367700724), - new Grad4(0.3239847771997537, 0.3239847771997537, 0.6740059517812944, -0.5794684678643381), - new Grad4(-0.6740059517812944, 0.5794684678643381, -0.3239847771997537, -0.3239847771997537), - new Grad4(-0.7504883828755602, 0.5029860367700724, -0.4004672082940195, 0.15296486218853164), - new Grad4(-0.7504883828755602, 0.5029860367700724, 0.15296486218853164, -0.4004672082940195), - new Grad4(-0.8828161875373585, 0.4553054119602712, 0.08164729285680945, 0.08164729285680945), - new Grad4(-0.4553054119602712, 0.8828161875373585, -0.08164729285680945, -0.08164729285680945), - new Grad4(-0.5029860367700724, 0.7504883828755602, -0.15296486218853164, 0.4004672082940195), - new Grad4(-0.5029860367700724, 0.7504883828755602, 0.4004672082940195, -0.15296486218853164), - new Grad4(-0.5794684678643381, 0.6740059517812944, 0.3239847771997537, 0.3239847771997537), - new Grad4(-0.3239847771997537, 0.5794684678643381, -0.6740059517812944, -0.3239847771997537), - new Grad4(-0.4004672082940195, 0.5029860367700724, -0.7504883828755602, 0.15296486218853164), - new Grad4(0.15296486218853164, 0.5029860367700724, -0.7504883828755602, -0.4004672082940195), - new Grad4(0.08164729285680945, 0.4553054119602712, -0.8828161875373585, 0.08164729285680945), - new Grad4(-0.08164729285680945, 0.8828161875373585, -0.4553054119602712, -0.08164729285680945), - new Grad4(-0.15296486218853164, 0.7504883828755602, -0.5029860367700724, 0.4004672082940195), - new Grad4(0.4004672082940195, 0.7504883828755602, -0.5029860367700724, -0.15296486218853164), - new Grad4(0.3239847771997537, 0.6740059517812944, -0.5794684678643381, 0.3239847771997537), - new Grad4(-0.3239847771997537, 0.5794684678643381, -0.3239847771997537, -0.6740059517812944), - new Grad4(-0.4004672082940195, 0.5029860367700724, 0.15296486218853164, -0.7504883828755602), - new Grad4(0.15296486218853164, 0.5029860367700724, -0.4004672082940195, -0.7504883828755602), - new Grad4(0.08164729285680945, 0.4553054119602712, 0.08164729285680945, -0.8828161875373585), - new Grad4(-0.08164729285680945, 0.8828161875373585, -0.08164729285680945, -0.4553054119602712), - new Grad4(-0.15296486218853164, 0.7504883828755602, 0.4004672082940195, -0.5029860367700724), - new Grad4(0.4004672082940195, 0.7504883828755602, -0.15296486218853164, -0.5029860367700724), - new Grad4(0.3239847771997537, 0.6740059517812944, 0.3239847771997537, -0.5794684678643381), - new Grad4(0.5794684678643381, -0.6740059517812944, -0.3239847771997537, -0.3239847771997537), - new Grad4(0.5029860367700724, -0.7504883828755602, -0.4004672082940195, 0.15296486218853164), - new Grad4(0.5029860367700724, -0.7504883828755602, 0.15296486218853164, -0.4004672082940195), - new Grad4(0.4553054119602712, -0.8828161875373585, 0.08164729285680945, 0.08164729285680945), - new Grad4(0.8828161875373585, -0.4553054119602712, -0.08164729285680945, -0.08164729285680945), - new Grad4(0.7504883828755602, -0.5029860367700724, -0.15296486218853164, 0.4004672082940195), - new Grad4(0.7504883828755602, -0.5029860367700724, 0.4004672082940195, -0.15296486218853164), - new Grad4(0.6740059517812944, -0.5794684678643381, 0.3239847771997537, 0.3239847771997537), - new Grad4(0.5794684678643381, -0.3239847771997537, -0.6740059517812944, -0.3239847771997537), - new Grad4(0.5029860367700724, -0.4004672082940195, -0.7504883828755602, 0.15296486218853164), - new Grad4(0.5029860367700724, 0.15296486218853164, -0.7504883828755602, -0.4004672082940195), - new Grad4(0.4553054119602712, 0.08164729285680945, -0.8828161875373585, 0.08164729285680945), - new Grad4(0.8828161875373585, -0.08164729285680945, -0.4553054119602712, -0.08164729285680945), - new Grad4(0.7504883828755602, -0.15296486218853164, -0.5029860367700724, 0.4004672082940195), - new Grad4(0.7504883828755602, 0.4004672082940195, -0.5029860367700724, -0.15296486218853164), - new Grad4(0.6740059517812944, 0.3239847771997537, -0.5794684678643381, 0.3239847771997537), - new Grad4(0.5794684678643381, -0.3239847771997537, -0.3239847771997537, -0.6740059517812944), - new Grad4(0.5029860367700724, -0.4004672082940195, 0.15296486218853164, -0.7504883828755602), - new Grad4(0.5029860367700724, 0.15296486218853164, -0.4004672082940195, -0.7504883828755602), - new Grad4(0.4553054119602712, 0.08164729285680945, 0.08164729285680945, -0.8828161875373585), - new Grad4(0.8828161875373585, -0.08164729285680945, -0.08164729285680945, -0.4553054119602712), - new Grad4(0.7504883828755602, -0.15296486218853164, 0.4004672082940195, -0.5029860367700724), - new Grad4(0.7504883828755602, 0.4004672082940195, -0.15296486218853164, -0.5029860367700724), - new Grad4(0.6740059517812944, 0.3239847771997537, 0.3239847771997537, -0.5794684678643381), - new Grad4(0.03381941603233842, 0.03381941603233842, 0.03381941603233842, 0.9982828964265062), - new Grad4(-0.044802370851755174, -0.044802370851755174, 0.508629699630796, 0.8586508742123365), - new Grad4(-0.044802370851755174, 0.508629699630796, -0.044802370851755174, 0.8586508742123365), - new Grad4(-0.12128480194602098, 0.4321472685365301, 0.4321472685365301, 0.7821684431180708), - new Grad4(0.508629699630796, -0.044802370851755174, -0.044802370851755174, 0.8586508742123365), - new Grad4(0.4321472685365301, -0.12128480194602098, 0.4321472685365301, 0.7821684431180708), - new Grad4(0.4321472685365301, 0.4321472685365301, -0.12128480194602098, 0.7821684431180708), - new Grad4(0.37968289875261624, 0.37968289875261624, 0.37968289875261624, 0.753341017856078), - new Grad4(0.03381941603233842, 0.03381941603233842, 0.9982828964265062, 0.03381941603233842), - new Grad4(-0.044802370851755174, 0.044802370851755174, 0.8586508742123365, 0.508629699630796), - new Grad4(-0.044802370851755174, 0.508629699630796, 0.8586508742123365, -0.044802370851755174), - new Grad4(-0.12128480194602098, 0.4321472685365301, 0.7821684431180708, 0.4321472685365301), - new Grad4(0.508629699630796, -0.044802370851755174, 0.8586508742123365, -0.044802370851755174), - new Grad4(0.4321472685365301, -0.12128480194602098, 0.7821684431180708, 0.4321472685365301), - new Grad4(0.4321472685365301, 0.4321472685365301, 0.7821684431180708, -0.12128480194602098), - new Grad4(0.37968289875261624, 0.37968289875261624, 0.753341017856078, 0.37968289875261624), - new Grad4(0.03381941603233842, 0.9982828964265062, 0.03381941603233842, 0.03381941603233842), - new Grad4(-0.044802370851755174, 0.8586508742123365, -0.044802370851755174, 0.508629699630796), - new Grad4(-0.044802370851755174, 0.8586508742123365, 0.508629699630796, -0.044802370851755174), - new Grad4(-0.12128480194602098, 0.7821684431180708, 0.4321472685365301, 0.4321472685365301), - new Grad4(0.508629699630796, 0.8586508742123365, -0.044802370851755174, -0.044802370851755174), - new Grad4(0.4321472685365301, 0.7821684431180708, -0.12128480194602098, 0.4321472685365301), - new Grad4(0.4321472685365301, 0.7821684431180708, 0.4321472685365301, -0.12128480194602098), - new Grad4(0.37968289875261624, 0.753341017856078, 0.37968289875261624, 0.37968289875261624), - new Grad4(0.9982828964265062, 0.03381941603233842, 0.03381941603233842, 0.03381941603233842), - new Grad4(0.8586508742123365, -0.044802370851755174, -0.044802370851755174, 0.508629699630796), - new Grad4(0.8586508742123365, -0.044802370851755174, 0.508629699630796, -0.044802370851755174), - new Grad4(0.7821684431180708, -0.12128480194602098, 0.4321472685365301, 0.4321472685365301), - new Grad4(0.8586508742123365, 0.508629699630796, -0.044802370851755174, -0.044802370851755174), - new Grad4(0.7821684431180708, 0.4321472685365301, -0.12128480194602098, 0.4321472685365301), - new Grad4(0.7821684431180708, 0.4321472685365301, 0.4321472685365301, -0.12128480194602098), - new Grad4(0.753341017856078, 0.37968289875261624, 0.37968289875261624, 0.37968289875261624) - }; - for (Grad4 grad41 : grad4) { - grad41.dx /= N4; - grad41.dy /= N4; - grad41.dz /= N4; - grad41.dw /= N4; - } - for (int i = 0; i < PSIZE; i++) { - GRADIENTS_4D[i] = grad4[i % grad4.length]; - } - } -} From 42298f11a9a3379cb2237f9cf9c9e346ce8a3648 Mon Sep 17 00:00:00 2001 From: monkstone Date: Mon, 5 Apr 2021 19:48:28 +0100 Subject: [PATCH 2/3] Almost there --- src/main/java/processing/core/PApplet.java | 93 +--------------------- test/respond_to_test.rb | 1 - 2 files changed, 1 insertion(+), 93 deletions(-) diff --git a/src/main/java/processing/core/PApplet.java b/src/main/java/processing/core/PApplet.java index 8067a75..597c6dd 100644 --- a/src/main/java/processing/core/PApplet.java +++ b/src/main/java/processing/core/PApplet.java @@ -39,7 +39,6 @@ // loadXML() error handling import javax.xml.parsers.ParserConfigurationException; -import monkstone.noise.NoiseGenerator; import org.xml.sax.SAXException; // TODO have this removed by 4.0 final @@ -48,8 +47,6 @@ import processing.data.*; import processing.event.*; import processing.opengl.*; -import monkstone.noise.Noise; -import monkstone.noise.NoiseMode; /** * Base class for all sketches that use processing.core. @@ -106,7 +103,6 @@ public class PApplet implements PConstants { } } - Noise noiseGenerator = new NoiseGenerator(); /** * Whether to use native (AWT) dialogs for selectInput and selectOutput. The * native dialogs on some platforms can be ugly, buggy, or missing features. @@ -4887,9 +4883,6 @@ public final void randomSeed(long seed) { internalRandom.setSeed(seed); } - public void noiseMode(NoiseMode mode) { - noiseGenerator.noiseMode(mode); - } /** * * @param lod @@ -4913,91 +4906,7 @@ public void noiseDetail(int lod, float falloff) { } - /** - * @param x - * @return - */ - public float noise(float x) { - return noiseGenerator.noise(x); - } - - /** - * @param x - * @param y - * @return - */ - public float noise(float x, float y) { - return noiseGenerator.noise(x, y); - } - - /** - * ( begin auto-generated from noise.xml ) - * - * Returns the Perlin noise value at specified coordinates.Perlin noise is a - * random sequence generator producing a more natural ordered, harmonic - * succession of numbers compared to the standard random() function. - * It was invented by Ken Perlin in the 1980s and been used since in - * graphical applications to produce procedural textures, natural motion, - * shapes, terrains etc. The main difference to the - * random() function is that Perlin noise is defined in an infinite - * n-dimensional space where each pair of coordinates corresponds to a fixed - * semi-random value (fixed only for the lifespan of the program). The - * resulting value will always be between 0.0 and 1.0. Processing can - * compute 1D, 2D and 3D noise, depending on the number of coordinates - * given. The noise value can be animated by moving through the noise space - * as demonstrated in the example above. The 2nd and 3rd dimension can also - * be interpreted as time.The actual noise is structured similar to an audio - * signal, in respect to the function's use of frequencies. Similar to the - * concept of harmonics in physics, perlin noise is computed over several - * octaves which are added together for the final result. Another way to - * adjust the character of the resulting sequence is the scale of the input - * coordinates. As the function works within an infinite space the value of - * the coordinates doesn't matter as such, only the distance between - * successive coordinates does (eg. when using noise() within a - * loop). As a general rule the smaller the difference between coordinates, - * the smoother the resulting noise sequence will be. Steps of 0.005-0.03 - * work best for most applications, but this will differ depending on use. - * - * - * - * @return - * @webref math:random - * @param x x-coordinate in noise space - * @param y y-coordinate in noise space - * @param z z-coordinate in noise space - * @see PApplet#noiseSeed(long) - * @see PApplet#noiseDetail(int, float) - * @see PApplet#random(float,float) - */ - public float noise(float x, float y, float z) { - return noiseGenerator.noise(x, y, z); - } - - public float noise(float x, float y, float z, float w) { - return noiseGenerator.noise(x, y, z, w); - } - - /** - * - * - * Sets the seed value for noise(). By default, noise() - * produces different results each time the program is run. Set the - * value parameter to a constant to return the same pseudo-random - * numbers each time the software is run. - * - * - * @webref math:random - * @param seed seed value - * @see PApplet#noise(float, float, float) - * @see PApplet#noiseDetail(int, float) - * @see PApplet#random(float,float) - * @see PApplet#randomSeed(long) - */ - public void noiseSeed(long seed) { - noiseGenerator.noiseSeed(seed); - } - - // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . /** * ( begin auto-generated from loadImage.xml ) * diff --git a/test/respond_to_test.rb b/test/respond_to_test.rb index 8631d0e..60720f5 100644 --- a/test/respond_to_test.rb +++ b/test/respond_to_test.rb @@ -104,7 +104,6 @@ no_stroke no_tint noise - noise_seed normal ortho perspective From a8752b8cf19fba1e6d780868a10313b7fee46c0b Mon Sep 17 00:00:00 2001 From: monkstone Date: Tue, 6 Apr 2021 19:22:08 +0100 Subject: [PATCH 3/3] Get read to merge --- CHANGELOG.md | 2 ++ README.md | 2 +- lib/picrate/version.rb | 2 +- picrate.gemspec | 2 +- vendors/Rakefile | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ff8cdd..87bef72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +v2.4.0 Refactor noise to two modules, FastNoise (default) & SmoothNoise, with terrain noise `:tnoise` option. + v2.3.0 Abandon Processing Value Noise in favour of OpenSimplex2, with choosable options. Added pdf library using iText5. v2.2.0 Bump to latest JOGL-rc January 2021 diff --git a/README.md b/README.md index c063922..7b18e9a 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Requires java to build (and [jogl-2.4.0-rc jars][jogl_jars]), but uses a maven w ```bash cd PiCrate # or whatever you call it rake # assumes an installed version of vanilla processing -jgem install picrate-2.2.0-java.gem +jgem install picrate-2.4.0-java.gem ``` To create a template sketch:- diff --git a/lib/picrate/version.rb b/lib/picrate/version.rb index 5c0f42f..77d6992 100644 --- a/lib/picrate/version.rb +++ b/lib/picrate/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module PiCrate - VERSION = '2.3.0' + VERSION = '2.4.0' end diff --git a/picrate.gemspec b/picrate.gemspec index 5f50004..80c1e04 100644 --- a/picrate.gemspec +++ b/picrate.gemspec @@ -31,7 +31,7 @@ Gem::Specification.new do |gem| gem.files << 'library/svg/batik-all-1.14.jar' gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) - gem.add_development_dependency 'minitest', '~> 5.10' + gem.add_development_dependency 'minitest', '~> 5.14' gem.add_runtime_dependency 'rake', '~> 13.0' gem.add_runtime_dependency 'arcball', '~> 1.0', '>= 1.0.1' gem.require_paths = ['lib'] diff --git a/vendors/Rakefile b/vendors/Rakefile index 5840c3b..daf5db1 100644 --- a/vendors/Rakefile +++ b/vendors/Rakefile @@ -8,7 +8,7 @@ SOUND = 'sound.zip' PROCESSING_GITHUB = 'https://github.com/processing' VIDEO = 'video.zip' DOWNLOAD = 'releases/download/latest' -EXAMPLES = '0.5.6' +EXAMPLES = '0.5.7' HOME_DIR = ENV['HOME'] LIBRARY = File.join(HOME_DIR, '.picrate', 'libraries') PROJECT_DIR = File.join(HOME_DIR, 'projects')