aboutsummaryrefslogtreecommitdiffstats
path: root/src/libnoiseforjava/module
diff options
context:
space:
mode:
Diffstat (limited to 'src/libnoiseforjava/module')
-rw-r--r--src/libnoiseforjava/module/Abs.java52
-rw-r--r--src/libnoiseforjava/module/Add.java53
-rw-r--r--src/libnoiseforjava/module/Billow.java184
-rw-r--r--src/libnoiseforjava/module/Blend.java79
-rw-r--r--src/libnoiseforjava/module/Cached.java97
-rw-r--r--src/libnoiseforjava/module/Checkerboard.java62
-rw-r--r--src/libnoiseforjava/module/Clamp.java90
-rw-r--r--src/libnoiseforjava/module/Const.java70
-rw-r--r--src/libnoiseforjava/module/Curve.java203
-rw-r--r--src/libnoiseforjava/module/Cylinders.java103
-rw-r--r--src/libnoiseforjava/module/Displace.java238
-rw-r--r--src/libnoiseforjava/module/Exponent.java79
-rw-r--r--src/libnoiseforjava/module/Gradient.java119
-rw-r--r--src/libnoiseforjava/module/Identity.java70
-rw-r--r--src/libnoiseforjava/module/Intersection.java63
-rw-r--r--src/libnoiseforjava/module/Invert.java48
-rw-r--r--src/libnoiseforjava/module/Max.java54
-rw-r--r--src/libnoiseforjava/module/Min.java56
-rw-r--r--src/libnoiseforjava/module/ModuleBase.java171
-rw-r--r--src/libnoiseforjava/module/Multiply.java55
-rw-r--r--src/libnoiseforjava/module/Perlin.java357
-rw-r--r--src/libnoiseforjava/module/Power.java56
-rw-r--r--src/libnoiseforjava/module/RidgedMulti.java357
-rw-r--r--src/libnoiseforjava/module/RotatePoint.java216
-rw-r--r--src/libnoiseforjava/module/ScaleBias.java124
-rw-r--r--src/libnoiseforjava/module/ScalePoint.java182
-rw-r--r--src/libnoiseforjava/module/Select.java300
-rw-r--r--src/libnoiseforjava/module/Simplex.java395
-rw-r--r--src/libnoiseforjava/module/Spheres.java102
-rw-r--r--src/libnoiseforjava/module/Terrace.java326
-rw-r--r--src/libnoiseforjava/module/TranslatePoint.java192
-rw-r--r--src/libnoiseforjava/module/Turbulence.java282
-rw-r--r--src/libnoiseforjava/module/Voronoi.java283
33 files changed, 5118 insertions, 0 deletions
diff --git a/src/libnoiseforjava/module/Abs.java b/src/libnoiseforjava/module/Abs.java
new file mode 100644
index 0000000..89e5c22
--- /dev/null
+++ b/src/libnoiseforjava/module/Abs.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class Abs extends ModuleBase
+{
+ /// Noise module that outputs the absolute value of the output value from
+ /// a source module.
+ ///
+ /// @image html moduleabs.png
+ ///
+ /// This noise module requires one source module.
+
+ Abs (ModuleBase sourceModule) throws ExceptionInvalidParam
+ {
+ super(1);
+ setSourceModule(0, sourceModule);
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (this.sourceModules[0] != null);
+
+ return Math.abs(this.sourceModules[0].getValue (x, y, z));
+ }
+
+}
diff --git a/src/libnoiseforjava/module/Add.java b/src/libnoiseforjava/module/Add.java
new file mode 100644
index 0000000..f06c895
--- /dev/null
+++ b/src/libnoiseforjava/module/Add.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class Add extends ModuleBase
+{
+ /// Noise module that outputs the additive value of the output value from
+ /// two source modules.
+ ///
+ /// This noise module requires two source modules.
+
+ public Add (ModuleBase sourceModuleOne, ModuleBase sourceModuleTwo) throws ExceptionInvalidParam
+ {
+ super(2);
+ setSourceModule(0, sourceModuleOne);
+ setSourceModule(1, sourceModuleTwo);
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+ assert (sourceModules[1] != null);
+
+ return sourceModules[0].getValue (x, y, z)
+ + sourceModules[1].getValue (x, y, z);
+ }
+
+}
diff --git a/src/libnoiseforjava/module/Billow.java b/src/libnoiseforjava/module/Billow.java
new file mode 100644
index 0000000..047c8df
--- /dev/null
+++ b/src/libnoiseforjava/module/Billow.java
@@ -0,0 +1,184 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.NoiseGen;
+import libnoiseforjava.NoiseGen.NoiseQuality;
+
+public class Billow extends ModuleBase
+{
+ /// Noise module that outputs three-dimensional "billowy" noise.
+ ///
+ /// @image html modulebillow.png
+ ///
+ /// This noise module generates "billowy" noise suitable for clouds and
+ /// rocks.
+ ///
+ /// This noise module is nearly identical to noise::module::Perlin except
+ /// this noise module modifies each octave with an absolute-value
+ /// function. See the documentation of noise::module::Perlin for more
+ /// information.
+
+
+ /// Default frequency for the Billow noise module.
+ static final double DEFAULT_BILLOW_FREQUENCY = 1.0;
+
+ /// Default lacunarity for the Billow noise module.
+ static final double DEFAULT_BILLOW_LACUNARITY = 2.0;
+
+ /// Default number of octaves for the the noise::module::Billow noise
+ /// module.
+ static final int DEFAULT_BILLOW_OCTAVE_COUNT = 6;
+
+ /// Default persistence value for the the noise::module::Billow noise
+ /// module.
+ static final double DEFAULT_BILLOW_PERSISTENCE = 0.5;
+
+ /// Default noise quality for the the noise::module::Billow noise module.
+ static final NoiseQuality DEFAULT_BILLOW_QUALITY = NoiseQuality.QUALITY_STD;
+
+ /// Default noise seed for the the noise::module::Billow noise module.
+ static final int DEFAULT_BILLOW_SEED = 0;
+
+ /// Maximum number of octaves for the the noise::module::Billow noise
+ /// module.
+ static final int BILLOW_MAX_OCTAVE = 30;
+
+ double frequency, lacunarity, persistence;
+ int octaveCount, seed;
+ NoiseQuality noiseQuality;
+
+ public Billow ()
+ {
+ super(0);
+ frequency = DEFAULT_BILLOW_FREQUENCY;
+ lacunarity = DEFAULT_BILLOW_LACUNARITY;
+ noiseQuality = DEFAULT_BILLOW_QUALITY;
+ octaveCount = DEFAULT_BILLOW_OCTAVE_COUNT;
+ persistence = DEFAULT_BILLOW_PERSISTENCE;
+ seed = DEFAULT_BILLOW_SEED;
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ double value = 0.0;
+ double signal = 0.0;
+ double curPersistence = 1.0;
+ double nx, ny, nz;
+ int calcSeed;
+
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+
+ for (int curOctave = 0; curOctave < octaveCount; curOctave++)
+ {
+ // Make sure that these floating-point values have the same range as a 32-
+ // bit integer so that we can pass them to the coherent-noise functions.
+ nx = NoiseGen.MakeInt32Range (x);
+ ny = NoiseGen.MakeInt32Range (y);
+ nz = NoiseGen.MakeInt32Range (z);
+
+ // Get the coherent-noise value from the input value and add it to the
+ // final result.
+ calcSeed = (seed + curOctave) & 0xffffffff;
+ signal = NoiseGen.GradientCoherentNoise3D (nx, ny, nz, calcSeed, noiseQuality);
+ signal = 2.0 * Math.abs(signal) - 1.0;
+ value += signal * curPersistence;
+
+ // Prepare the next octave.
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ curPersistence *= persistence;
+ }
+
+ value += 0.5;
+
+ return value;
+ }
+
+ public double getFrequency()
+ {
+ return frequency;
+ }
+
+ public double getLacunarity()
+ {
+ return lacunarity;
+ }
+
+ public double getPersistence()
+ {
+ return persistence;
+ }
+
+ public int getOctaveCount()
+ {
+ return octaveCount;
+ }
+
+ public int getSeed()
+ {
+ return seed;
+ }
+
+ public NoiseQuality getNoiseQuality()
+ {
+ return noiseQuality;
+ }
+
+ public void setFrequency(double frequency)
+ {
+ this.frequency = frequency;
+ }
+
+ public void setLacunarity(double lacunarity)
+ {
+ this.lacunarity = lacunarity;
+ }
+
+ public void setPersistence(double persistence)
+ {
+ this.persistence = persistence;
+ }
+
+ public void setOctaveCount(int octaveCount)
+ {
+ this.octaveCount = octaveCount;
+ }
+
+ public void setSeed(int seed)
+ {
+ this.seed = seed;
+ }
+
+ public void setNoiseQuality(NoiseQuality noiseQuality)
+ {
+ this.noiseQuality = noiseQuality;
+ }
+
+}
diff --git a/src/libnoiseforjava/module/Blend.java b/src/libnoiseforjava/module/Blend.java
new file mode 100644
index 0000000..5e442b7
--- /dev/null
+++ b/src/libnoiseforjava/module/Blend.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.Interp;
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class Blend extends ModuleBase
+{
+ /// Noise module that outputs a weighted blend of the output values from
+ /// two source modules given the output value supplied by a control module.
+ ///
+ /// Unlike most other noise modules, the index value assigned to a source
+ /// module determines its role in the blending operation:
+ /// - Source module 0 outputs one of the
+ /// values to blend.
+ /// - Source module 1 outputs one of the
+ /// values to blend.
+ /// - Source module 2 is known as the <i>control
+ /// module</i>. The control module determines the weight of the
+ /// blending operation. Negative values weigh the blend towards the
+ /// output value from the source module with an index value of 0.
+ /// Positive values weigh the blend towards the output value from the
+ /// source module with an index value of 1.
+ ///
+ /// An application can pass the control module to the setControlModule()
+ /// method instead of the setSourceModule() method. This may make the
+ /// application code easier to read.
+ ///
+ /// This noise module uses linear interpolation to perform the blending
+ /// operation.
+ ///
+ /// This noise module requires three source modules.
+
+ public Blend (ModuleBase sourceModuleOne, ModuleBase sourceModuleTwo,
+ ModuleBase sourceModuleThree) throws ExceptionInvalidParam
+ {
+ super(3);
+ setSourceModule(0, sourceModuleOne);
+ setSourceModule(1, sourceModuleTwo);
+ setSourceModule(2, sourceModuleThree);
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+ assert (sourceModules[1] != null);
+ assert (sourceModules[2] != null);
+
+ double v0 = sourceModules[0].getValue (x, y, z);
+ double v1 = sourceModules[1].getValue (x, y, z);
+ double alpha = (sourceModules[2].getValue (x, y, z) + 1.0) / 2.0;
+
+ return Interp.linearInterp (v0, v1, alpha);
+ }
+}
diff --git a/src/libnoiseforjava/module/Cached.java b/src/libnoiseforjava/module/Cached.java
new file mode 100644
index 0000000..3afab4c
--- /dev/null
+++ b/src/libnoiseforjava/module/Cached.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class Cached extends ModuleBase
+{
+ /// Noise module that caches the last output value generated by a source
+ /// module.
+ ///
+ /// If an application passes an input value to the getValue() method that
+ /// differs from the previously passed-in input value, this noise module
+ /// instructs the source module to calculate the output value. This
+ /// value, as well as the ( @a x, @a y, @a z ) coordinates of the input
+ /// value, are stored (cached) in this noise module.
+ ///
+ /// If the application passes an input value to the getValue() method
+ /// that is equal to the previously passed-in input value, this noise
+ /// module returns the cached output value without having the source
+ /// module recalculate the output value.
+ ///
+ /// If an application passes a new source module to the setSourceModule()
+ /// method, the cache is invalidated.
+ ///
+ /// Caching a noise module is useful if it is used as a source module for
+ /// multiple noise modules. If a source module is not cached, the source
+ /// module will redundantly calculate the same output value once for each
+ /// noise module in which it is included.
+ ///
+ /// This noise module requires one source module.
+
+ /// The cached output value at the cached input value.
+ double cachedValue;
+
+ /// Determines if a cached output value is stored in this noise module.
+ boolean isCached;
+
+ /// @a x coordinate of the cached input value.
+ double xCache;
+
+ /// @a y coordinate of the cached input value.
+ double yCache;
+
+ /// @a z coordinate of the cached input value.
+ double zCache;
+
+ public Cached(ModuleBase sourceModule) throws ExceptionInvalidParam
+ {
+ super(1);
+ setSourceModule(0, sourceModule);
+ isCached = false;
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+
+ if (!(isCached && x == xCache && y == yCache && z == zCache))
+ {
+ cachedValue = sourceModules[0].getValue (x, y, z);
+ xCache = x;
+ yCache = y;
+ zCache = z;
+ }
+
+ isCached = true;
+
+ return cachedValue;
+ }
+
+
+
+}
diff --git a/src/libnoiseforjava/module/Checkerboard.java b/src/libnoiseforjava/module/Checkerboard.java
new file mode 100644
index 0000000..d9f4e1f
--- /dev/null
+++ b/src/libnoiseforjava/module/Checkerboard.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.NoiseGen;
+
+public class Checkerboard extends ModuleBase
+{
+ /// Noise module that outputs a checkerboard pattern.
+ ///
+ /// This noise module outputs unit-sized blocks of alternating values.
+ /// The values of these blocks alternate between -1.0 and +1.0.
+ ///
+ /// This noise module is not really useful by itself, but it is often used
+ /// for debugging purposes.
+ ///
+ /// This noise module does not require any source modules.
+
+ public Checkerboard()
+ {
+ super(0);
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ int ix = (int)(Math.floor(NoiseGen.MakeInt32Range (x)));
+ int iy = (int)(Math.floor(NoiseGen.MakeInt32Range (y)));
+ int iz = (int)(Math.floor(NoiseGen.MakeInt32Range (z)));
+
+ // original was
+ //(ix & 1 ^ iy & 1 ^ iz & 1)
+ // not certain if this duplicates it or not
+ if ((ix%2 == 1) ^ (iy%2 == 1) ^ (iz%2 == 1))
+ return -1.0;
+ else
+ return 1.0;
+ }
+}
+
diff --git a/src/libnoiseforjava/module/Clamp.java b/src/libnoiseforjava/module/Clamp.java
new file mode 100644
index 0000000..3ad6d39
--- /dev/null
+++ b/src/libnoiseforjava/module/Clamp.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class Clamp extends ModuleBase
+{
+
+ /// Noise module that clamps the output value from a source module to a
+ /// range of values.
+ ///
+ /// @image html moduleclamp.png
+ ///
+ /// The range of values in which to clamp the output value is called the
+ /// <i>clamping range</i>.
+ ///
+ /// If the output value from the source module is less than the lower
+ /// bound of the clamping range, this noise module clamps that value to
+ /// the lower bound. If the output value from the source module is
+ /// greater than the upper bound of the clamping range, this noise module
+ /// clamps that value to the upper bound.
+ ///
+ /// To specify the upper and lower bounds of the clamping range, call the
+ /// setBounds() method.
+ ///
+ /// This noise module requires one source module.
+
+ /// Default lower bound of the clamping range for the Clamp noise module.
+ static final double DEFAULT_CLAMP_LOWER_BOUND = -1.0;
+
+ /// Default upper bound of the clamping range for the Clamp noise module.
+ static final double DEFAULT_CLAMP_UPPER_BOUND = 1.0;
+
+ double lowerBound, upperBound;
+
+ public Clamp (ModuleBase sourceModule) throws ExceptionInvalidParam
+ {
+ super(1);
+ setSourceModule(0, sourceModule);
+
+ lowerBound = DEFAULT_CLAMP_LOWER_BOUND;
+ upperBound = DEFAULT_CLAMP_UPPER_BOUND;
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+
+ double value = sourceModules[0].getValue (x, y, z);
+ if (value < lowerBound)
+ return lowerBound;
+ else if (value > upperBound)
+ return upperBound;
+ else
+ return value;
+ }
+
+ public void setBounds (double lowerBound, double upperBound)
+ {
+ assert (lowerBound < upperBound);
+
+ this.lowerBound = lowerBound;
+ this.upperBound = upperBound;
+ }
+
+}
diff --git a/src/libnoiseforjava/module/Const.java b/src/libnoiseforjava/module/Const.java
new file mode 100644
index 0000000..4454f7d
--- /dev/null
+++ b/src/libnoiseforjava/module/Const.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+public class Const extends ModuleBase
+{
+ /// Noise module that outputs a constant value.
+ ///
+ /// @image html moduleconst.png
+ ///
+ /// To specify the constant value, call the setConstValue() method.
+ ///
+ /// This noise module is not useful by itself, but it is often used as a
+ /// source module for other noise modules.
+ ///
+ /// This noise module does not require any source modules.
+
+ /// Default constant value for the Const noise module.
+ static final double DEFAULT_CONST_VALUE = 0.0;
+
+ double constValue;
+
+ public Const ()
+ {
+ super(0);
+ this.constValue = DEFAULT_CONST_VALUE;
+ }
+
+ public Const(double c) {
+ super(0);
+ this.constValue = c;
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ return constValue;
+ }
+
+ /// Sets the constant output value for this noise module.
+ ///
+ /// @param constValue The constant output value for this noise module.
+ public void setConstValue (double constValue)
+ {
+ this.constValue = constValue;
+ }
+
+}
diff --git a/src/libnoiseforjava/module/Curve.java b/src/libnoiseforjava/module/Curve.java
new file mode 100644
index 0000000..2d78818
--- /dev/null
+++ b/src/libnoiseforjava/module/Curve.java
@@ -0,0 +1,203 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.Interp;
+import libnoiseforjava.Misc;
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class Curve extends ModuleBase
+{
+ /// Noise module that maps the output value from a source module onto an
+ /// arbitrary function curve.
+ ///
+ /// This noise module maps the output value from the source module onto an
+ /// application-defined curve. This curve is defined by a number of
+ /// <i>control points</i>; each control point has an <i>input value</i>
+ /// that maps to an <i>output value</i>.
+ ///
+ /// To add the control points to this curve, call the addControlPoint()
+ /// method. Note that the class ControlPoint follows the class Curve in
+ /// this file.
+ ///
+ /// Since this curve is a cubic spline, an application must add a minimum
+ /// of four control points to the curve. If this is not done, the
+ /// getValue() method fails. Each control point can have any input and
+ /// output value, although no two control points can have the same input
+ /// value. There is no limit to the number of control points that can be
+ /// added to the curve.
+ ///
+ /// This noise module requires one source module
+
+ int controlPointCount;
+ ControlPoint[] controlPoints;
+
+ public Curve (ModuleBase sourceModule) throws ExceptionInvalidParam
+ {
+ super(1);
+ setSourceModule(0, sourceModule);
+ controlPointCount = 0;
+ controlPoints= new ControlPoint[1];
+ controlPoints[0] = new ControlPoint(0.0, 0.0);
+ }
+
+ public void addControlPoint (double inputValue, double outputValue)
+ throws ExceptionInvalidParam
+ {
+ // Find the insertion point for the new control point and insert the new
+ // point at that position. The control point array will remain sorted by
+ // input value.
+ int insertionPos = findInsertionPos(inputValue);
+ insertAtPos (insertionPos, inputValue, outputValue);
+ }
+
+ public void clearAllControlPoints ()
+ {
+ controlPoints = null;
+ controlPointCount = 0;
+ }
+
+ public int findInsertionPos (double inputValue) throws ExceptionInvalidParam
+ {
+ int insertionPos;
+ for (insertionPos = 0; insertionPos < controlPointCount; insertionPos++)
+ {
+ if (inputValue < controlPoints[insertionPos].inputValue)
+ // We found the array index in which to insert the new control point.
+ // Exit now.
+ break;
+ else if (inputValue == controlPoints[insertionPos].inputValue)
+ // Each control point is required to contain a unique input value, so
+ // throw an exception.
+ throw new ExceptionInvalidParam("Invalid Parameter in Curve");
+ }
+ return insertionPos;
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+ assert (controlPointCount >= 4);
+
+ // Get the output value from the source module.
+ double sourceModuleValue = sourceModules[0].getValue (x, y, z);
+
+ // Find the first element in the control point array that has an input value
+ // larger than the output value from the source module.
+ int indexPos;
+ for (indexPos = 0; indexPos < controlPointCount; indexPos++)
+ {
+ if (sourceModuleValue < controlPoints[indexPos].inputValue)
+ break;
+
+ }
+
+ // Find the four nearest control points so that we can perform cubic
+ // interpolation.
+ int index0 = Misc.ClampValue (indexPos - 2, 0, controlPointCount - 1);
+ int index1 = Misc.ClampValue (indexPos - 1, 0, controlPointCount - 1);
+ int index2 = Misc.ClampValue (indexPos , 0, controlPointCount - 1);
+ int index3 = Misc.ClampValue (indexPos + 1, 0, controlPointCount - 1);
+
+ // If some control points are missing (which occurs if the value from the
+ // source module is greater than the largest input value or less than the
+ // smallest input value of the control point array), get the corresponding
+ // output value of the nearest control point and exit now.
+ if (index1 == index2) {
+ return controlPoints[index1].outputValue;
+ }
+
+ // Compute the alpha value used for cubic interpolation.
+ double input0 = controlPoints[index1].inputValue;
+ double input1 = controlPoints[index2].inputValue;
+ double alpha = (sourceModuleValue - input0) / (input1 - input0);
+
+ // Now perform the cubic interpolation given the alpha value.
+ return Interp.cubicInterp(
+ controlPoints[index0].outputValue,
+ controlPoints[index1].outputValue,
+ controlPoints[index2].outputValue,
+ controlPoints[index3].outputValue,
+ alpha);
+ }
+
+ public void insertAtPos (int insertionPos, double inputValue,
+ double outputValue)
+ {
+ // Make room for the new control point at the specified position within the
+ // control point array. The position is determined by the input value of
+ // the control point; the control points must be sorted by input value
+ // within that array.
+ ControlPoint[] newControlPoints = new ControlPoint[controlPointCount + 1];
+
+ for (int t = 0; t < (controlPointCount + 1); t++)
+ newControlPoints[t] = new ControlPoint();
+
+ for (int i = 0; i < controlPointCount; i++) {
+ if (i < insertionPos) {
+ newControlPoints[i] = controlPoints[i];
+ } else {
+ newControlPoints[i + 1] = controlPoints[i];
+ }
+ }
+
+ controlPoints = newControlPoints;
+ ++controlPointCount;
+
+ // Now that we've made room for the new control point within the array, add
+ // the new control point.
+ controlPoints[insertionPos].inputValue = inputValue;
+ controlPoints[insertionPos].outputValue = outputValue;
+ }
+}
+
+
+/// This class defines a control point.
+///
+/// Control points are used for defining splines.
+class ControlPoint
+{
+ /// The input value.
+ double inputValue;
+
+ /// The output value that is mapped from the input value.
+ double outputValue;
+
+ ControlPoint()
+ {
+ inputValue = 0.0;
+ outputValue = 0.0;
+ }
+
+ ControlPoint(double inputValue, double outputValue)
+ {
+ this.inputValue = inputValue;
+ this.outputValue = outputValue;
+ }
+
+
+
+} \ No newline at end of file
diff --git a/src/libnoiseforjava/module/Cylinders.java b/src/libnoiseforjava/module/Cylinders.java
new file mode 100644
index 0000000..c67d019
--- /dev/null
+++ b/src/libnoiseforjava/module/Cylinders.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+public class Cylinders extends ModuleBase
+{
+ /// Noise module that outputs concentric cylinders.
+ ///
+ /// This noise module outputs concentric cylinders centered on the origin.
+ /// These cylinders are oriented along the @a y axis similar to the
+ /// concentric rings of a tree. Each cylinder extends infinitely along
+ /// the @a y axis.
+ ///
+ /// The first cylinder has a radius of 1.0. Each subsequent cylinder has
+ /// a radius that is 1.0 unit larger than the previous cylinder.
+ ///
+ /// The output value from this noise module is determined by the distance
+ /// between the input value and the the nearest cylinder surface. The
+ /// input values that are located on a cylinder surface are given the
+ /// output value 1.0 and the input values that are equidistant from two
+ /// cylinder surfaces are given the output value -1.0.
+ ///
+ /// An application can change the frequency of the concentric cylinders.
+ /// Increasing the frequency reduces the distances between cylinders. To
+ /// specify the frequency, call the setFrequency() method.
+ ///
+ /// This noise module, modified with some low-frequency, low-power
+ /// turbulence, is useful for generating wood-like textures.
+ ///
+ /// This noise module does not require any source modules.
+
+ /// Default frequency value for the Cylinders noise module.
+ static final double DEFAULT_CYLINDERS_FREQUENCY = 1.0;
+
+ /// Frequency of the concentric cylinders.
+ double frequency;
+
+ public Cylinders ()
+ {
+ super(0);
+ frequency = DEFAULT_CYLINDERS_FREQUENCY;
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ x *= frequency;
+ z *= frequency;
+
+ double distFromCenter = Math.sqrt(x * x + z * z);
+ double distFromSmallerSphere = distFromCenter - Math.floor(distFromCenter);
+ double distFromLargerSphere = 1.0 - distFromSmallerSphere;
+ double nearestDist = Math.min(distFromSmallerSphere, distFromLargerSphere);
+
+ // Puts it in the -1.0 to +1.0 range.
+ return 1.0 - (nearestDist * 4.0);
+ }
+
+ /// Returns the frequency of the concentric cylinders.
+ ///
+ /// @returns The frequency of the concentric cylinders.
+ ///
+ /// Increasing the frequency increases the density of the concentric
+ /// cylinders, reducing the distances between them.
+ public double getFrequency()
+ {
+ return frequency;
+ }
+
+ /// Sets the frequency of the concentric cylinders.
+ ///
+ /// @param frequency The frequency of the concentric cylinders.
+ ///
+ /// Increasing the frequency increases the density of the concentric
+ /// cylinders, reducing the distances between them.
+ public void setFrequency (double frequency)
+ {
+ this.frequency = frequency;
+ }
+
+}
diff --git a/src/libnoiseforjava/module/Displace.java b/src/libnoiseforjava/module/Displace.java
new file mode 100644
index 0000000..7725ce6
--- /dev/null
+++ b/src/libnoiseforjava/module/Displace.java
@@ -0,0 +1,238 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.exception.ExceptionInvalidParam;
+import libnoiseforjava.exception.ExceptionNoModule;
+
+public class Displace extends ModuleBase
+{
+ /// Noise module that uses three source modules to displace each
+ /// coordinate of the input value before returning the output value from
+ /// a source module.
+ ///
+ /// Unlike most other noise modules, the index value assigned to a source
+ /// module determines its role in the displacement operation:
+ /// - Source module 0 (left in the diagram) outputs a value.
+ /// - Source module 1 (lower left in the diagram) specifies the offset to
+ /// apply to the @a x coordinate of the input value.
+ /// - Source module 2 (lower center in the diagram) specifies the
+ /// offset to apply to the @a y coordinate of the input value.
+ /// - Source module 3 (lower right in the diagram) specifies the offset
+ /// to apply to the @a z coordinate of the input value.
+ ///
+ /// The getValue() method modifies the ( @a x, @a y, @a z ) coordinates of
+ /// the input value using the output values from the three displacement
+ /// modules before retrieving the output value from the source module.
+ ///
+ /// The Turbulence noise module is a special case of the
+ /// Displace module; internally, there are three Perlin-noise modules
+ /// that perform the displacement operation.
+ ///
+ /// This noise module requires four source modules.
+
+ public Displace (ModuleBase sourceModuleOne, ModuleBase sourceModuleTwo,
+ ModuleBase sourceModuleThree, ModuleBase sourceModuleFour) throws ExceptionInvalidParam
+ {
+ super(4);
+ setSourceModule(0, sourceModuleOne);
+ setSourceModule(1, sourceModuleTwo);
+ setSourceModule(2, sourceModuleThree);
+ setSourceModule(3, sourceModuleFour);
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+ assert (sourceModules[1] != null);
+ assert (sourceModules[2] != null);
+ assert (sourceModules[3] != null);
+
+ // Get the output values from the three displacement modules. Add each
+ // value to the corresponding coordinate in the input value.
+ double xDisplace = x + (sourceModules[1].getValue (x, y, z));
+ double yDisplace = y + (sourceModules[2].getValue (x, y, z));
+ double zDisplace = z + (sourceModules[3].getValue (x, y, z));
+
+ // Retrieve the output value using the offset input value instead of
+ // the original input value.
+ return sourceModules[0].getValue (xDisplace, yDisplace, zDisplace);
+ }
+
+ public ModuleBase getXDisplaceModule() throws ExceptionNoModule
+ {
+ if (sourceModules == null || sourceModules[1] == null)
+ throw new ExceptionNoModule ("Could not retrieve a source module " +
+ "from a noise module.");
+
+ return sourceModules[1];
+ }
+
+ /// Returns the @a y displacement module.
+ ///
+ /// @returns A reference to the @a y displacement module.
+ ///
+ /// @pre This displacement module has been added to this noise module
+ /// via a call to setSourceModule() or setYDisplaceModule().
+ ///
+ /// @throw ExceptionNoModule See the preconditions for more
+ /// information.
+ ///
+ /// The getValue() method displaces the input value by adding the output
+ /// value from this displacement module to the @a y coordinate of the
+ /// input value before returning the output value from the source
+ /// module.
+ public ModuleBase getYDisplaceModule () throws ExceptionNoModule
+ {
+ if (sourceModules == null || sourceModules[2] == null)
+ throw new ExceptionNoModule ("Could not retrieve a source module " +
+ "from Displace noise module.");
+
+ return sourceModules[2];
+ }
+
+ /// Returns the @a z displacement module.
+ ///
+ /// @returns A reference to the @a z displacement module.
+ ///
+ /// @pre This displacement module has been added to this noise module
+ /// via a call to setSourceModule() or setZDisplaceModule().
+ ///
+ /// @throw ExceptionNoModule See the preconditions for more
+ /// information.
+ ///
+ /// The getValue() method displaces the input value by adding the output
+ /// value from this displacement module to the @a z coordinate of the
+ /// input value before returning the output value from the source
+ /// module.
+ public ModuleBase getZDisplaceModule () throws ExceptionNoModule
+ {
+ if (sourceModules == null || sourceModules[3] == null)
+ throw new ExceptionNoModule ("Could not retrieve a source module " +
+ "from Displace noise module.");
+
+ return sourceModules[3];
+ }
+
+
+ /// Sets the @a x, @a y, and @a z displacement modules.
+ ///
+ /// @param xDisplaceModule Displacement module that displaces the @a x
+ /// coordinate of the input value.
+ /// @param yDisplaceModule Displacement module that displaces the @a y
+ /// coordinate of the input value.
+ /// @param zDisplaceModule Displacement module that displaces the @a z
+ /// coordinate of the input value.
+ ///
+ /// The getValue() method displaces the input value by adding the output
+ /// value from each of the displacement modules to the corresponding
+ /// coordinates of the input value before returning the output value
+ /// from the source module.
+ ///
+ /// This method assigns an index value of 1 to the @a x displacement
+ /// module, an index value of 2 to the @a y displacement module, and an
+ /// index value of 3 to the @a z displacement module.
+ ///
+ /// These displacement modules must exist throughout the lifetime of
+ /// this noise module unless another displacement module replaces it.
+ public void setDisplaceModules (ModuleBase xDisplaceModule,
+ ModuleBase yDisplaceModule, ModuleBase zDisplaceModule)
+ {
+ setXDisplaceModule (xDisplaceModule);
+ setYDisplaceModule (yDisplaceModule);
+ setZDisplaceModule (zDisplaceModule);
+ }
+
+ /// Sets the @a x displacement module.
+ ///
+ /// @param xDisplaceModule Displacement module that displaces the @a x
+ /// coordinate.
+ ///
+ /// The getValue() method displaces the input value by adding the output
+ /// value from this displacement module to the @a x coordinate of the
+ /// input value before returning the output value from the source
+ /// module.
+ ///
+ /// This method assigns an index value of 1 to the @a x displacement
+ /// module. Passing this displacement module to this method produces
+ /// the same results as passing this displacement module to the
+ /// setSourceModule() method while assigning it an index value of 1.
+ ///
+ /// This displacement module must exist throughout the lifetime of this
+ /// noise module unless another displacement module replaces it.
+ public void setXDisplaceModule (ModuleBase xDisplaceModule)
+ {
+ assert (sourceModules != null);
+ sourceModules[1] = xDisplaceModule;
+ }
+
+ /// Sets the @a y displacement module.
+ ///
+ /// @param yDisplaceModule Displacement module that displaces the @a y
+ /// coordinate.
+ ///
+ /// The getValue() method displaces the input value by adding the output
+ /// value from this displacement module to the @a y coordinate of the
+ /// input value before returning the output value from the source
+ /// module.
+ ///
+ /// This method assigns an index value of 2 to the @a y displacement
+ /// module. Passing this displacement module to this method produces
+ /// the same results as passing this displacement module to the
+ /// setSourceModule() method while assigning it an index value of 2.
+ ///
+ /// This displacement module must exist throughout the lifetime of this
+ /// noise module unless another displacement module replaces it.
+ public void setYDisplaceModule (ModuleBase yDisplaceModule)
+ {
+ assert (sourceModules != null);
+ sourceModules[2] = yDisplaceModule;
+ }
+
+ /// Sets the @a z displacement module.
+ ///
+ /// @param zDisplaceModule Displacement module that displaces the @a z
+ /// coordinate.
+ ///
+ /// The getValue() method displaces the input value by adding the output
+ /// value from this displacement module to the @a z coordinate of the
+ /// input value before returning the output value from the source
+ /// module.
+ ///
+ /// This method assigns an index value of 3 to the @a z displacement
+ /// module. Passing this displacement module to this method produces
+ /// the same results as passing this displacement module to the
+ /// setSourceModule() method while assigning it an index value of 3.
+ ///
+ /// This displacement module must exist throughout the lifetime of this
+ /// noise module unless another displacement module replaces it.
+ public void setZDisplaceModule (ModuleBase zDisplaceModule)
+ {
+ assert (sourceModules != null);
+ sourceModules[3] = zDisplaceModule;
+ }
+
+}
diff --git a/src/libnoiseforjava/module/Exponent.java b/src/libnoiseforjava/module/Exponent.java
new file mode 100644
index 0000000..64f9cdc
--- /dev/null
+++ b/src/libnoiseforjava/module/Exponent.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class Exponent extends ModuleBase
+{
+ /// Noise module that maps the output value from a source module onto an
+ /// exponential curve.
+ ///
+ /// Because most noise modules will output values that range from -1.0 to
+ /// +1.0, this noise module first normalizes this output value (the range
+ /// becomes 0.0 to 1.0), maps that value onto an exponential curve, then
+ /// rescales that value back to the original range.
+ ///
+ /// This noise module requires one source module.
+
+ /// Default exponent for the Exponent noise module.
+ static final double DEFAULT_EXPONENT = 1.0;
+
+
+ /// Exponent to apply to the output value from the source module.
+ double exponent;
+
+ public Exponent (ModuleBase sourceModule) throws ExceptionInvalidParam
+ {
+ super(1);
+ setSourceModule(0, sourceModule);
+ exponent = DEFAULT_EXPONENT;
+
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+
+ double value = sourceModules[0].getValue (x, y, z);
+ return (Math.pow (Math.abs ((value + 1.0) / 2.0), exponent) * 2.0 - 1.0);
+ }
+
+ /// Returns the exponent value to apply to the output value from the
+ /// source module.
+ ///
+ /// @returns The exponent value.
+ public double getExponent ()
+ {
+ return exponent;
+ }
+
+ public void setExponent(double exponent)
+ {
+ this.exponent = exponent;
+ }
+
+}
diff --git a/src/libnoiseforjava/module/Gradient.java b/src/libnoiseforjava/module/Gradient.java
new file mode 100644
index 0000000..91b4132
--- /dev/null
+++ b/src/libnoiseforjava/module/Gradient.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ * Copyright 2012 Michael Nugent (This module)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+/**
+ * User: mike nugent
+ * Date: 2/5/12
+ * Time: 4:40 PM
+ * URL: https://github.com/michaelnugent/libnoiseforjava
+ * Package: libnoiseforjava.module
+ */
+public class Gradient extends ModuleBase {
+
+ AXIS axis = AXIS.Y;
+
+ double inputMin = 0;
+ double inputMax = 255;
+
+ double scaledMin = -1;
+ double scaledMax = 1;
+
+ public enum AXIS {
+ X,
+ Y,
+ Z
+ };
+
+ public Gradient() {
+ super();
+ }
+
+ public Gradient(AXIS axis) {
+ super();
+ this.axis = axis;
+ }
+
+ public double getValue(double x, double y, double z) {
+ if (axis == AXIS.Y) {
+ double outy = scale(y, this.inputMin, this.inputMax, this.scaledMin, this.scaledMax);
+ return outy;
+ } else if (axis == AXIS.X) {
+ double outx = scale(x, this.inputMin, this.inputMax, this.scaledMin, this.scaledMax);
+ return outx;
+ } else {
+ double outz = scale(z, this.inputMin, this.inputMax, this.scaledMin, this.scaledMax);
+ return outz;
+ }
+ }
+
+ private double scale( double inVal, double inMin, double inMax, double min, double max ) {
+ double m = (max-min)/(inMax-inMin);
+ double c = min-inMin*m;
+ return m*inVal+c;
+ }
+
+ public AXIS getAxis() {
+ return axis;
+ }
+
+ public void setAxis(AXIS axis) {
+ this.axis = axis;
+ }
+
+ public double getInputMin() {
+ return inputMin;
+ }
+
+ public void setInputMin(double inputMin) {
+ this.inputMin = inputMin;
+ }
+
+ public double getInputMax() {
+ return inputMax;
+ }
+
+ public void setInputMax(double inputMax) {
+ this.inputMax = inputMax;
+ }
+
+ public double getScaledMin() {
+ return scaledMin;
+ }
+
+ public void setScaledMin(double scaledMin) {
+ this.scaledMin = scaledMin;
+ }
+
+ public double getScaledMax() {
+ return scaledMax;
+ }
+
+ public void setScaledMax(double scaledMax) {
+ this.scaledMax = scaledMax;
+ }
+}
diff --git a/src/libnoiseforjava/module/Identity.java b/src/libnoiseforjava/module/Identity.java
new file mode 100644
index 0000000..6fe0f3a
--- /dev/null
+++ b/src/libnoiseforjava/module/Identity.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ * Copyright 2012 Michael Nugent (This module)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+/**
+ * User: mike nugent
+ * Date: 2/5/12
+ * Time: 4:19 PM
+ * URL: https://github.com/michaelnugent/libnoiseforjava
+ * Package: libnoiseforjava.module
+ */
+public class Identity extends ModuleBase {
+
+ AXIS axis = AXIS.Y;
+
+ public enum AXIS {
+ X,
+ Y,
+ Z
+ };
+
+ public Identity() {
+ super();
+ }
+
+ public Identity( AXIS axis ) {
+ super();
+ this.axis = axis;
+ }
+
+ public void setAxis( AXIS axis ) {
+ this.axis = axis;
+ }
+
+ public double getValue(double x, double y, double z) {
+ if ( axis == AXIS.Y ) {
+ return y;
+ }
+ else if ( axis == AXIS.X ) {
+ return x;
+ }
+ else {
+ return z;
+ }
+ }
+}
diff --git a/src/libnoiseforjava/module/Intersection.java b/src/libnoiseforjava/module/Intersection.java
new file mode 100644
index 0000000..4a0f20e
--- /dev/null
+++ b/src/libnoiseforjava/module/Intersection.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ * Copyright 2012 Michael Nugent (This module)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+/**
+ * User: mike nugent
+ * Date: 2/18/12
+ * Time: 11:57 PM
+ * URL: https://github.com/michaelnugent/libnoiseforjava
+ * Package: libnoiseforjava.module
+ */
+public class Intersection extends ModuleBase {
+ double cutoff;
+ public Intersection(ModuleBase sourceModuleOne, ModuleBase sourceModuleTwo, double cutoff) throws ExceptionInvalidParam
+ {
+ super(2);
+ setSourceModule(0, sourceModuleOne);
+ setSourceModule(1, sourceModuleTwo);
+ this.cutoff = cutoff;
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+ assert (sourceModules[1] != null);
+
+ double s1 = sourceModules[0].getValue(x,y,z);
+ double s2 = sourceModules[1].getValue(x,y,z);
+
+ if ( s1 + cutoff > s2 && s1 - cutoff < s2 ) {
+ return s1;
+ }
+ else {
+ return -1;
+ }
+ }
+}
diff --git a/src/libnoiseforjava/module/Invert.java b/src/libnoiseforjava/module/Invert.java
new file mode 100644
index 0000000..106b79f
--- /dev/null
+++ b/src/libnoiseforjava/module/Invert.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class Invert extends ModuleBase
+{
+ /// Noise module that inverts the output value from a source module.
+ ///
+ /// This noise module requires one source module.
+ public Invert (ModuleBase sourceModule) throws ExceptionInvalidParam
+ {
+ super(1);
+ setSourceModule(0, sourceModule);
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+
+ return -(sourceModules[0].getValue (x, y, z));
+ }
+
+}
diff --git a/src/libnoiseforjava/module/Max.java b/src/libnoiseforjava/module/Max.java
new file mode 100644
index 0000000..34757f6
--- /dev/null
+++ b/src/libnoiseforjava/module/Max.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class Max extends ModuleBase
+{
+ /// Noise module that outputs the larger of the two output values from two
+ /// source modules.
+ ///
+ /// This noise module requires two source modules.
+
+ public Max (ModuleBase sourceModuleOne, ModuleBase sourceModuleTwo) throws ExceptionInvalidParam
+ {
+ super(2);
+ setSourceModule(0, sourceModuleOne);
+ setSourceModule(1, sourceModuleTwo);
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+ assert (sourceModules[1] != null);
+
+ double v0 = sourceModules[0].getValue (x, y, z);
+ double v1 = sourceModules[1].getValue (x, y, z);
+ return Math.max(v0, v1);
+ }
+
+}
diff --git a/src/libnoiseforjava/module/Min.java b/src/libnoiseforjava/module/Min.java
new file mode 100644
index 0000000..cd6bea0
--- /dev/null
+++ b/src/libnoiseforjava/module/Min.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class Min extends ModuleBase
+{
+ /// Noise module that outputs the smaller of the two output values from
+ /// two source modules.
+ ///
+ /// @image html modulemin.png
+ ///
+ /// This noise module requires two source modules.
+
+ public Min (ModuleBase sourceModuleOne, ModuleBase sourceModuleTwo) throws ExceptionInvalidParam
+ {
+ super(2);
+ setSourceModule(0, sourceModuleOne);
+ setSourceModule(1, sourceModuleTwo);
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+ assert (sourceModules[1] != null);
+
+ double v0 = sourceModules[0].getValue (x, y, z);
+ double v1 = sourceModules[1].getValue (x, y, z);
+ return Math.min(v0, v1);
+ }
+
+}
diff --git a/src/libnoiseforjava/module/ModuleBase.java b/src/libnoiseforjava/module/ModuleBase.java
new file mode 100644
index 0000000..895e67b
--- /dev/null
+++ b/src/libnoiseforjava/module/ModuleBase.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.exception.ExceptionInvalidParam;
+import libnoiseforjava.exception.ExceptionNoModule;
+
+public class ModuleBase
+{
+
+ // base class for noise modules.
+ public ModuleBase[] sourceModules;
+ public int modulesRequired;
+
+ public ModuleBase()
+ {
+ modulesRequired = 0;
+ }
+
+ public ModuleBase (int modulesRequired)
+ {
+ // Create an array of pointers to all source modules required by this
+ // noise module. Set these pointers to null.
+ if(modulesRequired>0)
+ {
+ sourceModules = new ModuleBase[modulesRequired];
+ for (int i = 0; i < modulesRequired; i++)
+ {
+ sourceModules[i] = new ModuleBase();
+ }
+ }
+ else
+ sourceModules = null;
+
+ this.modulesRequired = modulesRequired;
+ }
+
+ /// Returns a reference to a source module connected to this noise
+ /// module.
+ ///
+ /// @param index The index value assigned to the source module.
+ ///
+ /// @returns A reference to the source module.
+ ///
+ /// @pre The index value ranges from 0 to one less than the number of
+ /// source modules required by this noise module.
+ /// @pre A source module with the specified index value has been added
+ /// to this noise module via a call to setSourceModule().
+ ///
+ /// @throw ExceptionNoModule See the preconditions for more
+ /// information.
+ ///
+ /// Each noise module requires the attachment of a certain number of
+ /// source modules before an application can call the getValue()
+ /// method.
+ public ModuleBase getSourceModule (int index) throws ExceptionNoModule
+ {
+ if (sourceModules != null)
+ {
+ if (index >= getSourceModuleCount () || index < 0
+ || sourceModules[index] == null)
+ {
+ throw new ExceptionNoModule ("Could not retrieve a source module " +
+ "from a noise module.");
+ }
+
+ return (sourceModules[index]);
+ }
+ throw new ExceptionNoModule ("Could not retrieve a source module " +
+ "from a noise module.");
+ }
+
+ /// Returns the number of source modules required by this noise
+ /// module.
+ ///
+ /// @returns The number of source modules required by this noise
+ /// module.
+ public int getSourceModuleCount()
+ {
+ return modulesRequired;
+ }
+
+ /// Generates an output value given the coordinates of the specified
+ /// input value.
+ ///
+ /// @param x The @a x coordinate of the input value.
+ /// @param y The @a y coordinate of the input value.
+ /// @param z The @a z coordinate of the input value.
+ ///
+ /// @returns The output value.
+ ///
+ /// @pre All source modules required by this noise module have been
+ /// passed to the setSourceModule() method.
+ ///
+ /// Before an application can call this method, it must first connect
+ /// all required source modules via the setSourceModule() method. If
+ /// these source modules are not connected to this noise module, this
+ /// method raises a debug assertion.
+ ///
+ /// To determine the number of source modules required by this noise
+ /// module, call the getSourceModuleCount() method.
+ public double getValue (double x, double y, double z)
+ {
+ return x;
+ }
+
+ /// Connects a source module to this noise module.
+ ///
+ /// @param index An index value to assign to this source module.
+ /// @param sourceModule The source module to attach.
+ ///
+ /// @pre The index value ranges from 0 to one less than the number of
+ /// source modules required by this noise module.
+ ///
+ /// @throw ExceptionInvalidParam An invalid parameter was
+ /// specified; see the preconditions for more information.
+ ///
+ /// A noise module mathematically combines the output values from the
+ /// source modules to generate the value returned by getValue().
+ ///
+ /// The index value to assign a source module is a unique identifier
+ /// for that source module. If an index value has already been
+ /// assigned to a source module, this noise module replaces the old
+ /// source module with the new source module.
+ ///
+ /// Before an application can call the getValue() method, it must
+ /// first connect all required source modules. To determine the
+ /// number of source modules required by this noise module, call the
+ /// getSourceModuleCount() method.
+ ///
+ /// This source module must exist throughout the lifetime of this
+ /// noise module unless another source module replaces that source
+ /// module.
+ ///
+ /// A noise module does not modify a source module; it only modifies
+ /// its output values.
+ public void setSourceModule (int index, ModuleBase sourceModule)
+ throws ExceptionInvalidParam
+ {
+ if (sourceModules != null)
+ {
+ if (index >= getSourceModuleCount () || index < 0)
+ throw new ExceptionInvalidParam ("Invalid Parameter in ModuleBase");
+ }
+ this.sourceModules[index] = sourceModule;
+ }
+
+}
diff --git a/src/libnoiseforjava/module/Multiply.java b/src/libnoiseforjava/module/Multiply.java
new file mode 100644
index 0000000..944994e
--- /dev/null
+++ b/src/libnoiseforjava/module/Multiply.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class Multiply extends ModuleBase
+{
+ /// Noise module that outputs the product of the two output values from
+ /// two source modules.
+ ///
+ /// @image html modulemultiply.png
+ ///
+ /// This noise module requires two source modules.
+
+ public Multiply (ModuleBase sourceModuleOne, ModuleBase sourceModuleTwo) throws ExceptionInvalidParam
+ {
+ super(2);
+ setSourceModule(0, sourceModuleOne);
+ setSourceModule(1, sourceModuleTwo);
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+ assert (sourceModules[1] != null);
+
+ return sourceModules[0].getValue (x, y, z)
+ * sourceModules[1].getValue (x, y, z);
+ }
+
+}
diff --git a/src/libnoiseforjava/module/Perlin.java b/src/libnoiseforjava/module/Perlin.java
new file mode 100644
index 0000000..70fb22e
--- /dev/null
+++ b/src/libnoiseforjava/module/Perlin.java
@@ -0,0 +1,357 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.NoiseGen;
+import libnoiseforjava.NoiseGen.NoiseQuality;
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class Perlin extends ModuleBase
+{
+ /// Noise module that outputs 3-dimensional Perlin noise.
+ ///
+ /// Perlin noise is the sum of several coherent-noise functions of
+ /// ever-increasing frequencies and ever-decreasing amplitudes.
+ ///
+ /// An important property of Perlin noise is that a small change in the
+ /// input value will produce a small change in the output value, while a
+ /// large change in the input value will produce a random change in the
+ /// output value.
+ ///
+ /// This noise module outputs Perlin-noise values that usually range from
+ /// -1.0 to +1.0, but there are no guarantees that all output values will
+ /// exist within that range.
+ ///
+ /// For a better description of Perlin noise, see the links in the
+ /// <i>References and Acknowledgments</i> section.
+ ///
+ /// This noise module does not require any source modules.
+ ///
+ /// <b>Octaves</b>
+ ///
+ /// The number of octaves control the <i>amount of detail</i> of the
+ /// Perlin noise. Adding more octaves increases the detail of the Perlin
+ /// noise, but with the drawback of increasing the calculation time.
+ ///
+ /// An octave is one of the coherent-noise functions in a series of
+ /// coherent-noise functions that are added together to form Perlin
+ /// noise.
+ ///
+ /// An application may specify the frequency of the first octave by
+ /// calling the setFrequency() method.
+ ///
+ /// An application may specify the number of octaves that generate Perlin
+ /// noise by calling the setOctaveCount() method.
+ ///
+ /// These coherent-noise functions are called octaves because each octave
+ /// has, by default, double the frequency of the previous octave. Musical
+ /// tones have this property as well; a musical C tone that is one octave
+ /// higher than the previous C tone has double its frequency.
+ ///
+ /// <b>Frequency</b>
+ ///
+ /// An application may specify the frequency of the first octave by
+ /// calling the setFrequency() method.
+ ///
+ /// <b>Persistence</b>
+ ///
+ /// The persistence value controls the <i>roughness</i> of the Perlin
+ /// noise. Larger values produce rougher noise.
+ ///
+ /// The persistence value determines how quickly the amplitudes diminish
+ /// for successive octaves. The amplitude of the first octave is 1.0.
+ /// The amplitude of each subsequent octave is equal to the product of the
+ /// previous octave's amplitude and the persistence value. So a
+ /// persistence value of 0.5 sets the amplitude of the first octave to
+ /// 1.0; the second, 0.5; the third, 0.25; etc.
+ ///
+ /// An application may specify the persistence value by calling the
+ /// setPersistence() method.
+ ///
+ /// <b>Lacunarity</b>
+ ///
+ /// The lacunarity specifies the frequency multipler between successive
+ /// octaves.
+ ///
+ /// The effect of modifying the lacunarity is subtle; you may need to play
+ /// with the lacunarity value to determine the effects. For best results,
+ /// set the lacunarity to a number between 1.5 and 3.5.
+ ///
+ /// <b>References &amp; acknowledgments</b>
+ ///
+ /// <a href=http://www.noisemachine.com/talk1/>The Noise Machine</a> -
+ /// From the master, Ken Perlin himself. This page contains a
+ /// presentation that describes Perlin noise and some of its variants.
+ /// He won an Oscar for creating the Perlin noise algorithm!
+ ///
+ /// <a
+ /// href=http://freespace.virgin.net/hugo.elias/models/m_perlin.htm>
+ /// Perlin Noise</a> - Hugo Elias's webpage contains a very good
+ /// description of Perlin noise and describes its many applications. This
+ /// page gave me the inspiration to create libnoise in the first place.
+ /// Now that I know how to generate Perlin noise, I will never again use
+ /// cheesy subdivision algorithms to create terrain (unless I absolutely
+ /// need the speed.)
+ ///
+ /// <a
+ /// href=http://www.robo-murito.net/code/perlin-noise-math-faq.html>The
+ /// Perlin noise math FAQ</a> - A good page that describes Perlin noise in
+ /// plain English with only a minor amount of math. During development of
+ /// libnoise, I noticed that my coherent-noise function generated terrain
+ /// with some "regularity" to the terrain features. This page describes a
+ /// better coherent-noise function called <i>gradient noise</i>. This
+ /// version of the Perlin module uses gradient coherent noise to
+ /// generate Perlin noise.
+
+
+ /// Default frequency for the noise::module::Perlin noise module.
+ static final double DEFAULT_PERLIN_FREQUENCY = 1.0;
+
+ /// Default lacunarity for the noise::module::Perlin noise module.
+ static final double DEFAULT_PERLIN_LACUNARITY = 2.0;
+
+ /// Default number of octaves for the noise::module::Perlin noise module.
+ static final int DEFAULT_PERLIN_OCTAVE_COUNT = 6;
+
+ /// Default persistence value for the noise::module::Perlin noise module.
+ static final double DEFAULT_PERLIN_PERSISTENCE = 0.5;
+
+ /// Default noise quality for the noise::module::Perlin noise module.
+ static final NoiseQuality DEFAULT_PERLIN_QUALITY = NoiseQuality.QUALITY_STD;
+
+ /// Default noise seed for the noise::module::Perlin noise module.
+ static final int DEFAULT_PERLIN_SEED = 0;
+
+ /// Maximum number of octaves for the noise::module::Perlin noise module.
+ static final int PERLIN_MAX_OCTAVE = 30;
+
+
+ /// Frequency of the first octave.
+ double frequency;
+
+ /// Frequency multiplier between successive octaves.
+ double lacunarity;
+
+ /// Quality of the Perlin noise.
+ NoiseQuality noiseQuality;
+
+ /// Total number of octaves that generate the Perlin noise.
+ int octaveCount;
+
+ /// Persistence of the Perlin noise.
+ double persistence;
+
+ /// Seed value used by the Perlin-noise function.
+ int seed;
+
+
+ public Perlin ()
+ {
+ super(0);
+ frequency = DEFAULT_PERLIN_FREQUENCY;
+ lacunarity = DEFAULT_PERLIN_LACUNARITY;
+ noiseQuality = DEFAULT_PERLIN_QUALITY;
+ octaveCount = DEFAULT_PERLIN_OCTAVE_COUNT;
+ persistence = DEFAULT_PERLIN_PERSISTENCE;
+ seed = DEFAULT_PERLIN_SEED;
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ double value = 0.0;
+ double signal = 0.0;
+ double curPersistence = 1.0;
+ double nx, ny, nz;
+ int curSeed;
+
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+
+ for (int curOctave = 0; curOctave < octaveCount; curOctave++)
+ {
+
+ // Make sure that these floating-point values have the same range as a 32-
+ // bit integer so that we can pass them to the coherent-noise functions.
+ nx = NoiseGen.MakeInt32Range (x);
+ ny = NoiseGen.MakeInt32Range (y);
+ nz = NoiseGen.MakeInt32Range (z);
+
+ // Get the coherent-noise value from the input value and add it to the
+ // final result.
+ curSeed = (seed + curOctave) & 0xffffffff;
+ signal = NoiseGen.GradientCoherentNoise3D (nx, ny, nz, curSeed, noiseQuality);
+ value += signal * curPersistence;
+
+ // Prepare the next octave.
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ curPersistence *= persistence;
+ }
+
+ return value;
+ }
+
+ /// Returns the frequency of the first octave.
+ ///
+ /// @returns The frequency of the first octave.
+ public double getFrequency ()
+ {
+ return frequency;
+ }
+
+ /// Returns the lacunarity of the Perlin noise.
+ ///
+ /// @returns The lacunarity of the Perlin noise.
+ ///
+ /// The lacunarity is the frequency multiplier between successive
+ /// octaves.
+ public double getLacunarity ()
+ {
+ return lacunarity;
+ }
+
+ /// Returns the quality of the Perlin noise.
+ ///
+ /// @returns The quality of the Perlin noise.
+ ///
+ /// See NoiseQuality for definitions of the various
+ /// coherent-noise qualities.
+ public NoiseQuality getNoiseQuality ()
+ {
+ return noiseQuality;
+ }
+
+ /// Returns the number of octaves that generate the Perlin noise.
+ ///
+ /// @returns The number of octaves that generate the Perlin noise.
+ ///
+ /// The number of octaves controls the amount of detail in the Perlin
+ /// noise.
+ public int getOctaveCount ()
+ {
+ return octaveCount;
+ }
+
+ /// Returns the persistence value of the Perlin noise.
+ ///
+ /// @returns The persistence value of the Perlin noise.
+ ///
+ /// The persistence value controls the roughness of the Perlin noise.
+ public double getPersistence ()
+ {
+ return persistence;
+ }
+
+ /// Returns the seed value used by the Perlin-noise function.
+ ///
+ /// @returns The seed value.
+ public int getSeed ()
+ {
+ return seed;
+ }
+
+ /// Sets the frequency of the first octave.
+ ///
+ /// @param frequency The frequency of the first octave.
+ public void setFrequency (double frequency)
+ {
+ this.frequency = frequency;
+ }
+
+ /// Sets the lacunarity of the Perlin noise.
+ ///
+ /// @param lacunarity The lacunarity of the Perlin noise.
+ ///
+ /// The lacunarity is the frequency multiplier between successive
+ /// octaves.
+ ///
+ /// For best results, set the lacunarity to a number between 1.5 and
+ /// 3.5.
+ public void setLacunarity (double lacunarity)
+ {
+ this.lacunarity = lacunarity;
+ }
+
+ /// Sets the quality of the Perlin noise.
+ ///
+ /// @param noiseQuality The quality of the Perlin noise.
+ ///
+ /// See NoiseQuality for definitions of the various
+ /// coherent-noise qualities.
+ public void setNoiseQuality (NoiseQuality noiseQuality)
+ {
+ this.noiseQuality = noiseQuality;
+ }
+
+ /// Sets the number of octaves that generate the Perlin noise.
+ ///
+ /// @param octaveCount The number of octaves that generate the Perlin
+ /// noise.
+ ///
+ /// @pre The number of octaves ranges from 1 to PERLIN_MAX_OCTAVE.
+ ///
+ /// @throw noise::ExceptionInvalidParam An invalid parameter was
+ /// specified; see the preconditions for more information.
+ ///
+ /// The number of octaves controls the amount of detail in the Perlin
+ /// noise.
+ ///
+ /// The larger the number of octaves, the more time required to
+ /// calculate the Perlin-noise value.
+ public void setOctaveCount (int octaveCount) throws ExceptionInvalidParam
+ {
+ if (octaveCount < 1 || octaveCount > PERLIN_MAX_OCTAVE)
+ {
+ throw new ExceptionInvalidParam ("Invalid parameter In Perlin Noise Module");
+ }
+
+ this.octaveCount = octaveCount;
+ }
+
+ /// Sets the persistence value of the Perlin noise.
+ ///
+ /// @param persistence The persistence value of the Perlin noise.
+ ///
+ /// The persistence value controls the roughness of the Perlin noise.
+ ///
+ /// For best results, set the persistence to a number between 0.0 and
+ /// 1.0.
+ public void setPersistence (double persistence)
+ {
+ this.persistence = persistence;
+ }
+
+ /// Sets the seed value used by the Perlin-noise function.
+ ///
+ /// @param seed The seed value.
+ public void setSeed (int seed)
+ {
+ this.seed = seed;
+ }
+
+}
diff --git a/src/libnoiseforjava/module/Power.java b/src/libnoiseforjava/module/Power.java
new file mode 100644
index 0000000..53484a9
--- /dev/null
+++ b/src/libnoiseforjava/module/Power.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class Power extends ModuleBase
+{
+ /// Noise module that raises the output value from a first source module
+ /// to the power of the output value from a second source module.
+ ///
+ /// The first source module must have an index value of 0.
+ ///
+ /// The second source module must have an index value of 1.
+ ///
+ /// This noise module requires two source modules.
+
+ public Power (ModuleBase sourceModuleOne, ModuleBase sourceModuleTwo) throws ExceptionInvalidParam
+ {
+ super(2);
+ setSourceModule(0, sourceModuleOne);
+ setSourceModule(1, sourceModuleTwo);
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+ assert (sourceModules[1] != null);
+
+ return Math.pow (sourceModules[0].getValue (x, y, z),
+ sourceModules[1].getValue (x, y, z));
+ }
+}
diff --git a/src/libnoiseforjava/module/RidgedMulti.java b/src/libnoiseforjava/module/RidgedMulti.java
new file mode 100644
index 0000000..c1a2d4c
--- /dev/null
+++ b/src/libnoiseforjava/module/RidgedMulti.java
@@ -0,0 +1,357 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.NoiseGen;
+import libnoiseforjava.NoiseGen.NoiseQuality;
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class RidgedMulti extends ModuleBase
+{
+ /// Noise module that outputs 3-dimensional ridged-multifractal noise.
+ ///
+ /// This noise module, heavily based on the Perlin-noise module, generates
+ /// ridged-multifractal noise. Ridged-multifractal noise is generated in
+ /// much of the same way as Perlin noise, except the output of each octave
+ /// is modified by an absolute-value function. Modifying the octave
+ /// values in this way produces ridge-like formations.
+ ///
+ /// Ridged-multifractal noise does not use a persistence value. This is
+ /// because the persistence values of the octaves are based on the values
+ /// generated from from previous octaves, creating a feedback loop (or
+ /// that's what it looks like after reading the code.)
+ ///
+ /// This noise module outputs ridged-multifractal-noise values that
+ /// usually range from -1.0 to +1.0, but there are no guarantees that all
+ /// output values will exist within that range.
+ ///
+ /// @note For ridged-multifractal noise generated with only one octave,
+ /// the output value ranges from -1.0 to 0.0.
+ ///
+ /// Ridged-multifractal noise is often used to generate craggy mountainous
+ /// terrain or marble-like textures.
+ ///
+ /// This noise module does not require any source modules.
+ ///
+ /// <b>Octaves</b>
+ ///
+ /// The number of octaves control the <i>amount of detail</i> of the
+ /// ridged-multifractal noise. Adding more octaves increases the detail
+ /// of the ridged-multifractal noise, but with the drawback of increasing
+ /// the calculation time.
+ ///
+ /// An application may specify the number of octaves that generate
+ /// ridged-multifractal noise by calling the setOctaveCount() method.
+ ///
+ /// <b>Frequency</b>
+ ///
+ /// An application may specify the frequency of the first octave by
+ /// calling the setFrequency() method.
+ ///
+ /// <b>Lacunarity</b>
+ ///
+ /// The lacunarity specifies the frequency multipler between successive
+ /// octaves.
+ ///
+ /// The effect of modifying the lacunarity is subtle; you may need to play
+ /// with the lacunarity value to determine the effects. For best results,
+ /// set the lacunarity to a number between 1.5 and 3.5.
+ ///
+ /// <b>References &amp; Acknowledgments</b>
+ ///
+ /// <a href=http://www.texturingandmodeling.com/Musgrave.html>F.
+ /// Kenton "Doc Mojo" Musgrave's texturing page</a> - This page contains
+ /// links to source code that generates ridged-multfractal noise, among
+ /// other types of noise. The source file <a
+ /// href=http://www.texturingandmodeling.com/CODE/MUSGRAVE/CLOUD/fractal.c>
+ /// fractal.c</a> contains the code I used in my ridged-multifractal class
+ /// (see the @a RidgedMultifractal() function.) This code was written by F.
+ /// Kenton Musgrave, the person who created
+ /// <a href=http://www.pandromeda.com/>MojoWorld</a>. He is also one of
+ /// the authors in <i>Texturing and Modeling: A Procedural Approach</i>
+ /// (Morgan Kaufmann, 2002. ISBN 1-55860-848-6.)
+
+ /// Default frequency for the noise::module::RidgedMulti noise module.
+ static final double DEFAULT_RIDGED_FREQUENCY = 1.0;
+
+ /// Default lacunarity for the noise::module::RidgedMulti noise module.
+ static final double DEFAULT_RIDGED_LACUNARITY = 2.0;
+
+ /// Default number of octaves for the noise::module::RidgedMulti noise
+ /// module.
+ static final int DEFAULT_RIDGED_OCTAVE_COUNT = 6;
+
+ /// Default noise quality for the noise::module::RidgedMulti noise
+ /// module.
+ static final NoiseQuality DEFAULT_RIDGED_QUALITY = NoiseQuality.QUALITY_STD;
+
+ /// Default noise seed for the noise::module::RidgedMulti noise module.
+ static final int DEFAULT_RIDGED_SEED = 0;
+
+ /// Maximum number of octaves for the noise::module::RidgedMulti noise
+ /// module.
+ static final int RIDGED_MAX_OCTAVE = 30;
+
+ /// Frequency of the first octave.
+ double frequency;
+
+ /// Frequency multiplier between successive octaves.
+ double lacunarity;
+
+ /// Quality of the ridged-multifractal noise.
+ NoiseQuality noiseQuality;
+
+ /// Total number of octaves that generate the ridged-multifractal
+ /// noise.
+ int octaveCount;
+
+ /// Contains the spectral weights for each octave.
+ double [] spectralWeights = new double[RIDGED_MAX_OCTAVE];
+
+ /// Seed value used by the ridged-multfractal-noise function.
+ int seed;
+
+
+ public RidgedMulti ()
+ {
+ super(0);
+ frequency = DEFAULT_RIDGED_FREQUENCY;
+ lacunarity = DEFAULT_RIDGED_LACUNARITY;
+ noiseQuality = DEFAULT_RIDGED_QUALITY;
+ octaveCount = DEFAULT_RIDGED_OCTAVE_COUNT;
+ seed = DEFAULT_RIDGED_SEED;
+
+ calcSpectralWeights();
+ }
+
+ // Calculates the spectral weights for each octave.
+ public void calcSpectralWeights ()
+ {
+ // This exponent parameter should be user-defined; it may be exposed in a
+ // future version of libnoise.
+ double h = 1.0;
+
+ double frequency = 1.0;
+ for (int i = 0; i < RIDGED_MAX_OCTAVE; i++) {
+ // Compute weight for each frequency.
+ this.spectralWeights[i] = Math.pow (frequency, -h);
+ frequency *= lacunarity;
+ }
+ }
+
+ // Multifractal code originally written by F. Kenton "Doc Mojo" Musgrave,
+ // 1998. Modified by jas for use with libnoise.
+ public double getValue (double x, double y, double z)
+ {
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+
+ double signal = 0.0;
+ double value = 0.0;
+ double weight = 1.0;
+
+ // These parameters should be user-defined; they may be exposed in a
+ // future version of libnoiseforjava.
+ double offset = 1.0;
+ double gain = 2.0;
+
+ for (int curOctave = 0; curOctave < octaveCount; curOctave++)
+ {
+ // Make sure that these floating-point values have the same range as a 32-
+ // bit integer so that we can pass them to the coherent-noise functions.
+ double nx, ny, nz;
+ nx = NoiseGen.MakeInt32Range (x);
+ ny = NoiseGen.MakeInt32Range (y);
+ nz = NoiseGen.MakeInt32Range (z);
+
+ // Get the coherent-noise value.
+ int curSeed = (seed + curOctave) & 0x7fffffff;
+ signal = NoiseGen.GradientCoherentNoise3D (nx, ny, nz, curSeed, noiseQuality);
+
+ // Make the ridges.
+ signal = Math.abs (signal);
+ signal = offset - signal;
+
+ // Square the signal to increase the sharpness of the ridges.
+ signal *= signal;
+
+ // The weighting from the previous octave is applied to the signal.
+ // Larger values have higher weights, producing sharp points along the
+ // ridges.
+ signal *= weight;
+
+ // Weight successive contributions by the previous signal.
+ weight = signal * gain;
+ if (weight > 1.0)
+ weight = 1.0;
+ if (weight < 0.0)
+ weight = 0.0;
+
+
+ // Add the signal to the output value.
+ value += (signal * spectralWeights[curOctave]);
+
+ // Go to the next octave.
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ }
+
+ return (value * 1.25) - 1.0;
+ }
+
+ public double getFrequency ()
+ {
+ return frequency;
+ }
+
+ /// Returns the lacunarity of the ridged-multifractal noise.
+ ///
+ /// @returns The lacunarity of the ridged-multifractal noise.
+ ///
+ /// The lacunarity is the frequency multiplier between successive
+ /// octaves.
+ public double getLacunarity ()
+ {
+ return lacunarity;
+ }
+
+ /// Returns the quality of the ridged-multifractal noise.
+ ///
+ /// @returns The quality of the ridged-multifractal noise.
+ ///
+ /// See noise::NoiseQuality for definitions of the various
+ /// coherent-noise qualities.
+ public NoiseQuality getNoiseQuality ()
+ {
+ return noiseQuality;
+ }
+
+ /// Returns the number of octaves that generate the
+ /// ridged-multifractal noise.
+ ///
+ /// @returns The number of octaves that generate the
+ /// ridged-multifractal noise.
+ ///
+ /// The number of octaves controls the amount of detail in the
+ /// ridged-multifractal noise.
+ public int getOctaveCount ()
+ {
+ return octaveCount;
+ }
+
+ /// Returns the seed value used by the ridged-multifractal-noise
+ /// function.
+ ///
+ /// @returns The seed value.
+ public int getSeed ()
+ {
+ return seed;
+ }
+
+
+ /// Sets the frequency of the first octave.
+ ///
+ /// @param frequency The frequency of the first octave.
+ public void setFrequency (double frequency)
+ {
+ this.frequency = frequency;
+ }
+
+ /// Sets the lacunarity of the ridged-multifractal noise.
+ ///
+ /// @param lacunarity The lacunarity of the ridged-multifractal noise.
+ ///
+ /// The lacunarity is the frequency multiplier between successive
+ /// octaves.
+ ///
+ /// For best results, set the lacunarity to a number between 1.5 and
+ /// 3.5.
+ public void setLacunarity (double lacunarity)
+ {
+ this.lacunarity = lacunarity;
+ calcSpectralWeights ();
+ }
+
+ /// Sets the quality of the ridged-multifractal noise.
+ ///
+ /// @param noiseQuality The quality of the ridged-multifractal noise.
+ ///
+ /// See NoiseQuality for definitions of the various
+ /// coherent-noise qualities.
+ public void setNoiseQuality (NoiseQuality noiseQuality)
+ {
+ this.noiseQuality = noiseQuality;
+ }
+
+ /// Sets the number of octaves that generate the ridged-multifractal
+ /// noise.
+ ///
+ /// @param octaveCount The number of octaves that generate the
+ /// ridged-multifractal noise.
+ ///
+ /// @pre The number of octaves ranges from 1 to RIDGED_MAX_OCTAVE.
+ ///
+ /// @throw ExceptionInvalidParam An invalid parameter was
+ /// specified; see the preconditions for more information.
+ ///
+ /// The number of octaves controls the amount of detail in the
+ /// ridged-multifractal noise.
+ ///
+ /// The larger the number of octaves, the more time required to
+ /// calculate the ridged-multifractal-noise value.
+ public void setOctaveCount (int octaveCount) throws ExceptionInvalidParam
+ {
+ if (octaveCount > RIDGED_MAX_OCTAVE)
+ {
+ throw new ExceptionInvalidParam ("An invalid parameter was passed" +
+ " to a libnoise function or method.");
+ }
+
+ this.octaveCount = octaveCount;
+ }
+
+ /// Sets the seed value used by the ridged-multifractal-noise
+ /// function.
+ ///
+ /// @param seed The seed value.
+ public void setSeed (int seed)
+ {
+ this.seed = seed;
+ }
+
+ public double[] getSpectralWeights()
+ {
+ return spectralWeights;
+ }
+
+ public void setSpectralWeights(double[] spectralWeights)
+ {
+ this.spectralWeights = spectralWeights;
+ }
+
+}
diff --git a/src/libnoiseforjava/module/RotatePoint.java b/src/libnoiseforjava/module/RotatePoint.java
new file mode 100644
index 0000000..a1a57b5
--- /dev/null
+++ b/src/libnoiseforjava/module/RotatePoint.java
@@ -0,0 +1,216 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class RotatePoint extends ModuleBase
+{
+ /// Noise module that rotates the input value around the origin before
+ /// returning the output value from a source module.
+ ///
+ /// The getValue() method rotates the coordinates of the input value
+ /// around the origin before returning the output value from the source
+ /// module. To set the rotation angles, call the setAngles() method. To
+ /// set the rotation angle around the individual @a x, @a y, or @a z axes,
+ /// call the setXAngle(), setYAngle() or setZAngle() methods,
+ /// respectively.
+ ///
+ /// The coordinate system of the input value is assumed to be
+ /// "left-handed" (@a x increases to the right, @a y increases upward,
+ /// and @a z increases inward.)
+ ///
+ /// This noise module requires one source module.
+
+ /// Default @a x rotation angle for the RotatePoint noise
+ /// module.
+ static final double DEFAULT_ROTATE_X = 0.0;
+
+ /// Default @a y rotation angle for the RotatePoint noise
+ /// module.
+ static final double DEFAULT_ROTATE_Y = 0.0;
+
+ /// Default @a z rotation angle for the RotatePoint noise
+ /// module.
+ static final double DEFAULT_ROTATE_Z = 0.0;
+
+
+ /// An entry within the 3x3 rotation matrix used for rotating the
+ /// input value.
+ double x1Matrix;
+
+ /// An entry within the 3x3 rotation matrix used for rotating the
+ /// input value.
+ double x2Matrix;
+
+ /// An entry within the 3x3 rotation matrix used for rotating the
+ /// input value.
+ double x3Matrix;
+
+ /// @a x rotation angle applied to the input value, in degrees.
+ double xAngle;
+
+ /// An entry within the 3x3 rotation matrix used for rotating the
+ /// input value.
+ double y1Matrix;
+
+ /// An entry within the 3x3 rotation matrix used for rotating the
+ /// input value.
+ double y2Matrix;
+
+ /// An entry within the 3x3 rotation matrix used for rotating the
+ /// input value.
+ double y3Matrix;
+
+ /// @a y rotation angle applied to the input value, in degrees.
+ double yAngle;
+
+ /// An entry within the 3x3 rotation matrix used for rotating the
+ /// input value.
+ double z1Matrix;
+
+ /// An entry within the 3x3 rotation matrix used for rotating the
+ /// input value.
+ double z2Matrix;
+
+ /// An entry within the 3x3 rotation matrix used for rotating the
+ /// input value.
+ double z3Matrix;
+
+ /// @a z rotation angle applied to the input value, in degrees.
+ double zAngle;
+
+
+ public RotatePoint (ModuleBase sourceModule) throws ExceptionInvalidParam
+ {
+ super(1);
+ setSourceModule(0, sourceModule);
+ setAngles (DEFAULT_ROTATE_X, DEFAULT_ROTATE_Y, DEFAULT_ROTATE_Z);
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+
+ double nx = (x1Matrix * x) + (y1Matrix * y) + (z1Matrix * z);
+ double ny = (x2Matrix * x) + (y2Matrix * y) + (z2Matrix * z);
+ double nz = (x3Matrix * x) + (y3Matrix * y) + (z3Matrix * z);
+ return sourceModules[0].getValue (nx, ny, nz);
+ }
+
+ public void setAngles (double xAngle, double yAngle,
+ double zAngle)
+ {
+ double xCos, yCos, zCos, xSin, ySin, zSin;
+ xCos = Math.cos (Math.toRadians(xAngle));
+ yCos = Math.cos (Math.toRadians(yAngle));
+ zCos = Math.cos (Math.toRadians(zAngle));
+ xSin = Math.sin (Math.toRadians(xAngle));
+ ySin = Math.sin (Math.toRadians(yAngle));
+ zSin = Math.sin (Math.toRadians(zAngle));
+
+ x1Matrix = ySin * xSin * zSin + yCos * zCos;
+ y1Matrix = xCos * zSin;
+ z1Matrix = ySin * zCos - yCos * xSin * zSin;
+ x2Matrix = ySin * xSin * zCos - yCos * zSin;
+ y2Matrix = xCos * zCos;
+ z2Matrix = -yCos * xSin * zCos - ySin * zSin;
+ x3Matrix = -ySin * xCos;
+ y3Matrix = xSin;
+ z3Matrix = yCos * xCos;
+
+ this.xAngle = xAngle;
+ this.yAngle = yAngle;
+ this.zAngle = zAngle;
+ }
+
+ /// Returns the rotation angle around the @a x axis to apply to the
+ /// input value.
+ ///
+ /// @returns The rotation angle around the @a x axis, in degrees.
+ public double getXAngle ()
+ {
+ return xAngle;
+ }
+
+ /// Returns the rotation angle around the @a y axis to apply to the
+ /// input value.
+ ///
+ /// @returns The rotation angle around the @a y axis, in degrees.
+ public double getYAngle ()
+ {
+ return yAngle;
+ }
+
+ /// Returns the rotation angle around the @a z axis to apply to the
+ /// input value.
+ ///
+ /// @returns The rotation angle around the @a z axis, in degrees.
+ public double getZAngle ()
+ {
+ return zAngle;
+ }
+
+ /// Sets the rotation angle around the @a x axis to apply to the input
+ /// value.
+ ///
+ /// @param xAngle The rotation angle around the @a x axis, in degrees.
+ ///
+ /// The getValue() method rotates the coordinates of the input value
+ /// around the origin before returning the output value from the
+ /// source module.
+ public void setXAngle (double xAngle)
+ {
+ setAngles (xAngle, this.yAngle, this.zAngle);
+ }
+
+ /// Sets the rotation angle around the @a y axis to apply to the input
+ /// value.
+ ///
+ /// @param yAngle The rotation angle around the @a y axis, in degrees.
+ ///
+ /// The getValue() method rotates the coordinates of the input value
+ /// around the origin before returning the output value from the
+ /// source module.
+ public void SetYAngle (double yAngle)
+ {
+ setAngles (this.xAngle, yAngle, this.zAngle);
+ }
+
+ /// Sets the rotation angle around the @a z axis to apply to the input
+ /// value.
+ ///
+ /// @param zAngle The rotation angle around the @a z axis, in degrees.
+ ///
+ /// The getValue() method rotates the coordinates of the input value
+ /// around the origin before returning the output value from the
+ /// source module.
+ public void SetZAngle (double zAngle)
+ {
+ setAngles (this.xAngle, this.yAngle, zAngle);
+ }
+
+}
diff --git a/src/libnoiseforjava/module/ScaleBias.java b/src/libnoiseforjava/module/ScaleBias.java
new file mode 100644
index 0000000..66daea4
--- /dev/null
+++ b/src/libnoiseforjava/module/ScaleBias.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class ScaleBias extends ModuleBase
+{
+
+ /// Noise module that applies a scaling factor and a bias to the output
+ /// value from a source module.
+ ///
+ /// The getValue() method retrieves the output value from the source
+ /// module, multiplies it with a scaling factor, adds a bias to it, then
+ /// outputs the value.
+ ///
+ /// This noise module requires one source module.
+
+ /// Default bias for the ScaleBias noise module.
+ static final double DEFAULT_BIAS = 0.0;
+
+ /// Default scale for the ScaleBias noise module.
+ static final double DEFAULT_SCALE = 1.0;
+
+ /// Bias to apply to the scaled output value from the source module.
+ double bias;
+
+ /// Scaling factor to apply to the output value from the source
+ /// module.
+ double scale;
+
+
+ public ScaleBias (ModuleBase sourceModule) throws ExceptionInvalidParam
+ {
+ super(1);
+ setSourceModule(0, sourceModule);
+ bias = DEFAULT_BIAS;
+ scale = DEFAULT_SCALE;
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+
+ return sourceModules[0].getValue (x, y, z) * scale + bias;
+ }
+
+ /// Returns the bias to apply to the scaled output value from the
+ /// source module.
+ ///
+ /// @returns The bias to apply.
+ ///
+ /// The getValue() method retrieves the output value from the source
+ /// module, multiplies it with the scaling factor, adds the bias to
+ /// it, then outputs the value.
+ public double getBias ()
+ {
+ return bias;
+ }
+
+ /// Returns the scaling factor to apply to the output value from the
+ /// source module.
+ ///
+ /// @returns The scaling factor to apply.
+ ///
+ /// The getValue() method retrieves the output value from the source
+ /// module, multiplies it with the scaling factor, adds the bias to
+ /// it, then outputs the value.
+ public double getScale ()
+ {
+ return scale;
+ }
+
+
+ /// Sets the bias to apply to the scaled output value from the source
+ /// module.
+ ///
+ /// @param bias The bias to apply.
+ ///
+ /// The getValue() method retrieves the output value from the source
+ /// module, multiplies it with the scaling factor, adds the bias to
+ /// it, then outputs the value.
+ public void setBias (double bias)
+ {
+ this.bias = bias;
+ }
+
+ /// Sets the scaling factor to apply to the output value from the
+ /// source module.
+ ///
+ /// @param scale The scaling factor to apply.
+ ///
+ /// The getValue() method retrieves the output value from the source
+ /// module, multiplies it with the scaling factor, adds the bias to
+ /// it, then outputs the value.
+ public void setScale (double scale)
+ {
+ this.scale = scale;
+ }
+
+}
diff --git a/src/libnoiseforjava/module/ScalePoint.java b/src/libnoiseforjava/module/ScalePoint.java
new file mode 100644
index 0000000..f0c10ce
--- /dev/null
+++ b/src/libnoiseforjava/module/ScalePoint.java
@@ -0,0 +1,182 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class ScalePoint extends ModuleBase
+{
+
+ /// Noise module that scales the coordinates of the input value before
+ /// returning the output value from a source module.
+ ///
+ /// The getValue() method multiplies the ( @a x, @a y, @a z ) coordinates
+ /// of the input value with a scaling factor before returning the output
+ /// value from the source module. To set the scaling factor, call the
+ /// setScale() method. To set the scaling factor to apply to the
+ /// individual @a x, @a y, or @a z coordinates, call the setXScale(),
+ /// setYScale() or setZScale() methods, respectively.
+ ///
+ /// This noise module requires one source module.
+
+ // Default scaling factor applied to the @a x coordinate for the
+ /// ScalePoint noise module.
+ static final double DEFAULT_SCALE_POINT_X = 1.0;
+
+ /// Default scaling factor applied to the @a y coordinate for the
+ /// ScalePoint noise module.
+ static final double DEFAULT_SCALE_POINT_Y = 1.0;
+
+ /// Default scaling factor applied to the @a z coordinate for the
+ /// ScalePoint noise module.
+ static final double DEFAULT_SCALE_POINT_Z = 1.0;
+
+ /// Scaling factor applied to the @a x coordinate of the input value.
+ double xScale;
+
+ /// Scaling factor applied to the @a y coordinate of the input value.
+ double yScale;
+
+ /// Scaling factor applied to the @a z coordinate of the input value.
+ double zScale;
+
+
+ public ScalePoint (ModuleBase sourceModule) throws ExceptionInvalidParam
+ {
+ super(1);
+ setSourceModule(0, sourceModule);
+
+ xScale = DEFAULT_SCALE_POINT_X;
+ yScale = DEFAULT_SCALE_POINT_Y;
+ zScale = DEFAULT_SCALE_POINT_Z;
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+
+ return sourceModules[0].getValue (x * xScale, y * yScale,
+ z * zScale);
+ }
+
+ /// Returns the scaling factor applied to the @a x coordinate of the
+ /// input value.
+ ///
+ /// @returns The scaling factor applied to the @a x coordinate.
+ public double getXScale ()
+ {
+ return xScale;
+ }
+
+ /// Returns the scaling factor applied to the @a y coordinate of the
+ /// input value.
+ ///
+ /// @returns The scaling factor applied to the @a y coordinate.
+ public double getYScale ()
+ {
+ return yScale;
+ }
+
+ /// Returns the scaling factor applied to the @a z coordinate of the
+ /// input value.
+ ///
+ /// @returns The scaling factor applied to the @a z coordinate.
+ public double getZScale ()
+ {
+ return zScale;
+ }
+
+ /// Sets the scaling factor to apply to the input value.
+ ///
+ /// @param scale The scaling factor to apply.
+ ///
+ /// The getValue() method multiplies the ( @a x, @a y, @a z )
+ /// coordinates of the input value with a scaling factor before
+ /// returning the output value from the source module.
+ public void setScale (double scale)
+ {
+ this.xScale = scale;
+ this.yScale = scale;
+ this.zScale = scale;
+ }
+
+ /// Sets the scaling factor to apply to the ( @a x, @a y, @a z )
+ /// coordinates of the input value.
+ ///
+ /// @param xScale The scaling factor to apply to the @a x coordinate.
+ /// @param yScale The scaling factor to apply to the @a y coordinate.
+ /// @param zScale The scaling factor to apply to the @a z coordinate.
+ ///
+ /// The getValue() method multiplies the ( @a x, @a y, @a z )
+ /// coordinates of the input value with a scaling factor before
+ /// returning the output value from the source module.
+ public void setScale (double xScale, double yScale, double zScale)
+ {
+ this.xScale = xScale;
+ this.yScale = yScale;
+ this.zScale = zScale;
+ }
+
+ /// Sets the scaling factor to apply to the @a x coordinate of the
+ /// input value.
+ ///
+ /// @param xScale The scaling factor to apply to the @a x coordinate.
+ ///
+ /// The getValue() method multiplies the ( @a x, @a y, @a z )
+ /// coordinates of the input value with a scaling factor before
+ /// returning the output value from the source module.
+ public void setXScale (double xScale)
+ {
+ this.xScale = xScale;
+ }
+
+ /// Sets the scaling factor to apply to the @a y coordinate of the
+ /// input value.
+ ///
+ /// @param yScale The scaling factor to apply to the @a y coordinate.
+ ///
+ /// The getValue() method multiplies the ( @a x, @a y, @a z )
+ /// coordinates of the input value with a scaling factor before
+ /// returning the output value from the source module.
+ public void setYScale (double yScale)
+ {
+ this.yScale = yScale;
+ }
+
+ /// Sets the scaling factor to apply to the @a z coordinate of the
+ /// input value.
+ ///
+ /// @param zScale The scaling factor to apply to the @a z coordinate.
+ ///
+ /// The getValue() method multiplies the ( @a x, @a y, @a z )
+ /// coordinates of the input value with a scaling factor before
+ /// returning the output value from the source module.
+ public void setZScale (double zScale)
+ {
+ this.zScale = zScale;
+ }
+
+}
diff --git a/src/libnoiseforjava/module/Select.java b/src/libnoiseforjava/module/Select.java
new file mode 100644
index 0000000..d394aa3
--- /dev/null
+++ b/src/libnoiseforjava/module/Select.java
@@ -0,0 +1,300 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.Interp;
+import libnoiseforjava.exception.ExceptionInvalidParam;
+import libnoiseforjava.exception.ExceptionNoModule;
+
+public class Select extends ModuleBase
+{
+ /// Noise module that outputs the value selected from one of two source
+ /// modules chosen by the output value from a control module.
+ ///
+ /// Unlike most other noise modules, the index value assigned to a source
+ /// module determines its role in the selection operation:
+ /// - Source module 0 (upper left in the diagram) outputs a value.
+ /// - Source module 1 (lower left in the diagram) outputs a value.
+ /// - Source module 2 (bottom of the diagram) is known as the <i>control
+ /// module</i>. The control module determines the value to select. If
+ /// the output value from the control module is within a range of values
+ /// known as the <i>selection range</i>, this noise module outputs the
+ /// value from the source module with an index value of 1. Otherwise,
+ /// this noise module outputs the value from the source module with an
+ /// index value of 0.
+ ///
+ /// To specify the bounds of the selection range, call the setBounds()
+ /// method.
+ ///
+ /// An application can pass the control module to the setControlModule()
+ /// method instead of the setSourceModule() method. This may make the
+ /// application code easier to read.
+ ///
+ /// By default, there is an abrupt transition between the output values
+ /// from the two source modules at the selection-range boundary. To
+ /// smooth the transition, pass a non-zero value to the setEdgeFalloff()
+ /// method. Higher values result in a smoother transition.
+ ///
+ /// This noise module requires three source modules.
+
+ /// Default edge-falloff value for the Select noise module.
+ static final double DEFAULT_SELECT_EDGE_FALLOFF = 0.0;
+
+ /// Default lower bound of the selection range for the
+ /// Select noise module.
+ static final double DEFAULT_SELECT_LOWER_BOUND = -1.0;
+
+ /// Default upper bound of the selection range for the
+ /// Select noise module.
+ static final double DEFAULT_SELECT_UPPER_BOUND = 1.0;
+
+ /// Edge-falloff value.
+ double edgeFalloff;
+
+ /// Lower bound of the selection range.
+ double lowerBound;
+
+ /// Upper bound of the selection range.
+ double upperBound;
+
+
+ public Select (ModuleBase sourceModuleOne, ModuleBase sourceModuleTwo,
+ ModuleBase sourceModuleThree) throws ExceptionInvalidParam
+ {
+ super(3);
+ setSourceModule(0, sourceModuleOne);
+ setSourceModule(1, sourceModuleTwo);
+ setSourceModule(2, sourceModuleThree);
+
+ edgeFalloff = DEFAULT_SELECT_EDGE_FALLOFF;
+ lowerBound = DEFAULT_SELECT_LOWER_BOUND;
+ upperBound = DEFAULT_SELECT_UPPER_BOUND;
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+ assert (sourceModules[1] != null);
+ assert (sourceModules[2] != null);
+
+ double controlValue = sourceModules[2].getValue (x, y, z);
+ double alpha;
+
+ if (edgeFalloff > 0.0)
+ {
+ if (controlValue < (lowerBound - edgeFalloff))
+ // The output value from the control module is below the selector
+ // threshold; return the output value from the first source module.
+ return sourceModules[0].getValue (x, y, z);
+ else if (controlValue < (lowerBound + edgeFalloff))
+ {
+ // The output value from the control module is near the lower end of the
+ // selector threshold and within the smooth curve. Interpolate between
+ // the output values from the first and second source modules.
+ double lowerCurve = (lowerBound - edgeFalloff);
+ double upperCurve = (lowerBound + edgeFalloff);
+ alpha = Interp.SCurve3 (
+ (controlValue - lowerCurve) / (upperCurve - lowerCurve));
+ return Interp.linearInterp (sourceModules[0].getValue (x, y, z),
+ sourceModules[2].getValue (x, y, z),
+ alpha);
+ }
+ else if (controlValue < (upperBound - edgeFalloff))
+ // The output value from the control module is within the selector
+ // threshold; return the output value from the second source module.
+ return sourceModules[1].getValue (x, y, z);
+ else if (controlValue < (upperBound + edgeFalloff))
+ {
+ // The output value from the control module is near the upper end of the
+ // selector threshold and within the smooth curve. Interpolate between
+ // the output values from the first and second source modules.
+ double lowerCurve = (upperBound - edgeFalloff);
+ double upperCurve = (upperBound + edgeFalloff);
+ alpha = Interp.SCurve3 (
+ (controlValue - lowerCurve) / (upperCurve - lowerCurve));
+ return Interp.linearInterp (sourceModules[1].getValue (x, y, z),
+ sourceModules[0].getValue (x, y, z),
+ alpha);
+ }
+ else
+ // Output value from the control module is above the selector threshold;
+ // return the output value from the first source module.
+ return sourceModules[0].getValue (x, y, z);
+ }
+ else
+ {
+ if (controlValue < lowerBound || controlValue > upperBound)
+ return sourceModules[0].getValue (x, y, z);
+ else
+ return sourceModules[1].getValue (x, y, z);
+ }
+ }
+
+ /// Sets the lower and upper bounds of the selection range.
+ ///
+ /// @param lowerBound The lower bound.
+ /// @param upperBound The upper bound.
+ ///
+ /// @pre The lower bound must be less than or equal to the upper
+ /// bound.
+ public void setBounds (double lowerBound, double upperBound)
+ {
+ assert (lowerBound < upperBound);
+
+ this.lowerBound = lowerBound;
+ this.upperBound = upperBound;
+
+ // Make sure that the edge falloff curves do not overlap.
+ setEdgeFalloff (edgeFalloff);
+ }
+
+ /// Sets the falloff value at the edge transition.
+ ///
+ /// @param edgeFalloff The falloff value at the edge transition.
+ ///
+ /// The falloff value is the width of the edge transition at either
+ /// edge of the selection range.
+ ///
+ /// By default, there is an abrupt transition between the values from
+ /// the two source modules at the boundaries of the selection range.
+ ///
+ /// For example, if the selection range is 0.5 to 0.8, and the edge
+ /// falloff value is 0.1, then the getValue() method outputs:
+ /// - the output value from the source module with an index value of 0
+ /// if the output value from the control module is less than 0.4
+ /// ( = 0.5 - 0.1).
+ /// - a linear blend between the two output values from the two source
+ /// modules if the output value from the control module is between
+ /// 0.4 ( = 0.5 - 0.1) and 0.6 ( = 0.5 + 0.1).
+ /// - the output value from the source module with an index value of 1
+ /// if the output value from the control module is between 0.6
+ /// ( = 0.5 + 0.1) and 0.7 ( = 0.8 - 0.1).
+ /// - a linear blend between the output values from the two source
+ /// modules if the output value from the control module is between
+ /// 0.7 ( = 0.8 - 0.1 ) and 0.9 ( = 0.8 + 0.1).
+ /// - the output value from the source module with an index value of 0
+ /// if the output value from the control module is greater than 0.9
+ /// ( = 0.8 + 0.1).
+ public void setEdgeFalloff (double edgeFalloff)
+ {
+ // Make sure that the edge falloff curves do not overlap.
+ double boundSize = upperBound - lowerBound;
+ edgeFalloff = (edgeFalloff > boundSize / 2)? boundSize / 2: edgeFalloff;
+ }
+
+ /// Returns the control module.
+ ///
+ /// @returns A reference to the control module.
+ ///
+ /// @pre A control module has been added to this noise module via a
+ /// call to setSourceModule() or setControlModule().
+ ///
+ /// @throw ExceptionNoModule See the preconditions for more
+ /// information.
+ ///
+ /// The control module determines the output value to select. If the
+ /// output value from the control module is within a range of values
+ /// known as the <i>selection range</i>, the getValue() method outputs
+ /// the value from the source module with an index value of 1.
+ /// Otherwise, this method outputs the value from the source module
+ /// with an index value of 0.
+
+ // not sure this does what it says it does. Recheck original source
+ public ModuleBase getControlModule () throws ExceptionNoModule
+ {
+ if (sourceModules == null || sourceModules[2] == null) {
+ throw new ExceptionNoModule ("Could not retrieve a source module from a noise module.");
+ }
+ return (sourceModules[2]);
+ }
+
+ /// Returns the falloff value at the edge transition.
+ ///
+ /// @returns The falloff value at the edge transition.
+ ///
+ /// The falloff value is the width of the edge transition at either
+ /// edge of the selection range.
+ ///
+ /// By default, there is an abrupt transition between the output
+ /// values from the two source modules at the selection-range
+ /// boundary.
+ public double getEdgeFalloff ()
+ {
+ return edgeFalloff;
+ }
+
+ /// Returns the lower bound of the selection range.
+ ///
+ /// @returns The lower bound of the selection range.
+ ///
+ /// If the output value from the control module is within the
+ /// selection range, the getValue() method outputs the value from the
+ /// source module with an index value of 1. Otherwise, this method
+ /// outputs the value from the source module with an index value of 0.
+ public double getLowerBound ()
+ {
+ return lowerBound;
+ }
+
+ /// Returns the upper bound of the selection range.
+ ///
+ /// @returns The upper bound of the selection range.
+ ///
+ /// If the output value from the control module is within the
+ /// selection range, the getValue() method outputs the value from the
+ /// source module with an index value of 1. Otherwise, this method
+ /// outputs the value from the source module with an index value of 0.
+ public double getUpperBound ()
+ {
+ return upperBound;
+ }
+
+ /// Sets the control module.
+ ///
+ /// @param controlModule The control module.
+ ///
+ /// The control module determines the output value to select. If the
+ /// output value from the control module is within a range of values
+ /// known as the <i>selection range</i>, the getValue() method outputs
+ /// the value from the source module with an index value of 1.
+ /// Otherwise, this method outputs the value from the source module
+ /// with an index value of 0.
+ ///
+ /// This method assigns the control module an index value of 2.
+ /// Passing the control module to this method produces the same
+ /// results as passing the control module to the setSourceModule()
+ /// method while assigning that noise module an index value of 2.
+ ///
+ /// This control module must exist throughout the lifetime of this
+ /// noise module unless another control module replaces that control
+ /// module.
+ public void setControlModule (ModuleBase controlModule)
+ {
+ assert (sourceModules != null);
+ sourceModules[2] = controlModule;
+ }
+
+}
diff --git a/src/libnoiseforjava/module/Simplex.java b/src/libnoiseforjava/module/Simplex.java
new file mode 100644
index 0000000..82d58c6
--- /dev/null
+++ b/src/libnoiseforjava/module/Simplex.java
@@ -0,0 +1,395 @@
+package libnoiseforjava.module;
+
+/**
+ * Michael Nugent
+ * Date: 3/9/12
+ * Time: 6:12 PM
+ * URL: https://github.com/michaelnugent/libnoiseforjava
+ * Package: libnoiseforjava.module
+ */
+
+
+/*
+* A speed-improved simplex noise algorithm for 2D, 3D and 4D in Java.
+*
+* Based on example code by Stefan Gustavson ([email protected]).
+* Optimisations by Peter Eastman ([email protected]).
+* Better rank ordering method by Stefan Gustavson in 2012.
+*
+* This could be speeded up even further, but it's useful as it is.
+*
+* Version 2012-03-09
+*
+* This code was placed in the public domain by its original author,
+* Stefan Gustavson. You may use it as you see fit, but
+* attribution is appreciated.
+*
+* Modified by Michael Nugent ([email protected]) for the
+* libnoise framework 20120309
+* All libnoise expects 3d, but I've left the 2d and 4d functions in for
+* reference.
+*
+*/
+
+public class Simplex extends ModuleBase { // Simplex noise in 2D, 3D and 4D
+ private static Grad grad3[] = {new Grad(1,1,0),new Grad(-1,1,0),new Grad(1,-1,0),new Grad(-1,-1,0),
+ new Grad(1,0,1),new Grad(-1,0,1),new Grad(1,0,-1),new Grad(-1,0,-1),
+ new Grad(0,1,1),new Grad(0,-1,1),new Grad(0,1,-1),new Grad(0,-1,-1)};
+
+ private static Grad grad4[]= {new Grad(0,1,1,1),new Grad(0,1,1,-1),new Grad(0,1,-1,1),new Grad(0,1,-1,-1),
+ new Grad(0,-1,1,1),new Grad(0,-1,1,-1),new Grad(0,-1,-1,1),new Grad(0,-1,-1,-1),
+ new Grad(1,0,1,1),new Grad(1,0,1,-1),new Grad(1,0,-1,1),new Grad(1,0,-1,-1),
+ new Grad(-1,0,1,1),new Grad(-1,0,1,-1),new Grad(-1,0,-1,1),new Grad(-1,0,-1,-1),
+ new Grad(1,1,0,1),new Grad(1,1,0,-1),new Grad(1,-1,0,1),new Grad(1,-1,0,-1),
+ new Grad(-1,1,0,1),new Grad(-1,1,0,-1),new Grad(-1,-1,0,1),new Grad(-1,-1,0,-1),
+ new Grad(1,1,1,0),new Grad(1,1,-1,0),new Grad(1,-1,1,0),new Grad(1,-1,-1,0),
+ new Grad(-1,1,1,0),new Grad(-1,1,-1,0),new Grad(-1,-1,1,0),new Grad(-1,-1,-1,0)};
+
+ private static short p[] = {151,160,137,91,90,15,
+ 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
+ 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
+ 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,
+ 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
+ 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,
+ 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,
+ 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,
+ 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,
+ 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,
+ 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,
+ 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
+ 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180};
+ // To remove the need for index wrapping, double the permutation table length
+ private short perm[] = new short[512];
+ private short permMod12[] = new short[512];
+
+ private double seed = 0;
+
+ public Simplex() {
+ super(0);
+ for(int i=0; i<512; i++) {
+ perm[i]=p[i & 255];
+ permMod12[i] = (short)(perm[i] % 12);
+ }
+ }
+
+ public double getSeed() {
+ return seed;
+ }
+
+ public void setSeed(double seed) {
+ this.seed = seed;
+ }
+
+ public void setSeed(int seed) {
+ this.seed = (double)seed;
+ }
+
+ // Skewing and unskewing factors for 2, 3, and 4 dimensions
+ private static final double F2 = 0.5*(Math.sqrt(3.0)-1.0);
+ private static final double G2 = (3.0-Math.sqrt(3.0))/6.0;
+ private static final double F3 = 1.0/3.0;
+ private static final double G3 = 1.0/6.0;
+ private static final double F4 = (Math.sqrt(5.0)-1.0)/4.0;
+ private static final double G4 = (5.0-Math.sqrt(5.0))/20.0;
+
+ // This method is a *lot* faster than using (int)Math.floor(x)
+ private static int fastfloor(double x) {
+ int xi = (int)x;
+ return x<xi ? xi-1 : xi;
+ }
+
+ private static double dot(Grad g, double x, double y) {
+ return g.x*x + g.y*y;
+ }
+
+ private static double dot(Grad g, double x, double y, double z) {
+ return g.x*x + g.y*y + g.z*z;
+ }
+
+ private static double dot(Grad g, double x, double y, double z, double w) {
+ return g.x*x + g.y*y + g.z*z + g.w*w;
+ }
+
+
+ // 2D simplex noise
+ public double getValue2d(double xin, double yin) {
+ double n0, n1, n2; // Noise contributions from the three corners
+ // Skew the input space to determine which simplex cell we're in
+ double s = (xin+yin)*F2; // Hairy factor for 2D
+ int i = fastfloor(xin+s);
+ int j = fastfloor(yin+s);
+ double t = (i+j)*G2;
+ double X0 = i-t; // Unskew the cell origin back to (x,y) space
+ double Y0 = j-t;
+ double x0 = xin-X0; // The x,y distances from the cell origin
+ double y0 = yin-Y0;
+ // For the 2D case, the simplex shape is an equilateral triangle.
+ // Determine which simplex we are in.
+ int i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords
+ if(x0>y0) {i1=1; j1=0;} // lower triangle, XY order: (0,0)->(1,0)->(1,1)
+ else {i1=0; j1=1;} // upper triangle, YX order: (0,0)->(0,1)->(1,1)
+ // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
+ // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
+ // c = (3-sqrt(3))/6
+ double x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords
+ double y1 = y0 - j1 + G2;
+ double x2 = x0 - 1.0 + 2.0 * G2; // Offsets for last corner in (x,y) unskewed coords
+ double y2 = y0 - 1.0 + 2.0 * G2;
+ // Work out the hashed gradient indices of the three simplex corners
+ int ii = i & 255;
+ int jj = j & 255;
+
+ int gi0 = permMod12[ii+perm[jj]];
+ int gi1 = permMod12[ii+i1+perm[jj+j1]];
+ int gi2 = permMod12[ii+1+perm[jj+1]];
+ // Calculate the contribution from the three corners
+ double t0 = 0.5 - x0*x0-y0*y0;
+ if(t0<0) n0 = 0.0;
+ else {
+ t0 *= t0;
+ n0 = t0 * t0 * dot(grad3[gi0], x0, y0); // (x,y) of grad3 used for 2D gradient
+ }
+ double t1 = 0.5 - x1*x1-y1*y1;
+ if(t1<0) n1 = 0.0;
+ else {
+ t1 *= t1;
+ n1 = t1 * t1 * dot(grad3[gi1], x1, y1);
+ }
+ double t2 = 0.5 - x2*x2-y2*y2;
+ if(t2<0) n2 = 0.0;
+ else {
+ t2 *= t2;
+ n2 = t2 * t2 * dot(grad3[gi2], x2, y2);
+ }
+ // Add contributions from each corner to get the final noise value.
+ // The result is scaled to return values in the interval [-1,1].
+ return 70.0 * (n0 + n1 + n2);
+ }
+
+
+ // 3D simplex noise
+ public double getValue(double xin, double yin, double zin) {
+ double n0, n1, n2, n3; // Noise contributions from the four corners
+ // Skew the input space to determine which simplex cell we're in
+ xin+=(seed + (seed * 7)) % Double.MAX_VALUE;
+ xin+=(seed + (seed * 13)) % Double.MAX_VALUE;
+ xin+=(seed + (seed * 17)) % Double.MAX_VALUE;
+ double s = (xin+yin+zin)*F3; // Very nice and simple skew factor for 3D
+ int i = fastfloor(xin+s);
+ int j = fastfloor(yin+s);
+ int k = fastfloor(zin+s);
+ double t = (i+j+k)*G3;
+ double X0 = i-t; // Unskew the cell origin back to (x,y,z) space
+ double Y0 = j-t;
+ double Z0 = k-t;
+ double x0 = xin-X0; // The x,y,z distances from the cell origin
+ double y0 = yin-Y0;
+ double z0 = zin-Z0;
+ // For the 3D case, the simplex shape is a slightly irregular tetrahedron.
+ // Determine which simplex we are in.
+ int i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords
+ int i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords
+ if(x0>=y0) {
+ if(y0>=z0)
+ { i1=1; j1=0; k1=0; i2=1; j2=1; k2=0; } // X Y Z order
+ else if(x0>=z0) { i1=1; j1=0; k1=0; i2=1; j2=0; k2=1; } // X Z Y order
+ else { i1=0; j1=0; k1=1; i2=1; j2=0; k2=1; } // Z X Y order
+ }
+ else { // x0<y0
+ if(y0<z0) { i1=0; j1=0; k1=1; i2=0; j2=1; k2=1; } // Z Y X order
+ else if(x0<z0) { i1=0; j1=1; k1=0; i2=0; j2=1; k2=1; } // Y Z X order
+ else { i1=0; j1=1; k1=0; i2=1; j2=1; k2=0; } // Y X Z order
+ }
+ // A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),
+ // a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
+ // a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
+ // c = 1/6.
+ double x1 = x0 - i1 + G3; // Offsets for second corner in (x,y,z) coords
+ double y1 = y0 - j1 + G3;
+ double z1 = z0 - k1 + G3;
+ double x2 = x0 - i2 + 2.0*G3; // Offsets for third corner in (x,y,z) coords
+ double y2 = y0 - j2 + 2.0*G3;
+ double z2 = z0 - k2 + 2.0*G3;
+ double x3 = x0 - 1.0 + 3.0*G3; // Offsets for last corner in (x,y,z) coords
+ double y3 = y0 - 1.0 + 3.0*G3;
+ double z3 = z0 - 1.0 + 3.0*G3;
+ // Work out the hashed gradient indices of the four simplex corners
+ int ii = i & 255;
+ int jj = j & 255;
+ int kk = k & 255;
+
+ int gi0 = permMod12[ii+perm[jj+perm[kk]]];
+ int gi1 = permMod12[ii+i1+perm[jj+j1+perm[kk+k1]]];
+ int gi2 = permMod12[ii+i2+perm[jj+j2+perm[kk+k2]]];
+ int gi3 = permMod12[ii+1+perm[jj+1+perm[kk+1]]];
+ // Calculate the contribution from the four corners
+ double t0 = 0.6 - x0*x0 - y0*y0 - z0*z0;
+ if(t0<0) n0 = 0.0;
+ else {
+ t0 *= t0;
+ n0 = t0 * t0 * dot(grad3[gi0], x0, y0, z0);
+ }
+ double t1 = 0.6 - x1*x1 - y1*y1 - z1*z1;
+ if(t1<0) n1 = 0.0;
+ else {
+ t1 *= t1;
+ n1 = t1 * t1 * dot(grad3[gi1], x1, y1, z1);
+ }
+ double t2 = 0.6 - x2*x2 - y2*y2 - z2*z2;
+ if(t2<0) n2 = 0.0;
+ else {
+ t2 *= t2;
+ n2 = t2 * t2 * dot(grad3[gi2], x2, y2, z2);
+ }
+ double t3 = 0.6 - x3*x3 - y3*y3 - z3*z3;
+ if(t3<0) n3 = 0.0;
+ else {
+ t3 *= t3;
+ n3 = t3 * t3 * dot(grad3[gi3], x3, y3, z3);
+ }
+ // Add contributions from each corner to get the final noise value.
+ // The result is scaled to stay just inside [-1,1]
+ return 32.0*(n0 + n1 + n2 + n3);
+ }
+
+
+ // 4D simplex noise, better simplex rank ordering method 2012-03-09
+ public double getValue4d(double x, double y, double z, double w) {
+
+ double n0, n1, n2, n3, n4; // Noise contributions from the five corners
+ // Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in
+ double s = (x + y + z + w) * F4; // Factor for 4D skewing
+ int i = fastfloor(x + s);
+ int j = fastfloor(y + s);
+ int k = fastfloor(z + s);
+ int l = fastfloor(w + s);
+ double t = (i + j + k + l) * G4; // Factor for 4D unskewing
+ double X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space
+ double Y0 = j - t;
+ double Z0 = k - t;
+ double W0 = l - t;
+ double x0 = x - X0; // The x,y,z,w distances from the cell origin
+ double y0 = y - Y0;
+ double z0 = z - Z0;
+ double w0 = w - W0;
+ // For the 4D case, the simplex is a 4D shape I won't even try to describe.
+ // To find out which of the 24 possible simplices we're in, we need to
+ // determine the magnitude ordering of x0, y0, z0 and w0.
+ // Six pair-wise comparisons are performed between each possible pair
+ // of the four coordinates, and the results are used to rank the numbers.
+ int rankx = 0;
+ int ranky = 0;
+ int rankz = 0;
+ int rankw = 0;
+ if(x0 > y0) rankx++; else ranky++;
+ if(x0 > z0) rankx++; else rankz++;
+ if(x0 > w0) rankx++; else rankw++;
+ if(y0 > z0) ranky++; else rankz++;
+ if(y0 > w0) ranky++; else rankw++;
+ if(z0 > w0) rankz++; else rankw++;
+ int i1, j1, k1, l1; // The integer offsets for the second simplex corner
+ int i2, j2, k2, l2; // The integer offsets for the third simplex corner
+ int i3, j3, k3, l3; // The integer offsets for the fourth simplex corner
+ // simplex[c] is a 4-vector with the numbers 0, 1, 2 and 3 in some order.
+ // Many values of c will never occur, since e.g. x>y>z>w makes x<z, y<w and x<w
+ // impossible. Only the 24 indices which have non-zero entries make any sense.
+ // We use a thresholding to set the coordinates in turn from the largest magnitude.
+ // Rank 3 denotes the largest coordinate.
+ i1 = rankx >= 3 ? 1 : 0;
+ j1 = ranky >= 3 ? 1 : 0;
+ k1 = rankz >= 3 ? 1 : 0;
+ l1 = rankw >= 3 ? 1 : 0;
+ // Rank 2 denotes the second largest coordinate.
+ i2 = rankx >= 2 ? 1 : 0;
+ j2 = ranky >= 2 ? 1 : 0;
+ k2 = rankz >= 2 ? 1 : 0;
+ l2 = rankw >= 2 ? 1 : 0;
+ // Rank 1 denotes the second smallest coordinate.
+ i3 = rankx >= 1 ? 1 : 0;
+ j3 = ranky >= 1 ? 1 : 0;
+ k3 = rankz >= 1 ? 1 : 0;
+ l3 = rankw >= 1 ? 1 : 0;
+ // The fifth corner has all coordinate offsets = 1, so no need to compute that.
+ double x1 = x0 - i1 + G4; // Offsets for second corner in (x,y,z,w) coords
+ double y1 = y0 - j1 + G4;
+ double z1 = z0 - k1 + G4;
+ double w1 = w0 - l1 + G4;
+ double x2 = x0 - i2 + 2.0*G4; // Offsets for third corner in (x,y,z,w) coords
+ double y2 = y0 - j2 + 2.0*G4;
+ double z2 = z0 - k2 + 2.0*G4;
+ double w2 = w0 - l2 + 2.0*G4;
+ double x3 = x0 - i3 + 3.0*G4; // Offsets for fourth corner in (x,y,z,w) coords
+ double y3 = y0 - j3 + 3.0*G4;
+ double z3 = z0 - k3 + 3.0*G4;
+ double w3 = w0 - l3 + 3.0*G4;
+ double x4 = x0 - 1.0 + 4.0*G4; // Offsets for last corner in (x,y,z,w) coords
+ double y4 = y0 - 1.0 + 4.0*G4;
+ double z4 = z0 - 1.0 + 4.0*G4;
+ double w4 = w0 - 1.0 + 4.0*G4;
+ // Work out the hashed gradient indices of the five simplex corners
+ int ii = i & 255;
+ int jj = j & 255;
+ int kk = k & 255;
+ int ll = l & 255;
+ int gi0 = perm[ii+perm[jj+perm[kk+perm[ll]]]] % 32;
+ int gi1 = perm[ii+i1+perm[jj+j1+perm[kk+k1+perm[ll+l1]]]] % 32;
+ int gi2 = perm[ii+i2+perm[jj+j2+perm[kk+k2+perm[ll+l2]]]] % 32;
+ int gi3 = perm[ii+i3+perm[jj+j3+perm[kk+k3+perm[ll+l3]]]] % 32;
+ int gi4 = perm[ii+1+perm[jj+1+perm[kk+1+perm[ll+1]]]] % 32;
+ // Calculate the contribution from the five corners
+ double t0 = 0.6 - x0*x0 - y0*y0 - z0*z0 - w0*w0;
+ if(t0<0) n0 = 0.0;
+ else {
+ t0 *= t0;
+ n0 = t0 * t0 * dot(grad4[gi0], x0, y0, z0, w0);
+ }
+ double t1 = 0.6 - x1*x1 - y1*y1 - z1*z1 - w1*w1;
+ if(t1<0) n1 = 0.0;
+ else {
+ t1 *= t1;
+ n1 = t1 * t1 * dot(grad4[gi1], x1, y1, z1, w1);
+ }
+ double t2 = 0.6 - x2*x2 - y2*y2 - z2*z2 - w2*w2;
+ if(t2<0) n2 = 0.0;
+ else {
+ t2 *= t2;
+ n2 = t2 * t2 * dot(grad4[gi2], x2, y2, z2, w2);
+ }
+ double t3 = 0.6 - x3*x3 - y3*y3 - z3*z3 - w3*w3;
+ if(t3<0) n3 = 0.0;
+ else {
+ t3 *= t3;
+ n3 = t3 * t3 * dot(grad4[gi3], x3, y3, z3, w3);
+ }
+ double t4 = 0.6 - x4*x4 - y4*y4 - z4*z4 - w4*w4;
+ if(t4<0) n4 = 0.0;
+ else {
+ t4 *= t4;
+ n4 = t4 * t4 * dot(grad4[gi4], x4, y4, z4, w4);
+ }
+ // Sum up and scale the result to cover the range [-1,1]
+ return 27.0 * (n0 + n1 + n2 + n3 + n4);
+ }
+
+ // Inner class to speed upp gradient computations
+ // (array access is a lot slower than member access)
+ private static class Grad
+ {
+ double x, y, z, w;
+
+ Grad(double x, double y, double z)
+ {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ }
+
+ Grad(double x, double y, double z, double w)
+ {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ this.w = w;
+ }
+ }
+}
diff --git a/src/libnoiseforjava/module/Spheres.java b/src/libnoiseforjava/module/Spheres.java
new file mode 100644
index 0000000..03b580f
--- /dev/null
+++ b/src/libnoiseforjava/module/Spheres.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+public class Spheres extends ModuleBase
+{
+
+ /// Noise module that outputs concentric spheres.
+ ///
+ /// This noise module outputs concentric spheres centered on the origin
+ /// like the concentric rings of an onion.
+ ///
+ /// The first sphere has a radius of 1.0. Each subsequent sphere has a
+ /// radius that is 1.0 unit larger than the previous sphere.
+ ///
+ /// The output value from this noise module is determined by the distance
+ /// between the input value and the the nearest spherical surface. The
+ /// input values that are located on a spherical surface are given the
+ /// output value 1.0 and the input values that are equidistant from two
+ /// spherical surfaces are given the output value -1.0.
+ ///
+ /// An application can change the frequency of the concentric spheres.
+ /// Increasing the frequency reduces the distances between spheres. To
+ /// specify the frequency, call the setFrequency() method.
+ ///
+ /// This noise module, modified with some low-frequency, low-power
+ /// turbulence, is useful for generating agate-like textures.
+ ///
+ /// This noise module does not require any source modules.
+
+ /// Default frequency value for the Spheres noise module.
+ static final double DEFAULT_SPHERES_FREQUENCY = 1.0;
+
+ /// Frequency of the concentric spheres.
+ double frequency;
+
+
+ public Spheres ()
+ {
+ super(0);
+ frequency = DEFAULT_SPHERES_FREQUENCY;
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+
+ double distFromCenter = Math.sqrt (x * x + y * y + z * z);
+ double distFromSmallerSphere = distFromCenter - Math.floor (distFromCenter);
+ double distFromLargerSphere = 1.0 - distFromSmallerSphere;
+ double nearestDist = Math.min(distFromSmallerSphere, distFromLargerSphere);
+ return 1.0 - (nearestDist * 4.0); // Puts it in the -1.0 to +1.0 range.
+ }
+
+ /// Returns the frequency of the concentric spheres.
+ ///
+ /// @returns The frequency of the concentric spheres.
+ ///
+ /// Increasing the frequency increases the density of the concentric
+ /// spheres, reducing the distances between them.
+ public double getFrequency ()
+ {
+ return frequency;
+ }
+
+ /// Sets the frequency of the concentric spheres.
+ ///
+ /// @param frequency The frequency of the concentric spheres.
+ ///
+ /// Increasing the frequency increases the density of the concentric
+ /// spheres, reducing the distances between them.
+ public void setFrequency (double frequency)
+ {
+ this.frequency = frequency;
+ }
+
+}
diff --git a/src/libnoiseforjava/module/Terrace.java b/src/libnoiseforjava/module/Terrace.java
new file mode 100644
index 0000000..2c22733
--- /dev/null
+++ b/src/libnoiseforjava/module/Terrace.java
@@ -0,0 +1,326 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.Interp;
+import libnoiseforjava.Misc;
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class Terrace extends ModuleBase
+{
+
+ /// Noise module that maps the output value from a source module onto a
+ /// terrace-forming curve.
+ ///
+ /// This noise module maps the output value from the source module onto a
+ /// terrace-forming curve. The start of this curve has a slope of zero;
+ /// its slope then smoothly increases. This curve also contains
+ /// <i>control points</i> which resets the slope to zero at that point,
+ /// producing a "terracing" effect. Refer to the following illustration:
+ ///
+ /// @image html terrace.png
+ ///
+ /// To add a control point to this noise module, call the
+ /// addControlPoint() method.
+ ///
+ /// An application must add a minimum of two control points to the curve.
+ /// If this is not done, the getValue() method fails. The control points
+ /// can have any value, although no two control points can have the same
+ /// value. There is no limit to the number of control points that can be
+ /// added to the curve.
+ ///
+ /// This noise module clamps the output value from the source module if
+ /// that value is less than the value of the lowest control point or
+ /// greater than the value of the highest control point.
+ ///
+ /// This noise module is often used to generate terrain features such as
+ /// your stereotypical desert canyon.
+ ///
+ /// This noise module requires one source module.
+
+
+ /// Number of control points stored in this noise module.
+ int controlPointCount;
+
+ /// Determines if the terrace-forming curve between all control points
+ /// is inverted.
+ boolean invertTerraces;
+
+ /// Array that stores the control points.
+ double [] controlPoints;
+
+
+ public Terrace (ModuleBase sourceModule) throws ExceptionInvalidParam
+ {
+ super(1);
+ setSourceModule(0, sourceModule);
+ controlPointCount = 0;
+ invertTerraces = false;
+ controlPoints = new double [0];
+
+ }
+
+ /// Adds a control point to the terrace-forming curve.
+ ///
+ /// @param value The value of the control point to add.
+ ///
+ /// @pre No two control points have the same value.
+ ///
+ /// @throw ExceptionInvalidParam An invalid parameter was
+ /// specified; see the preconditions for more information.
+ ///
+ /// Two or more control points define the terrace-forming curve. The
+ /// start of this curve has a slope of zero; its slope then smoothly
+ /// increases. At the control points, its slope resets to zero.
+ ///
+ /// It does not matter which order these points are added.
+ public void addControlPoint (double value) throws ExceptionInvalidParam
+ {
+ // Find the insertion point for the new control point and insert the new
+ // point at that position. The control point array will remain sorted by
+ // value.
+ int insertionPos = findInsertionPos (value);
+ insertAtPos (insertionPos, value);
+ }
+
+
+ /// Deletes all the control points on the terrace-forming curve.
+ ///
+ /// @post All control points on the terrace-forming curve are deleted.
+ public void clearAllControlPoints ()
+ {
+ controlPoints = null;
+ controlPointCount = 0;
+ }
+
+ /// Determines the array index in which to insert the control point
+ /// into the internal control point array.
+ ///
+ /// @param value The value of the control point.
+ ///
+ /// @returns The array index in which to insert the control point.
+ ///
+ /// @pre No two control points have the same value.
+ ///
+ /// @throw ExceptionInvalidParam An invalid parameter was
+ /// specified; see the preconditions for more information.
+ ///
+ /// By inserting the control point at the returned array index, this
+ /// class ensures that the control point array is sorted by value.
+ /// The code that maps a value onto the curve requires a sorted
+ /// control point array.
+ public int findInsertionPos (double value) throws ExceptionInvalidParam
+ {
+ int insertionPos;
+ for (insertionPos = 0; insertionPos < controlPointCount; insertionPos++)
+ {
+ if (value < controlPoints[insertionPos])
+ // We found the array index in which to insert the new control point.
+ // Exit now.
+ break;
+ else if (value == controlPoints[insertionPos])
+ // Each control point is required to contain a unique value, so throw
+ // an exception.
+ throw new ExceptionInvalidParam ("Invalid Parameter in Terrace Noise Moduled");
+ }
+ return insertionPos;
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+ assert (controlPointCount >= 2);
+
+ // Get the output value from the source module.
+ double sourceModuleValue = sourceModules[0].getValue (x, y, z);
+
+ // Find the first element in the control point array that has a value
+ // larger than the output value from the source module.
+ int indexPos;
+ for (indexPos = 0; indexPos < controlPointCount; indexPos++)
+ {
+ if (sourceModuleValue < controlPoints[indexPos])
+ break;
+
+ }
+
+ // Find the two nearest control points so that we can map their values
+ // onto a quadratic curve.
+ int index0 = Misc.ClampValue (indexPos - 1, 0, controlPointCount - 1);
+ int index1 = Misc.ClampValue (indexPos, 0, controlPointCount - 1);
+
+ // If some control points are missing (which occurs if the output value from
+ // the source module is greater than the largest value or less than the
+ // smallest value of the control point array), get the value of the nearest
+ // control point and exit now.
+ if (index0 == index1)
+ return controlPoints[index1];
+
+ // Compute the alpha value used for linear interpolation.
+ double value0 = controlPoints[index0];
+ double value1 = controlPoints[index1];
+ double alpha = (sourceModuleValue - value0) / (value1 - value0);
+ if (invertTerraces)
+ {
+ alpha = 1.0 - alpha;
+ double tempValue = value0;
+ value0 = value1;
+ value1 = tempValue;
+ }
+
+ // Squaring the alpha produces the terrace effect.
+ alpha *= alpha;
+
+ // Now perform the linear interpolation given the alpha value.
+ return Interp.linearInterp (value0, value1, alpha);
+ }
+
+ /// Inserts the control point at the specified position in the
+ /// internal control point array.
+ ///
+ /// @param insertionPos The zero-based array position in which to
+ /// insert the control point.
+ /// @param value The value of the control point.
+ ///
+ /// To make room for this new control point, this method reallocates
+ /// the control point array and shifts all control points occurring
+ /// after the insertion position up by one.
+ ///
+ /// Because the curve mapping algorithm in this noise module requires
+ /// that all control points in the array be sorted by value, the new
+ /// control point should be inserted at the position in which the
+ /// order is still preserved.
+ public void insertAtPos (int insertionPos, double value)
+ {
+ // Make room for the new control point at the specified position within
+ // the control point array. The position is determined by the value of
+ // the control point; the control points must be sorted by value within
+ // that array.
+ double[] newControlPoints = new double[controlPointCount + 1];
+
+ for (int i = 0; i < controlPointCount; i++)
+ {
+ if (i < insertionPos)
+ newControlPoints[i] = controlPoints[i];
+ else
+ newControlPoints[i + 1] = controlPoints[i];
+ }
+
+ controlPoints = newControlPoints;
+ ++controlPointCount;
+
+ // Now that we've made room for the new control point within the array,
+ // add the new control point.
+ controlPoints[insertionPos] = value;
+ }
+
+ /// Creates a number of equally-spaced control points that range from
+ /// -1 to +1.
+ ///
+ /// @param controlPointCount The number of control points to generate.
+ ///
+ /// @pre The number of control points must be greater than or equal to
+ /// 2.
+ ///
+ /// @post The previous control points on the terrace-forming curve are
+ /// deleted.
+ ///
+ /// @throw ExceptionInvalidParam An invalid parameter was
+ /// specified; see the preconditions for more information.
+ ///
+ /// Two or more control points define the terrace-forming curve. The
+ /// start of this curve has a slope of zero; its slope then smoothly
+ /// increases. At the control points, its slope resets to zero.
+ void makeControlPoints (int controlPointCount) throws ExceptionInvalidParam
+ {
+ if (controlPointCount < 2)
+ throw new ExceptionInvalidParam ("Invalid Parameter in Terrace Noise Module");
+
+ clearAllControlPoints ();
+
+ double terraceStep = 2.0 / ((double)controlPointCount - 1.0);
+ double curValue = -1.0;
+ for (int i = 0; i < (int)controlPointCount; i++)
+ {
+ addControlPoint (curValue);
+ curValue += terraceStep;
+ }
+ }
+
+ /// Returns a pointer to the array of control points on the
+ /// terrace-forming curve.
+ ///
+ /// @returns A pointer to the array of control points in this noise
+ /// module.
+ ///
+ /// Two or more control points define the terrace-forming curve. The
+ /// start of this curve has a slope of zero; its slope then smoothly
+ /// increases. At the control points, its slope resets to zero.
+ ///
+ /// Before calling this method, call getControlPointCount() to
+ /// determine the number of control points in this array.
+ ///
+ /// It is recommended that an application does not store this pointer
+ /// for later use since the pointer to the array may change if the
+ /// application calls another method of this object.
+ public double[] getControlPointArray ()
+ {
+ return controlPoints;
+ }
+
+ /// Returns the number of control points on the terrace-forming curve.
+ ///
+ /// @returns The number of control points on the terrace-forming
+ /// curve.
+ public int getControlPointCount ()
+ {
+ return controlPointCount;
+ }
+
+ /// Enables or disables the inversion of the terrace-forming curve
+ /// between the control points.
+ ///
+ /// @param invert Specifies whether to invert the curve between the
+ /// control points.
+ public void invertTerraces (boolean invert)
+ {
+ if (invert)
+ invertTerraces = invert;
+ }
+
+ /// Determines if the terrace-forming curve between the control
+ /// points is inverted.
+ ///
+ /// @returns
+ /// - @a true if the curve between the control points is inverted.
+ /// - @a false if the curve between the control points is not
+ /// inverted.
+ public boolean isTerracesInverted ()
+ {
+ return invertTerraces;
+ }
+
+}
diff --git a/src/libnoiseforjava/module/TranslatePoint.java b/src/libnoiseforjava/module/TranslatePoint.java
new file mode 100644
index 0000000..23ed712
--- /dev/null
+++ b/src/libnoiseforjava/module/TranslatePoint.java
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class TranslatePoint extends ModuleBase
+{
+ /// Noise module that moves the coordinates of the input value before
+ /// returning the output value from a source module.
+ ///
+ /// The getValue() method moves the ( @a x, @a y, @a z ) coordinates of
+ /// the input value by a translation amount before returning the output
+ /// value from the source module. To set the translation amount, call
+ /// the setTranslation() method. To set the translation amount to
+ /// apply to the individual @a x, @a y, or @a z coordinates, call the
+ /// setXTranslation(), setYTranslation() or setZTranslation() methods,
+ /// respectively.
+ ///
+ /// This noise module requires one source module.
+
+
+ /// Default translation factor applied to the @a x coordinate for the
+ /// TranslatePoint noise module.
+ static final double DEFAULT_TRANSLATE_POINT_X = 0.0;
+
+ /// Default translation factor applied to the @a y coordinate for the
+ /// TranslatePoint noise module.
+ static final double DEFAULT_TRANSLATE_POINT_Y = 0.0;
+
+ /// Default translation factor applied to the @a z coordinate for the
+ /// TranslatePoint noise module.
+ static final double DEFAULT_TRANSLATE_POINT_Z = 0.0;
+
+ /// Translation amount applied to the @a x coordinate of the input
+ /// value.
+ double xTranslation;
+
+ /// Translation amount applied to the @a y coordinate of the input
+ /// value.
+ double yTranslation;
+
+ /// Translation amount applied to the @a z coordinate of the input
+ /// value.
+ double zTranslation;
+
+ public TranslatePoint (ModuleBase sourceModule) throws ExceptionInvalidParam
+ {
+ super(1);
+ setSourceModule(0, sourceModule);
+ xTranslation = DEFAULT_TRANSLATE_POINT_X;
+ yTranslation = DEFAULT_TRANSLATE_POINT_Y;
+ zTranslation = DEFAULT_TRANSLATE_POINT_Z;
+
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+
+ return sourceModules[0].getValue (x + xTranslation, y + yTranslation,
+ z + zTranslation);
+ }
+
+ /// Returns the translation amount to apply to the @a x coordinate of
+ /// the input value.
+ ///
+ /// @returns The translation amount to apply to the @a x coordinate.
+ public double getXTranslation ()
+ {
+ return xTranslation;
+ }
+
+ /// Returns the translation amount to apply to the @a y coordinate of
+ /// the input value.
+ ///
+ /// @returns The translation amount to apply to the @a y coordinate.
+ public double getYTranslation ()
+ {
+ return yTranslation;
+ }
+
+ /// Returns the translation amount to apply to the @a z coordinate of
+ /// the input value.
+ ///
+ /// @returns The translation amount to apply to the @a z coordinate.
+ public double getZTranslation ()
+ {
+ return zTranslation;
+ }
+
+ /// Sets the translation amount to apply to the input value.
+ ///
+ /// @param translation The translation amount to apply.
+ ///
+ /// The getValue() method moves the ( @a x, @a y, @a z ) coordinates
+ /// of the input value by a translation amount before returning the
+ /// output value from the source module
+ public void setTranslation (double translation)
+ {
+ this.xTranslation = translation;
+ this.yTranslation = translation;
+ this.zTranslation = translation;
+ }
+
+ /// Sets the translation amounts to apply to the ( @a x, @a y, @a z )
+ /// coordinates of the input value.
+ ///
+ /// @param xTranslation The translation amount to apply to the @a x
+ /// coordinate.
+ /// @param yTranslation The translation amount to apply to the @a y
+ /// coordinate.
+ /// @param zTranslation The translation amount to apply to the @a z
+ /// coordinate.
+ ///
+ /// The getValue() method moves the ( @a x, @a y, @a z ) coordinates
+ /// of the input value by a translation amount before returning the
+ /// output value from the source module
+ public void setTranslation (double xTranslation, double yTranslation,
+ double zTranslation)
+ {
+ this.xTranslation = xTranslation;
+ this.yTranslation = yTranslation;
+ this.zTranslation = zTranslation;
+ }
+
+ /// Sets the translation amount to apply to the @a x coordinate of the
+ /// input value.
+ ///
+ /// @param xTranslation The translation amount to apply to the @a x
+ /// coordinate.
+ ///
+ /// The getValue() method moves the ( @a x, @a y, @a z ) coordinates
+ /// of the input value by a translation amount before returning the
+ /// output value from the source module
+ public void setXTranslation (double xTranslation)
+ {
+ this.xTranslation = xTranslation;
+ }
+
+ /// Sets the translation amount to apply to the @a y coordinate of the
+ /// input value.
+ ///
+ /// @param yTranslation The translation amount to apply to the @a y
+ /// coordinate.
+ ///
+ /// The getValue() method moves the ( @a x, @a y, @a z ) coordinates
+ /// of the input value by a translation amount before returning the
+ /// output value from the source module
+ public void setYTranslation (double yTranslation)
+ {
+ this.yTranslation = yTranslation;
+ }
+
+ /// Sets the translation amount to apply to the @a z coordinate of the
+ /// input value.
+ ///
+ /// @param zTranslation The translation amount to apply to the @a z
+ /// coordinate.
+ ///
+ /// The getValue() method moves the ( @a x, @a y, @a z ) coordinates
+ /// of the input value by a translation amount before returning the
+ /// output value from the source module
+ public void setZTranslation (double zTranslation)
+ {
+ this.zTranslation = zTranslation;
+ }
+
+}
diff --git a/src/libnoiseforjava/module/Turbulence.java b/src/libnoiseforjava/module/Turbulence.java
new file mode 100644
index 0000000..021cff0
--- /dev/null
+++ b/src/libnoiseforjava/module/Turbulence.java
@@ -0,0 +1,282 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.exception.ExceptionInvalidParam;
+
+public class Turbulence extends ModuleBase
+{
+ /// Noise module that randomly displaces the input value before
+ /// returning the output value from a source module.
+ ///
+ /// @a Turbulence is the pseudo-random displacement of the input value.
+ /// The getValue() method randomly displaces the ( @a x, @a y, @a z )
+ /// coordinates of the input value before retrieving the output value from
+ /// the source module. To control the turbulence, an application can
+ /// modify its frequency, its power, and its roughness.
+ ///
+ /// The frequency of the turbulence determines how rapidly the
+ /// displacement amount changes. To specify the frequency, call the
+ /// setFrequency() method.
+ ///
+ /// The power of the turbulence determines the scaling factor that is
+ /// applied to the displacement amount. To specify the power, call the
+ /// setPower() method.
+ ///
+ /// The roughness of the turbulence determines the roughness of the
+ /// changes to the displacement amount. Low values smoothly change the
+ /// displacement amount. High values roughly change the displacement
+ /// amount, which produces more "kinky" changes. To specify the
+ /// roughness, call the setRoughness() method.
+ ///
+ /// Use of this noise module may require some trial and error. Assuming
+ /// that you are using a generator module as the source module, you
+ /// should first:
+ /// - Set the frequency to the same frequency as the source module.
+ /// - Set the power to the reciprocal of the frequency.
+ ///
+ /// From these initial frequency and power values, modify these values
+ /// until this noise module produce the desired changes in your terrain or
+ /// texture. For example:
+ /// - Low frequency (1/8 initial frequency) and low power (1/8 initial
+ /// power) produces very minor, almost unnoticeable changes.
+ /// - Low frequency (1/8 initial frequency) and high power (8 times
+ /// initial power) produces "ropey" lava-like terrain or marble-like
+ /// textures.
+ /// - High frequency (8 times initial frequency) and low power (1/8
+ /// initial power) produces a noisy version of the initial terrain or
+ /// texture.
+ /// - High frequency (8 times initial frequency) and high power (8 times
+ /// initial power) produces nearly pure noise, which isn't entirely
+ /// useful.
+ ///
+ /// Displacing the input values result in more realistic terrain and
+ /// textures. If you are generating elevations for terrain height maps,
+ /// you can use this noise module to produce more realistic mountain
+ /// ranges or terrain features that look like flowing lava rock. If you
+ /// are generating values for textures, you can use this noise module to
+ /// produce realistic marble-like or "oily" textures.
+ ///
+ /// Internally, there are three noise::module::Perlin noise modules
+ /// that displace the input value; one for the @a x, one for the @a y,
+ /// and one for the @a z coordinate.
+ ///
+ /// This noise module requires one source module.
+
+ /// Default frequency for the Turbulence noise module.
+ static final double DEFAULT_TURBULENCE_FREQUENCY = Perlin.DEFAULT_PERLIN_FREQUENCY;
+
+ /// Default power for the Turbulence noise module.
+ static final double DEFAULT_TURBULENCE_POWER = 1.0;
+
+ /// Default roughness for the Turbulence noise module.
+ static final int DEFAULT_TURBULENCE_ROUGHNESS = 3;
+
+ /// Default noise seed for the Turbulence noise module.
+ static final int DEFAULT_TURBULENCE_SEED = Perlin.DEFAULT_PERLIN_SEED;
+
+
+ /// The power (scale) of the displacement.
+ double power;
+
+ /// Noise module that displaces the @a x coordinate.
+ Perlin xDistortModule;
+
+ /// Noise module that displaces the @a y coordinate.
+ Perlin yDistortModule;
+
+ /// Noise module that displaces the @a z coordinate.
+ Perlin zDistortModule;
+
+ public Turbulence (ModuleBase sourceModule) throws ExceptionInvalidParam
+ {
+ super(1);
+ setSourceModule(0, sourceModule);
+
+ power = DEFAULT_TURBULENCE_POWER;
+
+ xDistortModule = new Perlin();
+ yDistortModule = new Perlin();
+ zDistortModule = new Perlin();
+
+ setSeed(DEFAULT_TURBULENCE_SEED);
+ setFrequency(DEFAULT_TURBULENCE_FREQUENCY);
+ setRoughness (DEFAULT_TURBULENCE_ROUGHNESS);
+ }
+
+ /// Returns the frequency of the turbulence.
+ ///
+ /// @returns The frequency of the turbulence.
+ ///
+ /// The frequency of the turbulence determines how rapidly the
+ /// displacement amount changes.
+ public double getFrequency ()
+ {
+ // Since each noise::module::Perlin noise module has the same frequency, it
+ // does not matter which module we use to retrieve the frequency.
+ return xDistortModule.getFrequency ();
+ }
+
+ /// Returns the seed value of the internal Perlin-noise modules that
+ /// are used to displace the input values.
+ ///
+ /// @returns The seed value.
+ ///
+ /// Internally, there are three Perlin noise modules
+ /// that displace the input value; one for the @a x, one for the @a y,
+ /// and one for the @a z coordinate.
+ public int getSeed ()
+ {
+ return xDistortModule.getSeed ();
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ assert (sourceModules[0] != null);
+
+ // Get the values from the three Perlin noise modules and
+ // add each value to each coordinate of the input value. There are also
+ // some offsets added to the coordinates of the input values. This prevents
+ // the distortion modules from returning zero if the (x, y, z) coordinates,
+ // when multiplied by the frequency, are near an integer boundary. This is
+ // due to a property of gradient coherent noise, which returns zero at
+ // integer boundaries.
+ double x0, y0, z0;
+ double x1, y1, z1;
+ double x2, y2, z2;
+
+ x0 = x + (12414.0 / 65536.0);
+ y0 = y + (65124.0 / 65536.0);
+ z0 = z + (31337.0 / 65536.0);
+ x1 = x + (26519.0 / 65536.0);
+ y1 = y + (18128.0 / 65536.0);
+ z1 = z + (60493.0 / 65536.0);
+ x2 = x + (53820.0 / 65536.0);
+ y2 = y + (11213.0 / 65536.0);
+ z2 = z + (44845.0 / 65536.0);
+
+ double xDistort = x + (xDistortModule.getValue (x0, y0, z0)
+ * power);
+ double yDistort = y + (yDistortModule.getValue (x1, y1, z1)
+ * power);
+ double zDistort = z + (zDistortModule.getValue (x2, y2, z2)
+ * power);
+
+ // Retrieve the output value at the offsetted input value instead of the
+ // original input value.
+ return sourceModules[0].getValue (xDistort, yDistort, zDistort);
+ }
+
+ /// Sets the seed value of the internal noise modules that are used to
+ /// displace the input values.
+ ///
+ /// @param seed The seed value.
+ ///
+ /// Internally, there are three Perlin noise modules
+ /// that displace the input value; one for the @a x, one for the @a y,
+ /// and one for the @a z coordinate. This noise module assigns the
+ /// following seed values to the Perlin noise modules:
+ /// - It assigns the seed value (@a seed + 0) to the @a x noise module.
+ /// - It assigns the seed value (@a seed + 1) to the @a y noise module.
+ /// - It assigns the seed value (@a seed + 2) to the @a z noise module.
+ /// This is done to prevent any sort of weird artifacting.
+ public void setSeed (int seed)
+ {
+ xDistortModule.setSeed (seed);
+ yDistortModule.setSeed (seed + 1);
+ zDistortModule.setSeed (seed + 2);
+ }
+
+ /// Returns the power of the turbulence.
+ ///
+ /// @returns The power of the turbulence.
+ ///
+ /// The power of the turbulence determines the scaling factor that is
+ /// applied to the displacement amount.
+ public double getPower ()
+ {
+ return power;
+ }
+
+ /// Returns the roughness of the turbulence.
+ ///
+ /// @returns The roughness of the turbulence.
+ ///
+ /// The roughness of the turbulence determines the roughness of the
+ /// changes to the displacement amount. Low values smoothly change
+ /// the displacement amount. High values roughly change the
+ /// displacement amount, which produces more "kinky" changes.
+ public int getRoughnessCount ()
+ {
+ return xDistortModule.getOctaveCount ();
+ }
+
+ /// Sets the frequency of the turbulence.
+ ///
+ /// @param frequency The frequency of the turbulence.
+ ///
+ /// The frequency of the turbulence determines how rapidly the
+ /// displacement amount changes.
+ public void setFrequency (double frequency)
+ {
+ xDistortModule.setFrequency (frequency);
+ yDistortModule.setFrequency (frequency);
+ zDistortModule.setFrequency (frequency);
+ }
+
+ /// Sets the power of the turbulence.
+ ///
+ /// @param power The power of the turbulence.
+ ///
+ /// The power of the turbulence determines the scaling factor that is
+ /// applied to the displacement amount.
+ public void setPower (double power)
+ {
+ this.power = power;
+ }
+
+ /// Sets the roughness of the turbulence.
+ ///
+ /// @param roughness The roughness of the turbulence.
+ ///
+ /// The roughness of the turbulence determines the roughness of the
+ /// changes to the displacement amount. Low values smoothly change
+ /// the displacement amount. High values roughly change the
+ /// displacement amount, which produces more "kinky" changes.
+ ///
+ /// Internally, there are three Perlin noise modules
+ /// that displace the input value; one for the @a x, one for the @a y,
+ /// and one for the @a z coordinate. The roughness value is equal to
+ /// the number of octaves used by the noise::module::Perlin noise
+ /// modules.
+ public void setRoughness (int roughness) throws ExceptionInvalidParam
+ {
+ xDistortModule.setOctaveCount (roughness);
+ yDistortModule.setOctaveCount (roughness);
+ zDistortModule.setOctaveCount (roughness);
+ }
+
+}
diff --git a/src/libnoiseforjava/module/Voronoi.java b/src/libnoiseforjava/module/Voronoi.java
new file mode 100644
index 0000000..79776c1
--- /dev/null
+++ b/src/libnoiseforjava/module/Voronoi.java
@@ -0,0 +1,283 @@
+/*
+ * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code)
+ * Copyright 2010 Thomas J. Hodge (java port of libnoise)
+ *
+ * This file is part of libnoiseforjava.
+ *
+ * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at
+ * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be
+ * contacted at [email protected] (for great email, take off every 'zig').
+ * Porting to Java was done by Thomas Hodge, who may be contacted at
+ * [email protected] (remove every 'zag').
+ *
+ * libnoiseforjava 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 of the License, or (at your option) any later version.
+ *
+ * libnoiseforjava 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * libnoiseforjava. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package libnoiseforjava.module;
+
+import libnoiseforjava.NoiseGen;
+
+public class Voronoi extends ModuleBase
+{
+
+ /// Noise module that outputs Voronoi cells.
+ ///
+ /// In mathematics, a <i>Voronoi cell</i> is a region containing all the
+ /// points that are closer to a specific <i>seed point</i> than to any
+ /// other seed point. These cells mesh with one another, producing
+ /// polygon-like formations.
+ ///
+ /// By default, this noise module randomly places a seed point within
+ /// each unit cube. By modifying the <i>frequency</i> of the seed points,
+ /// an application can change the distance between seed points. The
+ /// higher the frequency, the closer together this noise module places
+ /// the seed points, which reduces the size of the cells. To specify the
+ /// frequency of the cells, call the setFrequency() method.
+ ///
+ /// This noise module assigns each Voronoi cell with a random constant
+ /// value from a coherent-noise function. The <i>displacement value</i>
+ /// controls the range of random values to assign to each cell. The
+ /// range of random values is +/- the displacement value. Call the
+ /// setDisplacement() method to specify the displacement value.
+ ///
+ /// To modify the random positions of the seed points, call the SetSeed()
+ /// method.
+ ///
+ /// This noise module can optionally add the distance from the nearest
+ /// seed to the output value. To enable this feature, call the
+ /// enableDistance() method. This causes the points in the Voronoi cells
+ /// to increase in value the further away that point is from the nearest
+ /// seed point.
+ ///
+ /// Voronoi cells are often used to generate cracked-mud terrain
+ /// formations or crystal-like textures
+ ///
+ /// This noise module requires no source modules.
+
+
+ /// Default displacement to apply to each cell for the
+ /// Voronoi noise module.
+ final static double DEFAULT_VORONOI_DISPLACEMENT = 1.0;
+
+ /// Default frequency of the seed points for the Voronoi
+ /// noise module.
+ final static double DEFAULT_VORONOI_FREQUENCY = 1.0;
+
+ /// Default seed of the noise function for the Voronoi
+ /// noise module.
+ final static int DEFAULT_VORONOI_SEED = 0;
+
+ private static final double SQRT_3 = 1.7320508075688772935;
+
+
+ /// Scale of the random displacement to apply to each Voronoi cell.
+ double displacement;
+
+ /// Determines if the distance from the nearest seed point is applied to
+ /// the output value.
+ boolean enableDistance;
+
+ /// Frequency of the seed points.
+ double frequency;
+
+ /// Seed value used by the coherent-noise function to determine the
+ /// positions of the seed points.
+ int seed;
+
+
+ public Voronoi ()
+ {
+ super(0);
+ displacement = DEFAULT_VORONOI_DISPLACEMENT;
+ enableDistance = false;
+ frequency = DEFAULT_VORONOI_FREQUENCY;
+ seed = DEFAULT_VORONOI_SEED;
+ }
+
+ public double getValue (double x, double y, double z)
+ {
+ // This method could be more efficient by caching the seed values. Fix
+ // later.
+
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+
+ int xInt = (x > 0.0? (int)x: (int)x - 1);
+ int yInt = (y > 0.0? (int)y: (int)y - 1);
+ int zInt = (z > 0.0? (int)z: (int)z - 1);
+
+ double minDist = 2147483647.0;
+ double xCandidate = 0;
+ double yCandidate = 0;
+ double zCandidate = 0;
+
+ // Inside each unit cube, there is a seed point at a random position. Go
+ // through each of the nearby cubes until we find a cube with a seed point
+ // that is closest to the specified position.
+ for (int zCur = zInt - 2; zCur <= zInt + 2; zCur++)
+ {
+ for (int yCur = yInt - 2; yCur <= yInt + 2; yCur++)
+ {
+ for (int xCur = xInt - 2; xCur <= xInt + 2; xCur++)
+ {
+ // Calculate the position and distance to the seed point inside of
+ // this unit cube.
+ double xPos = xCur + NoiseGen.ValueNoise3D (xCur, yCur, zCur, seed);
+ double yPos = yCur + NoiseGen.ValueNoise3D (xCur, yCur, zCur, seed + 1);
+ double zPos = zCur + NoiseGen.ValueNoise3D (xCur, yCur, zCur, seed + 2);
+ double xDist = xPos - x;
+ double yDist = yPos - y;
+ double zDist = zPos - z;
+ double dist = xDist * xDist + yDist * yDist + zDist * zDist;
+
+ if (dist < minDist)
+ {
+ // This seed point is closer to any others found so far, so record
+ // this seed point.
+ minDist = dist;
+ xCandidate = xPos;
+ yCandidate = yPos;
+ zCandidate = zPos;
+ }
+ }
+ }
+ }
+
+ double value;
+ if (enableDistance)
+ {
+ // Determine the distance to the nearest seed point.
+ double xDist = xCandidate - x;
+ double yDist = yCandidate - y;
+ double zDist = zCandidate - z;
+ value = (Math.sqrt(xDist * xDist + yDist * yDist + zDist * zDist)
+ ) * SQRT_3 - 1.0;
+ } else {
+ value = 0.0;
+ }
+
+ // Return the calculated distance with the displacement value applied.
+ return value + (displacement * (double)NoiseGen.ValueNoise3D (
+ (int)(Math.floor (xCandidate)),
+ (int)(Math.floor (yCandidate)),
+ (int)(Math.floor (zCandidate)), seed));// added seed here, not in original
+ // but there isn't a working method
+ // without seed
+ }
+
+ /// Enables or disables applying the distance from the nearest seed
+ /// point to the output value.
+ ///
+ /// @param enable Specifies whether to apply the distance to the
+ /// output value or not.
+ ///
+ /// Applying the distance from the nearest seed point to the output
+ /// value causes the points in the Voronoi cells to increase in value
+ /// the further away that point is from the nearest seed point.
+ /// Setting this value to @a true (and setting the displacement to a
+ /// near-zero value) causes this noise module to generate cracked mud
+ /// formations.
+ public void enableDistance (boolean enable)
+ {
+ enableDistance = enable;
+ }
+
+ /// Returns the displacement value of the Voronoi cells.
+ ///
+ /// @returns The displacement value of the Voronoi cells.
+ ///
+ /// This noise module assigns each Voronoi cell with a random constant
+ /// value from a coherent-noise function. The <i>displacement
+ /// value</i> controls the range of random values to assign to each
+ /// cell. The range of random values is +/- the displacement value.
+ public double getDisplacement ()
+ {
+ return displacement;
+ }
+
+ /// Returns the frequency of the seed points.
+ ///
+ /// @returns The frequency of the seed points.
+ ///
+ /// The frequency determines the size of the Voronoi cells and the
+ /// distance between these cells.
+ public double GetFrequency ()
+ {
+ return frequency;
+ }
+
+ /// Returns the seed value used by the Voronoi cells
+ ///
+ /// @returns The seed value.
+ ///
+ /// The positions of the seed values are calculated by a
+ /// coherent-noise function. By modifying the seed value, the output
+ /// of that function changes.
+ public int getSeed ()
+ {
+ return seed;
+ }
+
+ /// Determines if the distance from the nearest seed point is applied
+ /// to the output value.
+ ///
+ /// @returns
+ /// - @a true if the distance is applied to the output value.
+ /// - @a false if not.
+ ///
+ /// Applying the distance from the nearest seed point to the output
+ /// value causes the points in the Voronoi cells to increase in value
+ /// the further away that point is from the nearest seed point.
+ public boolean IsDistanceEnabled ()
+ {
+ return enableDistance;
+ }
+
+ /// Sets the displacement value of the Voronoi cells.
+ ///
+ /// @param displacement The displacement value of the Voronoi cells.
+ ///
+ /// This noise module assigns each Voronoi cell with a random constant
+ /// value from a coherent-noise function. The <i>displacement
+ /// value</i> controls the range of random values to assign to each
+ /// cell. The range of random values is +/- the displacement value.
+ public void setDisplacement (double displacement)
+ {
+ this.displacement = displacement;
+ }
+
+ /// Sets the frequency of the seed points.
+ ///
+ /// @param frequency The frequency of the seed points.
+ ///
+ /// The frequency determines the size of the Voronoi cells and the
+ /// distance between these cells.
+ public void setFrequency (double frequency)
+ {
+ this.frequency = frequency;
+ }
+
+ /// Sets the seed value used by the Voronoi cells
+ ///
+ /// @param seed The seed value.
+ ///
+ /// The positions of the seed values are calculated by a
+ /// coherent-noise function. By modifying the seed value, the output
+ /// of that function changes.
+ public void setSeed (int seed)
+ {
+ this.seed = seed;
+ }
+
+}