>();
+
+ /**
+ * Creates a new instance of Joise with the supplied module chain.
+ *
+ * This method duplicates the module chain by first converting the chain to a
+ * {@link ModuleMap}, then converting it back to a {@link Module} while
+ * mapping any seed names to the seedmap.
+ *
+ * Changes made to the original module passed in will not be reflected in this
+ * instance of Joise.
+ *
+ * @param module
+ */
+ public Joise(Module module) {
+ Assert.notNull(module);
+ moduleMap = module.getModuleMap();
+ this.module = fromModuleMap(moduleMap);
+ }
+
+ /**
+ * Creates a new instance of Joise from the supplied {@link ModuleMap}.
+ *
+ * This method duplicates the module map by first converting the map to a
+ * {@link Module}, then converting it back to a module map. Seed names are
+ * mapped during the conversion from map to module.
+ *
+ * Changes made to the original module map passed in will not be reflected in
+ * this instance of Joise.
+ *
+ * @param moduleMap
+ */
+ public Joise(ModuleMap moduleMap) {
+ Assert.notNull(moduleMap);
+ this.module = fromModuleMap(moduleMap);
+ this.moduleMap = module.getModuleMap();
+ }
+
+ private Module fromModuleMap(ModuleMap map) {
+ try {
+ ModuleInstanceMap im = new ModuleInstanceMap();
+ Iterator> it = map.mapIterator();
+ Module module = null;
+ while (it.hasNext()) {
+ Entry e = it.next();
+ ModulePropertyMap props = e.getValue();
+ String moduleName = "com.sudoplay.joise.module." + props.get("module");
+ module = (Module) Class.forName(moduleName).newInstance();
+ module.buildFromPropertyMap(props, im);
+ if (module instanceof SeedableModule
+ && ((SeedableModule) module).hasSeedName()) {
+ SeedableModule sm = (SeedableModule) module;
+ String seedName = sm.getSeedName();
+
+ ArrayList list = seedMap.get(seedName);
+ if (list == null) {
+ list = new ArrayList();
+ seedMap.put(seedName, list);
+ }
+ list.add(sm);
+ }
+ im.put(e.getKey(), module);
+ }
+ return module;
+ } catch (Exception e) {
+ throw new JoiseException(e);
+ }
+ }
+
+ /**
+ * Sets the seed of the module linked by seedName.
+ *
+ * @param seedName
+ * @param seed
+ * @throws IllegalStateException
+ * if the seed name is not found in the seed map
+ */
+ public void setSeed(String seedName, long seed) {
+ ArrayList list = seedMap.get(seedName);
+ if (list == null || list.isEmpty()) {
+ throw new IllegalStateException("Seed name not found: " + seedName);
+ }
+ for (SeedableModule sm : list) {
+ sm.setSeed(seed);
+ }
+ }
+
+ public boolean hasSeed(String seedName) {
+ return seedMap.get(seedName) != null;
+ }
+
+ /**
+ * @return the stored module map for this Joise
+ */
+ public ModuleMap getModuleMap() {
+ return moduleMap;
+ }
+
+ public double get(double x, double y) {
+ return module.get(x, y);
+ }
+
+ public double get(double x, double y, double z) {
+ return module.get(x, y, z);
+ }
+
+ public double get(double x, double y, double z, double w) {
+ return module.get(x, y, z, w);
+ }
+
+ public double get(double x, double y, double z, double w, double u, double v) {
+ return module.get(x, y, z, w, u, v);
+ }
+
+}
diff --git a/src/com/sudoplay/joise/JoiseException.java b/src/com/sudoplay/joise/JoiseException.java
new file mode 100755
index 000000000..3a888f168
--- /dev/null
+++ b/src/com/sudoplay/joise/JoiseException.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise;
+
+@SuppressWarnings("serial")
+public class JoiseException extends RuntimeException {
+
+ public JoiseException(String msg) {
+ super(msg);
+ }
+
+ public JoiseException(Exception e) {
+ super(e);
+ }
+
+ public JoiseException(String msg, Exception e) {
+ super(msg, e);
+ }
+
+}
diff --git a/src/com/sudoplay/joise/ModuleInstanceMap.java b/src/com/sudoplay/joise/ModuleInstanceMap.java
new file mode 100755
index 000000000..f8502ca73
--- /dev/null
+++ b/src/com/sudoplay/joise/ModuleInstanceMap.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map.Entry;
+
+import com.sudoplay.joise.module.Module;
+
+@SuppressWarnings("serial")
+public class ModuleInstanceMap extends HashMap {
+
+ @Override
+ public Module put(String id, Module module) {
+ if (id == null) {
+ throw new NullPointerException("null id");
+ }
+ if (module == null) {
+ throw new NullPointerException("null module, id=" + id);
+ }
+ return super.put(id, module);
+ }
+
+ @Override
+ public Module get(Object key) {
+ Module module = super.get(key);
+ if (module == null) {
+ throw new NullPointerException("null module, id=" + key);
+ }
+ return module;
+ }
+
+ public boolean contains(String id) {
+ return super.get(id) != null;
+ }
+
+ public Iterator> iterator() {
+ return super.entrySet().iterator();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("[");
+
+ Iterator> it = iterator();
+ while (it.hasNext()) {
+ Entry e = it.next();
+ sb.append("[");
+ sb.append(e.getKey());
+ sb.append("|");
+ sb.append(e.getValue());
+ sb.append("]");
+ }
+
+ sb.append("]");
+ return sb.toString();
+ }
+
+}
diff --git a/src/com/sudoplay/joise/ModuleMap.java b/src/com/sudoplay/joise/ModuleMap.java
new file mode 100755
index 000000000..fe5680701
--- /dev/null
+++ b/src/com/sudoplay/joise/ModuleMap.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise;
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map.Entry;
+
+@SuppressWarnings("serial")
+public class ModuleMap extends LinkedHashMap {
+
+ @Override
+ public ModulePropertyMap put(String module, ModulePropertyMap propertyMap) {
+ if (propertyMap == null) {
+ throw new NullPointerException("property map for module [" + module
+ + "] null");
+ }
+ return super.put(module, propertyMap);
+ }
+
+ @Override
+ public ModulePropertyMap get(Object key) {
+ ModulePropertyMap props = super.get(key);
+ if (props == null) {
+ throw new NullPointerException("property map [" + key + "] null");
+ }
+ return super.get(key);
+ }
+
+ public boolean contains(String id) {
+ return super.get(id) != null;
+ }
+
+ public Iterator> mapIterator() {
+ return super.entrySet().iterator();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("[");
+
+ Iterator> it = mapIterator();
+ while (it.hasNext()) {
+ Entry e = it.next();
+ sb.append("[");
+ sb.append(e.getKey());
+ sb.append("|");
+ sb.append(e.getValue());
+ sb.append("]");
+ }
+
+ sb.append("]");
+ return sb.toString();
+ }
+
+}
diff --git a/src/com/sudoplay/joise/ModulePropertyMap.java b/src/com/sudoplay/joise/ModulePropertyMap.java
new file mode 100755
index 000000000..3f292c320
--- /dev/null
+++ b/src/com/sudoplay/joise/ModulePropertyMap.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise;
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map.Entry;
+
+import com.sudoplay.joise.module.Module;
+
+@SuppressWarnings("serial")
+public class ModulePropertyMap extends LinkedHashMap {
+
+ public ModulePropertyMap() {
+ // serialization
+ }
+
+ public ModulePropertyMap(Module module) {
+ setModule(module);
+ }
+
+ public void setModule(Module module) {
+ super.put("module", module.getClass().getSimpleName());
+ }
+
+ @Override
+ public Object put(String key, Object value) {
+ if (key == null) {
+ throw new NullPointerException();
+ }
+ if (value == null) {
+ return super.put(key, null);
+ } else {
+ return super.put(key, value.toString());
+ }
+ }
+
+ @Override
+ public Object get(Object key) {
+ if (key == null) {
+ throw new NullPointerException();
+ }
+ Object value = super.get(key);
+ return value;
+ }
+
+ public String getAsString(String key) {
+ return get(key).toString();
+ }
+
+ public long getAsLong(String key) {
+ try {
+ return Long.parseLong(getAsString(key));
+ } catch (NumberFormatException e) {
+ throw new JoiseException("Expecting property [" + key + ", "
+ + getAsString(key) + "] to be a long");
+ }
+ }
+
+ public double getAsDouble(String key) {
+ try {
+ return Double.parseDouble(getAsString(key));
+ } catch (NumberFormatException e) {
+ throw new JoiseException("Expecting property [" + key + ", "
+ + getAsString(key) + "] to be a double");
+ }
+ }
+
+ public boolean getAsBoolean(String key) {
+ String candidate = getAsString(key).toLowerCase();
+ if ("true".equals(candidate) || "false".equals(candidate)) {
+ return Boolean.parseBoolean(getAsString(key));
+ } else {
+ throw new JoiseException("Expecting property [" + key + ", "
+ + getAsString(key) + "] to be a boolean");
+ }
+ }
+
+ public boolean isModuleID(String key) {
+ return getAsString(key).startsWith("func_");
+ }
+
+ public boolean contains(String key) {
+ return super.get(key) != null;
+ }
+
+ public Iterator> iterator() {
+ return super.entrySet().iterator();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+
+ Iterator> it = iterator();
+ while (it.hasNext()) {
+ Entry e = it.next();
+ sb.append("[");
+ sb.append(e.getKey());
+ sb.append("|");
+ sb.append(e.getValue());
+ sb.append("]");
+ }
+
+ return sb.toString();
+ }
+
+}
diff --git a/src/com/sudoplay/joise/generator/BasePRNG.java b/src/com/sudoplay/joise/generator/BasePRNG.java
new file mode 100755
index 000000000..183f73bde
--- /dev/null
+++ b/src/com/sudoplay/joise/generator/BasePRNG.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.generator;
+
+public abstract class BasePRNG {
+
+ public abstract int get();
+
+ public abstract void setSeed(long seed);
+
+ public void setSeedTime() {
+ setSeed(System.currentTimeMillis());
+ }
+
+ public int getTarget(int t) {
+ double v = get01();
+ return (int) (v * (double) t);
+ }
+
+ public double get01() {
+ return ((double) get() / (double) 4294967295L) + 0.5;
+ }
+
+ public int getRange(int low, int high) {
+ if (high < low) {
+ int temp = low;
+ low = high;
+ high = temp;
+ }
+ double range = (double) ((high - low) + 1);
+ double val = (double) low + get01() * range;
+ return (int) val;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/generator/CMWC4096.java b/src/com/sudoplay/joise/generator/CMWC4096.java
new file mode 100755
index 000000000..42c6b3f04
--- /dev/null
+++ b/src/com/sudoplay/joise/generator/CMWC4096.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.generator;
+
+/**
+ * Complimentary multiply with carry.
+ */
+public class CMWC4096 extends BasePRNG {
+
+ protected int c;
+ protected int[] Q = new int[4096];
+ protected LCG lcg = new LCG();
+ protected int i;
+
+ public CMWC4096() {
+ setSeed(10000);
+ }
+
+ @Override
+ public int get() {
+ long t;
+ long a = 18782L;
+ long b = 4294967295L;
+ int r = (int) (b - 1);
+ i = (i + 1) & 4095;
+ t = a * Q[i] + c;
+ c = (int) (t >> 32);
+ t = (t & b) + c;
+ if (t > r) {
+ c++;
+ t = t - b;
+ }
+ return Q[i] = (int) (r - t);
+ }
+
+ @Override
+ public void setSeed(long seed) {
+ lcg.setSeed(seed);
+ for (int i = 0; i < 4096; i++) {
+ Q[i] = lcg.get();
+ }
+ c = lcg.getTarget(18781);
+ }
+
+}
diff --git a/src/com/sudoplay/joise/generator/KISS.java b/src/com/sudoplay/joise/generator/KISS.java
new file mode 100755
index 000000000..71236dc2b
--- /dev/null
+++ b/src/com/sudoplay/joise/generator/KISS.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.generator;
+
+public class KISS extends BasePRNG {
+
+ protected LCG lcg = new LCG();
+ protected int z, w, jsr, jcong;
+
+ public KISS() {
+ setSeed(10000);
+ }
+
+ @Override
+ public int get() {
+ z = 36969 * (z & 65535) + (z >> 16);
+ w = 18000 * (w & 65535) + (w >> 16);
+ int mwc = (z << 16) + w;
+ jcong = 69069 * jcong + 1234567;
+ jsr ^= (jsr << 17);
+ jsr ^= (jsr >> 13);
+ jsr ^= (jsr << 5);
+ return ((mwc ^ jcong) + jsr);
+ }
+
+ @Override
+ public void setSeed(long seed) {
+ lcg.setSeed(seed);
+ z = lcg.get();
+ w = lcg.get();
+ jsr = lcg.get();
+ jcong = lcg.get();
+ }
+
+}
diff --git a/src/com/sudoplay/joise/generator/LCG.java b/src/com/sudoplay/joise/generator/LCG.java
new file mode 100755
index 000000000..5d4f887bc
--- /dev/null
+++ b/src/com/sudoplay/joise/generator/LCG.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.generator;
+
+/**
+ * Linear congruential generator.
+ */
+public class LCG extends BasePRNG {
+
+ protected long state;
+
+ public LCG() {
+ setSeed(10000);
+ }
+
+ @Override
+ public int get() {
+ return (int) (state = (25214903917L * state + 11) % 281474976710656L);
+ }
+
+ @Override
+ public void setSeed(long seed) {
+ state = (int) seed;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/generator/MWC.java b/src/com/sudoplay/joise/generator/MWC.java
new file mode 100755
index 000000000..1e8c0a24b
--- /dev/null
+++ b/src/com/sudoplay/joise/generator/MWC.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.generator;
+
+/**
+ * Multiply with carry.
+ */
+public class MWC extends BasePRNG {
+
+ protected LCG lcg = new LCG();
+ protected long x;
+ protected long a = 0xffffda61L;
+
+ public MWC() {
+ setSeed(10000);
+ }
+
+ @Override
+ public int get() {
+ return (int) (x = (a * (x & 0xffffffffL)) + (x >>> 32));
+ }
+
+ @Override
+ public void setSeed(long seed) {
+ lcg.setSeed(seed);
+ x = lcg.get() & 0xffffffffL;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/generator/MWC256.java b/src/com/sudoplay/joise/generator/MWC256.java
new file mode 100755
index 000000000..cd22c4113
--- /dev/null
+++ b/src/com/sudoplay/joise/generator/MWC256.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.generator;
+
+/**
+ * Multiply with carry.
+ */
+public class MWC256 extends BasePRNG {
+
+ protected int[] Q = new int[256];
+ protected int c;
+ protected LCG lcg = new LCG();
+ protected byte b = (byte) 255;
+
+ public MWC256() {
+ setSeed(10000);
+ }
+
+ @Override
+ public int get() {
+ long t;
+ long a = 809430660L;
+ t = a * Q[++b & 0xFF] + c;
+ c = (int) (t >> 32);
+ return Q[b & 0xFF] = (int) t;
+ }
+
+ @Override
+ public void setSeed(long seed) {
+ lcg.setSeed(seed);
+ for (int i = 0; i < 256; i++) {
+ Q[i] = lcg.get();
+ }
+ c = lcg.getTarget(809430660);
+ }
+
+}
diff --git a/src/com/sudoplay/joise/generator/XORShift.java b/src/com/sudoplay/joise/generator/XORShift.java
new file mode 100755
index 000000000..1f4c3723b
--- /dev/null
+++ b/src/com/sudoplay/joise/generator/XORShift.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.generator;
+
+public class XORShift extends BasePRNG {
+
+ protected int x, y, z, w, v;
+ protected LCG lcg = new LCG();
+
+ public XORShift() {
+ setSeed(10000);
+ }
+
+ @Override
+ public int get() {
+ int t;
+ t = (x ^ (x >> 7));
+ x = y;
+ y = z;
+ z = w;
+ w = v;
+ v = (v ^ (v << 6)) ^ (t ^ (t << 13));
+ return (y + y + 1) * v;
+ }
+
+ @Override
+ public void setSeed(long seed) {
+ lcg.setSeed(seed);
+ x = lcg.get();
+ y = lcg.get();
+ z = lcg.get();
+ w = lcg.get();
+ v = lcg.get();
+ }
+
+}
diff --git a/src/com/sudoplay/joise/mapping/Array2Double.java b/src/com/sudoplay/joise/mapping/Array2Double.java
new file mode 100755
index 000000000..afa79a4f3
--- /dev/null
+++ b/src/com/sudoplay/joise/mapping/Array2Double.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.mapping;
+
+public class Array2Double {
+
+ public static final byte X = 0;
+ public static final byte Y = 1;
+
+ private int[] size = new int[2];
+ private double[] data;
+
+ @SuppressWarnings("unused")
+ private Array2Double() {}
+
+ public Array2Double(int x, int y) {
+ this(x, y, new double[x * y]);
+ }
+
+ public Array2Double(int x, int y, double[] data) {
+ size[X] = x;
+ size[Y] = y;
+ this.data = data;
+ }
+
+ public void set(int x, int y, double v) {
+ data[x + size[X] * y] = v;
+ }
+
+ public double get(int x, int y) {
+ return data[x + size[X] * y];
+ }
+
+ public double[] getData() {
+ return data;
+ }
+
+ public int[] getSize() {
+ return size;
+ }
+
+ public int getWidth() {
+ return size[X];
+ }
+
+ public int getHeight() {
+ return size[Y];
+ }
+
+}
diff --git a/src/com/sudoplay/joise/mapping/Array2DoubleWriter.java b/src/com/sudoplay/joise/mapping/Array2DoubleWriter.java
new file mode 100755
index 000000000..e419470db
--- /dev/null
+++ b/src/com/sudoplay/joise/mapping/Array2DoubleWriter.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.mapping;
+
+public class Array2DoubleWriter implements Mapping2DWriter {
+
+ private Array2Double data;
+
+ public Array2DoubleWriter(int x, int y) {
+ this(new Array2Double(x, y));
+ }
+
+ public Array2DoubleWriter(Array2Double data) {
+ this.data = data;
+ }
+
+ public Array2Double getData() {
+ return data;
+ }
+
+ @Override
+ public void write(int x, int y, double value) {
+ data.set(x, y, value);
+ }
+
+}
diff --git a/src/com/sudoplay/joise/mapping/Array3Double.java b/src/com/sudoplay/joise/mapping/Array3Double.java
new file mode 100755
index 000000000..cabeb1623
--- /dev/null
+++ b/src/com/sudoplay/joise/mapping/Array3Double.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.mapping;
+
+public class Array3Double {
+
+ public static final byte X = 0;
+ public static final byte Y = 1;
+ public static final byte Z = 2;
+ public static final byte XY = 3;
+
+ private int[] size = new int[4];
+ private double[] data;
+
+ @SuppressWarnings("unused")
+ private Array3Double() {}
+
+ public Array3Double(int x, int y, int z) {
+ size[X] = x;
+ size[Y] = y;
+ size[Z] = z;
+ size[XY] = x * y;
+ data = new double[x * y * z];
+ }
+
+ public void set(int x, int y, int z, double v) {
+ data[x + (size[X] * y) + (size[XY] * z)] = v;
+ }
+
+ public double get(int x, int y, int z) {
+ return data[x + (size[X] * y) + (size[XY] * z)];
+ }
+
+ public double[] getData() {
+ return data;
+ }
+
+ public int[] getSize() {
+ return size;
+ }
+
+ public int getWidth() {
+ return size[X];
+ }
+
+ public int getHeight() {
+ return size[Y];
+ }
+
+ public int getDepth() {
+ return size[Z];
+ }
+
+}
diff --git a/src/com/sudoplay/joise/mapping/Array3DoubleWriter.java b/src/com/sudoplay/joise/mapping/Array3DoubleWriter.java
new file mode 100755
index 000000000..429b502ec
--- /dev/null
+++ b/src/com/sudoplay/joise/mapping/Array3DoubleWriter.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.mapping;
+
+public class Array3DoubleWriter implements Mapping3DWriter {
+
+ private Array3Double data;
+
+ public Array3DoubleWriter(int x, int y, int z) {
+ this(new Array3Double(x, y, z));
+ }
+
+ public Array3DoubleWriter(Array3Double data) {
+ this.data = data;
+ }
+
+ public Array3Double getData() {
+ return data;
+ }
+
+ @Override
+ public void write(int x, int y, int z, double value) {
+ data.set(x, y, z, value);
+ }
+
+}
diff --git a/src/com/sudoplay/joise/mapping/Mapping.java b/src/com/sudoplay/joise/mapping/Mapping.java
new file mode 100755
index 000000000..540512347
--- /dev/null
+++ b/src/com/sudoplay/joise/mapping/Mapping.java
@@ -0,0 +1,753 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.mapping;
+
+import com.sudoplay.joise.module.Module;
+
+public final class Mapping {
+
+ private static final double TWO_PI = Math.PI * 2.0;
+
+ private Mapping() {
+ // do not instantiate
+ }
+
+ public static void map2D(MappingMode mode, int width, int height, Module m,
+ MappingRange range, Mapping2DWriter writer,
+ MappingUpdateListener listener, double z) {
+
+ if (writer == null) {
+ writer = Mapping2DWriter.NULL_WRITER;
+ }
+
+ if (listener == null) {
+ listener = MappingUpdateListener.NULL_LISTENER;
+ }
+
+ double p, q;
+ double nx, ny, nz, nw, nu, nv;
+ double r;
+ double zval;
+
+ double dx, dy, dz;
+ double dx_div_2pi;
+ double dy_div_2pi;
+ double dz_div_2pi;
+
+ double iw = 1.0 / (double) width;
+ double ih = 1.0 / (double) height;
+
+ double total = width * height;
+ double current = 0;
+
+ switch (mode) {
+
+ case NORMAL:
+
+ dx = range.map1.x - range.map0.x;
+ dy = range.map1.y - range.map0.y;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+
+ nx = range.map0.x + p * dx;
+ ny = range.map0.y + q * dy;
+ nz = z;
+
+ writer.write(x, y, m.get(nx, ny, nz));
+ listener.update(++current, total);
+ }
+ }
+ return;
+
+ case SEAMLESS_X:
+
+ dx = range.loop1.x - range.loop0.x;
+ dy = range.map1.y - range.map0.y;
+
+ dx_div_2pi = dx / TWO_PI;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+
+ p = p * (range.map1.x - range.map0.x) / dx;
+
+ nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
+ ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
+ nz = range.map0.y + q * dy;
+ nw = z;
+
+ writer.write(x, y, m.get(nx, ny, nz, nw));
+ listener.update(++current, total);
+ }
+ }
+ return;
+
+ case SEAMLESS_Y:
+
+ dx = range.map1.x - range.map0.x;
+ dy = range.loop1.y - range.loop0.y;
+
+ dy_div_2pi = dy / TWO_PI;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+
+ q = q * (range.map1.y - range.map0.y) / dy;
+
+ nx = range.map0.x + p * dx;
+ ny = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
+ nz = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
+ nw = z;
+
+ writer.write(x, y, m.get(nx, ny, nz, nw));
+ listener.update(++current, total);
+ }
+ }
+ return;
+
+ case SEAMLESS_Z:
+
+ dx = range.map1.x - range.map0.x;
+ dy = range.map1.y - range.map0.y;
+ dz = range.loop1.z - range.loop0.z;
+
+ r = (z - range.map0.z) / (range.map1.z - range.map0.z);
+ zval = r * (range.map1.z - range.map0.z) / dz;
+
+ dz_div_2pi = dz / TWO_PI;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+
+ nx = range.map0.x + p * dx;
+ ny = range.map0.y + p * dx;
+
+ nz = range.loop0.z + Math.cos(zval * TWO_PI) * dz_div_2pi;
+ nw = range.loop0.z + Math.sin(zval * TWO_PI) * dz_div_2pi;
+
+ writer.write(x, y, m.get(nx, ny, nz, nw));
+ listener.update(++current, total);
+ }
+ }
+ return;
+
+ case SEAMLESS_XY:
+
+ dx = range.loop1.x - range.loop0.x;
+ dy = range.loop1.y - range.loop0.y;
+
+ dx_div_2pi = dx / TWO_PI;
+ dy_div_2pi = dy / TWO_PI;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+
+ p = p * (range.map1.x - range.map0.x) / dx;
+ q = q * (range.map1.y - range.map0.y) / dy;
+
+ nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
+ ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
+ nz = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
+ nw = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
+ nu = z;
+ nv = 0;
+
+ writer.write(x, y, m.get(nx, ny, nz, nw, nu, nv));
+ listener.update(++current, total);
+ }
+ }
+ return;
+
+ case SEAMLESS_XZ:
+
+ dx = range.loop1.x - range.loop0.x;
+ dy = range.map1.y - range.map0.y;
+ dz = range.loop1.z - range.loop0.z;
+
+ dx_div_2pi = dx / TWO_PI;
+ dz_div_2pi = dz / TWO_PI;
+
+ r = (z - range.map0.z) / (range.map1.z - range.map0.z);
+ zval = r * (range.map1.z - range.map0.z) / dz;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+
+ p = p * (range.map1.x - range.map0.x) / dz;
+
+ nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
+ ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
+ nz = range.map0.y + q * dy;
+ nw = range.loop0.z + Math.cos(zval * TWO_PI) * dz_div_2pi;
+ nu = range.loop0.z + Math.sin(zval * TWO_PI) * dz_div_2pi;
+ nv = 0;
+
+ writer.write(x, y, m.get(nx, ny, nz, nw, nu, nv));
+ listener.update(++current, total);
+ }
+ }
+ return;
+
+ case SEAMLESS_YZ:
+
+ dx = range.map1.x - range.map0.x;
+ dy = range.loop1.y - range.loop0.y;
+ dz = range.loop1.z - range.loop0.z;
+
+ dy_div_2pi = dy / TWO_PI;
+ dz_div_2pi = dz / TWO_PI;
+
+ r = (z - range.map0.z) / (range.map1.z - range.map0.z);
+ zval = r * (range.map1.z - range.map0.z) / dz;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+
+ q = q * (range.map1.y - range.map0.y) / dy;
+
+ nx = range.map0.x + p * dx;
+ ny = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
+ nz = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
+ nw = range.loop0.z + Math.cos(zval * TWO_PI) * dz_div_2pi;
+ nu = range.loop0.z + Math.sin(zval * TWO_PI) * dz_div_2pi;
+ nv = 0;
+
+ writer.write(x, y, m.get(nx, ny, nz, nw, nu, nv));
+ listener.update(++current, total);
+ }
+ }
+ return;
+
+ case SEAMLESS_XYZ:
+
+ dx = range.loop1.x - range.loop0.x;
+ dy = range.loop1.y - range.loop0.y;
+ dz = range.loop1.z - range.loop0.z;
+
+ dx_div_2pi = dx / TWO_PI;
+ dy_div_2pi = dy / TWO_PI;
+ dz_div_2pi = dz / TWO_PI;
+
+ r = (z - range.map0.z) / (range.map1.z - range.map0.z);
+ zval = r * (range.map1.z - range.map0.z) / dz;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+
+ p = p * (range.map1.x - range.map0.x) / dx;
+ q = q * (range.map1.y - range.map0.y) / dy;
+
+ nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
+ ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
+ nz = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
+ nw = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
+ nu = range.loop0.z + Math.cos(zval * TWO_PI) * dz_div_2pi;
+ nv = range.loop0.z + Math.sin(zval * TWO_PI) * dz_div_2pi;
+
+ writer.write(x, y, m.get(nx, ny, nz, nw, nu, nv));
+ listener.update(++current, total);
+ }
+ }
+ return;
+
+ default:
+ throw new AssertionError();
+ }
+
+ }
+
+ public static void map2DNoZ(MappingMode mode, int width, int height,
+ Module m, MappingRange range, Mapping2DWriter writer,
+ MappingUpdateListener listener) {
+
+ if (writer == null) {
+ writer = Mapping2DWriter.NULL_WRITER;
+ }
+
+ if (listener == null) {
+ listener = MappingUpdateListener.NULL_LISTENER;
+ }
+
+ double p, q;
+ double nx, ny, nz, nw;
+
+ double dx, dy;
+ double dx_div_2pi;
+ double dy_div_2pi;
+
+ double iw = 1.0 / (double) width;
+ double ih = 1.0 / (double) height;
+
+ double total = width * height;
+ double current = 0;
+
+ switch (mode) {
+
+ case NORMAL:
+
+ dx = range.map1.x - range.map0.x;
+ dy = range.map1.y - range.map0.y;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+
+ nx = range.map0.x + p * dx;
+ ny = range.map0.y + q * dy;
+
+ writer.write(x, y, m.get(nx, ny));
+ listener.update(++current, total);
+ }
+ }
+ return;
+
+ case SEAMLESS_X:
+
+ dx = range.loop1.x - range.loop0.x;
+ dy = range.map1.y - range.map0.y;
+
+ dx_div_2pi = dx / TWO_PI;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+
+ p = p * (range.map1.x - range.map0.x) / dx;
+
+ nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
+ ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
+ nz = range.map0.y + q * dy;
+
+ writer.write(x, y, m.get(nx, ny, nz));
+ listener.update(++current, total);
+ }
+ }
+ return;
+
+ case SEAMLESS_Y:
+
+ dx = range.map1.x - range.map0.x;
+ dy = range.loop1.y - range.loop0.y;
+
+ dy_div_2pi = dy / TWO_PI;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+
+ q = q * (range.map1.y - range.map0.y) / dy;
+
+ nx = range.map0.x + p * dx;
+ ny = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
+ nz = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
+
+ writer.write(x, y, m.get(nx, ny, nz));
+ listener.update(++current, total);
+ }
+ }
+ return;
+
+ case SEAMLESS_XY:
+
+ dx = range.loop1.x - range.loop0.x;
+ dy = range.loop1.y - range.loop0.y;
+
+ dx_div_2pi = dx / TWO_PI;
+ dy_div_2pi = dy / TWO_PI;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+
+ p = p * (range.map1.x - range.map0.x) / dx;
+ q = q * (range.map1.y - range.map0.y) / dy;
+
+ nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
+ ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
+ nz = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
+ nw = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
+
+ writer.write(x, y, m.get(nx, ny, nz, nw));
+ listener.update(++current, total);
+ }
+ }
+ return;
+
+ case SEAMLESS_Z:
+ case SEAMLESS_XZ:
+ case SEAMLESS_YZ:
+ case SEAMLESS_XYZ:
+ throw new UnsupportedOperationException(mode.toString());
+ default:
+ throw new AssertionError();
+ }
+
+ }
+
+ public static void map3D(MappingMode mode, int width, int height, int depth,
+ Module m, MappingRange range, Mapping3DWriter writer,
+ MappingUpdateListener listener) {
+
+ if (writer == null) {
+ writer = Mapping3DWriter.NULL_WRITER;
+ }
+
+ if (listener == null) {
+ listener = MappingUpdateListener.NULL_LISTENER;
+ }
+
+ double p, q, r;
+ double nx, ny, nz, nw, nu, nv;
+
+ double dx, dy, dz;
+ double dx_div_2pi;
+ double dy_div_2pi;
+ double dz_div_2pi;
+
+ double iw = 1.0 / (double) width;
+ double ih = 1.0 / (double) height;
+ double id = 1.0 / (double) depth;
+
+ double total = width * height * depth;
+ double current = 0;
+
+ switch (mode) {
+
+ case NORMAL:
+
+ dx = range.map1.x - range.map0.x;
+ dy = range.map1.y - range.map0.y;
+ dz = range.map1.z - range.map0.z;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ for (int z = 0; z < depth; z++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+ r = (double) z * id;
+
+ nx = range.map0.x + p * dx;
+ ny = range.map0.y + q * dy;
+ nz = range.map0.z + r * dz;
+
+ writer.write(x, y, z, m.get(nx, ny, nz));
+ listener.update(++current, total);
+ }
+ }
+ }
+ return;
+
+ case SEAMLESS_X:
+
+ dx = range.loop1.x - range.loop0.x;
+ dy = range.map1.y - range.map0.y;
+ dz = range.map1.z - range.map0.z;
+
+ dx_div_2pi = dx / TWO_PI;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ for (int z = 0; z < depth; z++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+ r = (double) z * id;
+
+ p = p * (range.map1.x - range.map0.x) / dx;
+
+ nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
+ ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
+ nz = range.map0.y + q * dy;
+ nw = range.map0.z + r * dz;
+
+ writer.write(x, y, z, m.get(nx, ny, nz, nw));
+ listener.update(++current, total);
+ }
+ }
+ }
+ return;
+
+ case SEAMLESS_Y:
+
+ dx = range.map1.x - range.map0.x;
+ dy = range.loop1.y - range.loop0.y;
+ dz = range.map1.z - range.map0.z;
+
+ dy_div_2pi = dy / TWO_PI;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ for (int z = 0; z < depth; z++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+ r = (double) z * id;
+
+ q = q * (range.map1.y - range.map0.y) / dy;
+
+ nx = range.map0.x + p * dx;
+ ny = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
+ nz = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
+ nw = range.map0.z + r * dz;
+
+ writer.write(x, y, z, m.get(nx, ny, nz, nw));
+ listener.update(++current, total);
+ }
+ }
+ }
+ return;
+
+ case SEAMLESS_Z:
+
+ dx = range.map1.x - range.map0.x;
+ dy = range.map1.y - range.map0.y;
+ dz = range.loop1.z - range.loop0.z;
+
+ dz_div_2pi = dz / TWO_PI;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ for (int z = 0; z < depth; z++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+ r = (double) z * id;
+
+ r = r * (range.map1.z - range.map0.z) / dz;
+
+ nx = range.map0.x + p * dx;
+ ny = range.map0.y + q * dy;
+ nz = range.loop0.z + Math.cos(r * TWO_PI) * dz_div_2pi;
+ nw = range.loop0.z + Math.sin(r * TWO_PI) * dz_div_2pi;
+
+ writer.write(x, y, z, m.get(nx, ny, nz, nw));
+ listener.update(++current, total);
+ }
+ }
+ }
+ return;
+
+ case SEAMLESS_XY:
+
+ dx = range.loop1.x - range.loop0.x;
+ dy = range.loop1.y - range.loop0.y;
+ dz = range.map1.z - range.map0.z;
+
+ dx_div_2pi = dx / TWO_PI;
+ dy_div_2pi = dy / TWO_PI;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ for (int z = 0; z < depth; z++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+ r = (double) z * id;
+
+ p = p * (range.map1.x - range.map0.x) / dx;
+ q = q * (range.map1.y - range.map0.y) / dy;
+
+ nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
+ ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
+ nz = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
+ nw = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
+ nu = range.map0.z + r * dz;
+ nv = 0;
+
+ writer.write(x, y, z, m.get(nx, ny, nz, nw, nu, nv));
+ listener.update(++current, total);
+ }
+ }
+ }
+ return;
+
+ case SEAMLESS_XZ:
+
+ dx = range.loop1.x - range.loop0.x;
+ dy = range.map1.y - range.map0.y;
+ dz = range.loop1.z - range.loop0.z;
+
+ dx_div_2pi = dx / TWO_PI;
+ dz_div_2pi = dz / TWO_PI;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ for (int z = 0; z < depth; z++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+ r = (double) z * id;
+
+ p = p * (range.map1.x - range.map0.x) / dx;
+ r = r * (range.map1.z - range.map0.z) / dz;
+
+ nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
+ ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
+ nz = range.map0.y + q * dy;
+ nw = range.loop0.z + Math.cos(r * TWO_PI) * dz_div_2pi;
+ nu = range.loop0.z + Math.sin(r * TWO_PI) * dz_div_2pi;
+ nv = 0;
+
+ writer.write(x, y, z, m.get(nx, ny, nz, nw, nu, nv));
+ listener.update(++current, total);
+ }
+ }
+ }
+ return;
+
+ case SEAMLESS_YZ:
+
+ dx = range.map1.x - range.map0.x;
+ dy = range.loop1.y - range.loop0.y;
+ dz = range.loop1.z - range.loop0.z;
+
+ dy_div_2pi = dy / TWO_PI;
+ dz_div_2pi = dz / TWO_PI;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ for (int z = 0; z < depth; z++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+ r = (double) z * id;
+
+ q = q * (range.map1.y - range.map0.y) / dy;
+ r = r * (range.map1.z - range.map0.z) / dz;
+
+ nx = range.map0.x + p * dx;
+ ny = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
+ nz = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
+ nw = range.loop0.z + Math.cos(r * TWO_PI) * dz_div_2pi;
+ nu = range.loop0.z + Math.sin(r * TWO_PI) * dz_div_2pi;
+ nv = 0;
+
+ writer.write(x, y, z, m.get(nx, ny, nz, nw, nu, nv));
+ listener.update(++current, total);
+ }
+ }
+ }
+ return;
+
+ case SEAMLESS_XYZ:
+
+ dx = range.loop1.x - range.loop0.x;
+ dy = range.loop1.y - range.loop0.y;
+ dz = range.loop1.z - range.loop0.z;
+
+ dx_div_2pi = dx / TWO_PI;
+ dy_div_2pi = dy / TWO_PI;
+ dz_div_2pi = dz / TWO_PI;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ for (int z = 0; z < depth; z++) {
+
+ p = (double) x * iw;
+ q = (double) y * ih;
+ r = (double) z * id;
+
+ p = p * (range.map1.x - range.map0.x) / dx;
+ q = q * (range.map1.y - range.map0.y) / dy;
+ r = r * (range.map1.z - range.map0.z) / dz;
+
+ nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
+ ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
+ nz = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
+ nw = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
+ nu = range.loop0.z + Math.cos(r * TWO_PI) * dz_div_2pi;
+ nv = range.loop0.z + Math.sin(r * TWO_PI) * dz_div_2pi;
+
+ writer.write(x, y, z, m.get(nx, ny, nz, nw, nu, nv));
+ listener.update(++current, total);
+ }
+ }
+ }
+ return;
+
+ default:
+ throw new AssertionError();
+ }
+ }
+
+}
diff --git a/src/com/sudoplay/joise/mapping/Mapping2DWriter.java b/src/com/sudoplay/joise/mapping/Mapping2DWriter.java
new file mode 100755
index 000000000..a117f8907
--- /dev/null
+++ b/src/com/sudoplay/joise/mapping/Mapping2DWriter.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.mapping;
+
+public interface Mapping2DWriter {
+
+ public void write(int x, int y, double value);
+
+ public static final Mapping2DWriter NULL_WRITER = new Mapping2DWriter() {
+ @Override
+ public void write(int x, int y, double value) {
+ // do nothing
+ }
+ };
+
+}
diff --git a/src/com/sudoplay/joise/mapping/Mapping3DWriter.java b/src/com/sudoplay/joise/mapping/Mapping3DWriter.java
new file mode 100755
index 000000000..79f8fff32
--- /dev/null
+++ b/src/com/sudoplay/joise/mapping/Mapping3DWriter.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.mapping;
+
+public interface Mapping3DWriter {
+
+ public void write(int x, int y, int z, double value);
+
+ public static final Mapping3DWriter NULL_WRITER = new Mapping3DWriter() {
+ @Override
+ public void write(int x, int y, int z, double value) {
+ // do nothing
+ }
+ };
+
+}
diff --git a/src/com/sudoplay/joise/mapping/MappingMode.java b/src/com/sudoplay/joise/mapping/MappingMode.java
new file mode 100755
index 000000000..b6626d950
--- /dev/null
+++ b/src/com/sudoplay/joise/mapping/MappingMode.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.mapping;
+
+public enum MappingMode {
+ NORMAL, SEAMLESS_X, SEAMLESS_Y, SEAMLESS_Z, SEAMLESS_XY, SEAMLESS_XZ, SEAMLESS_YZ, SEAMLESS_XYZ
+}
diff --git a/src/com/sudoplay/joise/mapping/MappingRange.java b/src/com/sudoplay/joise/mapping/MappingRange.java
new file mode 100755
index 000000000..6ade070e5
--- /dev/null
+++ b/src/com/sudoplay/joise/mapping/MappingRange.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.mapping;
+
+import com.sudoplay.joise.noise.Util.Vector3d;
+
+public class MappingRange {
+ public Vector3d map0 = new Vector3d(-1, -1, -1);
+ public Vector3d map1 = new Vector3d(1, 1, 1);
+ public Vector3d loop0 = new Vector3d(-1, -1, -1);
+ public Vector3d loop1 = new Vector3d(1, 1, 1);
+
+ public static final MappingRange DEFAULT = new MappingRange();
+}
diff --git a/src/com/sudoplay/joise/mapping/MappingUpdateListener.java b/src/com/sudoplay/joise/mapping/MappingUpdateListener.java
new file mode 100755
index 000000000..32b04fea0
--- /dev/null
+++ b/src/com/sudoplay/joise/mapping/MappingUpdateListener.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.mapping;
+
+public interface MappingUpdateListener {
+
+ public void update(double current, double total);
+
+ public static final MappingUpdateListener NULL_LISTENER = new MappingUpdateListener() {
+ @Override
+ public void update(double current, double total) {
+ // do nothing
+ }
+ };
+
+}
diff --git a/src/com/sudoplay/joise/module/Module.java b/src/com/sudoplay/joise/module/Module.java
new file mode 100755
index 000000000..c0ff6f8d8
--- /dev/null
+++ b/src/com/sudoplay/joise/module/Module.java
@@ -0,0 +1,371 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import java.lang.reflect.Method;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import com.sudoplay.joise.JoiseException;
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public abstract class Module {
+
+ public static final long DEFAULT_SEED = 10000;
+ public static final int MAX_SOURCES = 10;
+
+ protected double spacing = 0.0001;
+
+ public abstract double get(double x, double y);
+
+ public abstract double get(double x, double y, double z);
+
+ public abstract double get(double x, double y, double z, double w);
+
+ public abstract double get(double x, double y, double z, double w, double u,
+ double v);
+
+ protected static AtomicInteger nextId = new AtomicInteger();
+
+ private String id = setId();
+
+ protected String setId() {
+ return "func_" + nextId.incrementAndGet();
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public ModuleMap getModuleMap() {
+ ModuleMap map = new ModuleMap();
+ _writeToMap(map);
+ return map;
+ }
+
+ public void writeToMap(ModuleMap map) {
+ if (map.contains(id)) {
+ return;
+ }
+ _writeToMap(map);
+ }
+
+ protected abstract void _writeToMap(ModuleMap map);
+
+ public abstract Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map);
+
+ public void setDerivativeSpacing(double spacing) {
+ this.spacing = spacing;
+ }
+
+ public double getDX(double x, double y) {
+ return (get(x - spacing, y) - get(x + spacing, y)) / spacing;
+ }
+
+ public double getDY(double x, double y) {
+ return (get(x, y - spacing) - get(x, y + spacing)) / spacing;
+ }
+
+ public double getDX(double x, double y, double z) {
+ return (get(x - spacing, y, z) - get(x + spacing, y, z)) / spacing;
+ }
+
+ public double getDY(double x, double y, double z) {
+ return (get(x, y - spacing, z) - get(x, y + spacing, z)) / spacing;
+ }
+
+ public double getDZ(double x, double y, double z) {
+ return (get(x, y, z - spacing) - get(x, y, z + spacing)) / spacing;
+ }
+
+ public double getDX(double x, double y, double z, double w) {
+ return (get(x - spacing, y, z, w) - get(x + spacing, y, z, w)) / spacing;
+ }
+
+ public double getDY(double x, double y, double z, double w) {
+ return (get(x, y - spacing, z, w) - get(x, y + spacing, z, w)) / spacing;
+ }
+
+ public double getDZ(double x, double y, double z, double w) {
+ return (get(x, y, z - spacing, w) - get(x, y, z + spacing, w)) / spacing;
+ }
+
+ public double getDW(double x, double y, double z, double w) {
+ return (get(x, y, z, w - spacing) - get(x, y, z, w + spacing)) / spacing;
+ }
+
+ public double getDX(double x, double y, double z, double w, double u, double v) {
+ return (get(x - spacing, y, z, w, u, v) - get(x + spacing, y, z, w, u, v))
+ / spacing;
+ }
+
+ public double getDY(double x, double y, double z, double w, double u, double v) {
+ return (get(x, y - spacing, z, w, u, v) - get(x, y + spacing, z, w, u, v))
+ / spacing;
+ }
+
+ public double getDZ(double x, double y, double z, double w, double u, double v) {
+ return (get(x, y, z - spacing, w, u, v) - get(x, y, z + spacing, w, u, v))
+ / spacing;
+ }
+
+ public double getDW(double x, double y, double z, double w, double u, double v) {
+ return (get(x, y, z, w - spacing, u, v) - get(x, y, z, w + spacing, u, v))
+ / spacing;
+ }
+
+ public double getDU(double x, double y, double z, double w, double u, double v) {
+ return (get(x, y, z, w, u - spacing, v) - get(x, y, z, w, u + spacing, v))
+ / spacing;
+ }
+
+ public double getDV(double x, double y, double z, double w, double u, double v) {
+ return (get(x, y, z, w, u, v - spacing) - get(x, y, z, w, u, v + spacing))
+ / spacing;
+ }
+
+ protected void assertMaxSources(int index) {
+ if (index < 0 || index >= MAX_SOURCES) {
+ throw new IllegalArgumentException("expecting index < " + MAX_SOURCES
+ + " but was " + index);
+ }
+ }
+
+ /**
+ * Read a scalar property from the provided property map and set the property
+ * in this module using reflection to call the supplied method name with the
+ * retrieved property passed as an argument. If the scalar is a module name,
+ * the module is retrieved from the provided {@link ModuleInstanceMap} and set
+ * using the reflected method provided.
+ *
+ * @param name
+ * @param methodName
+ * @param props
+ * @param map
+ *
+ * @throws JoiseException
+ * if there is an error with the retrieval or setting of the
+ * property
+ */
+ protected void readScalar(String name, String methodName,
+ ModulePropertyMap props, ModuleInstanceMap map) {
+
+ try {
+ if (props.isModuleID(name)) {
+ Method method = getClass().getMethod(methodName, Module.class);
+ method.invoke(this, new Object[] { map.get(props.get(name)) });
+ } else {
+ Method method = getClass().getMethod(methodName, double.class);
+ method.invoke(this, new Object[] { props.getAsDouble(name) });
+ }
+ } catch (Exception e) {
+ throw new JoiseException(e);
+ }
+
+ }
+
+ /**
+ * Write a scalar property to the provided property map. If the scalar is a
+ * module, {@link #_writeToMap(ModuleMap)} is called on the scalar's module.
+ *
+ * @param key
+ * @param scalar
+ * @param props
+ * @param map
+ */
+ protected void writeScalar(String key, ScalarParameter scalar,
+ ModulePropertyMap props, ModuleMap map) {
+
+ props.put(key, scalar);
+ if (scalar != null && scalar.isModule()) {
+ scalar.getModule()._writeToMap(map);
+ }
+
+ }
+
+ /**
+ * Read an enum property from the provided property map and set the property
+ * in this module using reflection to call the supplied method name with the
+ * retrieved property passed as an argument.
+ *
+ * @param name
+ * @param methodName
+ * @param c
+ * @param props
+ */
+ protected > void readEnum(String name, String methodName,
+ Class c, ModulePropertyMap props) {
+
+ try {
+ Method method = getClass().getMethod(methodName, c);
+ T _enum = Enum.valueOf(c, props.get(name).toString().toUpperCase());
+ method.invoke(this, new Object[] { _enum });
+ } catch (Exception e) {
+ throw new JoiseException(e);
+ }
+
+ }
+
+ /**
+ * Write an enum property to the provided property map. The enum is converted
+ * to lower-case.
+ *
+ * @param key
+ * @param _enum
+ * @param props
+ */
+ protected void writeEnum(String key, Enum> _enum, ModulePropertyMap props) {
+
+ props.put(key, _enum.toString().toLowerCase());
+
+ }
+
+ /**
+ * Read a long property from the provided property map and set the property in
+ * this module using reflection to call the supplied method name with the
+ * retrieved property passed as an argument.
+ *
+ * @param key
+ * @param methodName
+ * @param props
+ */
+ protected void readLong(String key, String methodName, ModulePropertyMap props) {
+
+ try {
+ Method method = getClass().getMethod(methodName, long.class);
+ method.invoke(this, new Object[] { props.getAsLong(key) });
+ } catch (Exception e) {
+ throw new JoiseException(e);
+ }
+
+ }
+
+ /**
+ * Write a long property to the provided property map.
+ *
+ * @param key
+ * @param value
+ * @param props
+ */
+ protected void writeLong(String key, long value, ModulePropertyMap props) {
+
+ props.put(key, value);
+
+ }
+
+ /**
+ * Read a double property from the provided property map and set the property
+ * in this module using reflection to call the supplied method name with the
+ * retrieved property passed as an argument.
+ *
+ * @param key
+ * @param methodName
+ * @param props
+ */
+ protected void readDouble(String key, String methodName,
+ ModulePropertyMap props) {
+
+ try {
+ Method method = getClass().getMethod(methodName, double.class);
+ method.invoke(this, new Object[] { props.getAsDouble(key) });
+ } catch (Exception e) {
+ throw new JoiseException(e);
+ }
+
+ }
+
+ /**
+ * Write a double property to the provided property map.
+ *
+ * @param key
+ * @param value
+ * @param props
+ */
+ protected void writeDouble(String key, double value, ModulePropertyMap props) {
+
+ props.put(key, value);
+
+ }
+
+ /**
+ * Read a boolean property from the provided property map and set the property
+ * in this module using reflection to call the supplied method name with the
+ * retrieved property passed as an argument.
+ *
+ * @param key
+ * @param methodName
+ * @param props
+ */
+ protected void readBoolean(String key, String methodName,
+ ModulePropertyMap props) {
+
+ try {
+ Method method = getClass().getMethod(methodName, boolean.class);
+ method.invoke(this, new Object[] { props.getAsBoolean(key) });
+ } catch (Exception e) {
+ throw new JoiseException(e);
+ }
+
+ }
+
+ /**
+ * Write a boolean property to the provided property map.
+ *
+ * @param key
+ * @param value
+ * @param props
+ */
+ protected void writeBoolean(String key, boolean value, ModulePropertyMap props) {
+
+ props.put(key, String.valueOf(value));
+
+ }
+}
diff --git a/src/com/sudoplay/joise/module/ModuleAbs.java b/src/com/sudoplay/joise/module/ModuleAbs.java
new file mode 100755
index 000000000..a89abd5d6
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleAbs.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleAbs extends SourcedModule {
+
+ @Override
+ public double get(double x, double y) {
+ return Math.abs(source.get(x, y));
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ return Math.abs(source.get(x, y, z));
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ return Math.abs(source.get(x, y, z, w));
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ return Math.abs(source.get(x, y, z, w, u, v));
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleAutoCorrect.java b/src/com/sudoplay/joise/module/ModuleAutoCorrect.java
new file mode 100755
index 000000000..29dc9f516
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleAutoCorrect.java
@@ -0,0 +1,305 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import static com.sudoplay.joise.noise.Util.clamp;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+import com.sudoplay.joise.generator.LCG;
+import com.sudoplay.util.Checked;
+
+public class ModuleAutoCorrect extends SourcedModule {
+
+ public static final double DEFAULT_LOW = 0.0;
+ public static final double DEFAULT_HIGH = 1.0;
+ public static final int DEFAULT_SAMPLES = 100;
+ public static final double DEFAULT_SAMPLE_SCALE = 1.0;
+
+ protected double low;
+ protected double high;
+
+ protected double sampleScale = DEFAULT_SAMPLE_SCALE;
+
+ protected double scale2, offset2;
+ protected double scale3, offset3;
+ protected double scale4, offset4;
+ protected double scale6, offset6;
+
+ protected boolean locked;
+
+ protected int samples = DEFAULT_SAMPLES;
+
+ public ModuleAutoCorrect() {
+ this(DEFAULT_LOW, DEFAULT_HIGH);
+ }
+
+ public ModuleAutoCorrect(double low, double high) {
+ this.low = low;
+ this.high = high;
+ }
+
+ public void setRange(double low, double high) {
+ this.low = low;
+ this.high = high;
+ }
+
+ public void setLow(double low) {
+ this.low = low;
+ }
+
+ public void setHigh(double high) {
+ this.high = high;
+ }
+
+ public void setSamples(long s) {
+ samples = Checked.safeLongToInt(s);
+ }
+
+ public void setSampleScale(double s) {
+ sampleScale = s;
+ }
+
+ public void setLocked(boolean lock) {
+ locked = lock;
+ }
+
+ @Override
+ public void setSource(double source) {
+ super.setSource(source);
+ }
+
+ @Override
+ public void setSource(Module source) {
+ super.setSource(source);
+ }
+
+ public void calculate() {
+ if (!source.isModule() || locked) return;
+
+ double mn, mx;
+ LCG lcg = new LCG();
+
+ // Calculate 2D
+ mn = 10000.0;
+ mx = -10000.0;
+ for (int c = 0; c < samples; c++) {
+ double nx = (lcg.get01() * 4.0 - 2.0) * sampleScale;
+ double ny = (lcg.get01() * 4.0 - 2.0) * sampleScale;
+
+ double v = source.get(nx, ny);
+ if (v < mn) mn = v;
+ if (v > mx) mx = v;
+ }
+ scale2 = (high - low) / (mx - mn);
+ offset2 = low - mn * scale2;
+
+ // Calculate 3D
+ mn = 10000.0;
+ mx = -10000.0;
+ for (int c = 0; c < samples; c++) {
+ double nx = (lcg.get01() * 4.0 - 2.0) * sampleScale;
+ double ny = (lcg.get01() * 4.0 - 2.0) * sampleScale;
+ double nz = (lcg.get01() * 4.0 - 2.0) * sampleScale;
+
+ double v = source.get(nx, ny, nz);
+ if (v < mn) mn = v;
+ if (v > mx) mx = v;
+ }
+ scale3 = (high - low) / (mx - mn);
+ offset3 = low - mn * scale3;
+
+ // Calculate 4D
+ mn = 10000.0;
+ mx = -10000.0;
+ for (int c = 0; c < samples; c++) {
+ double nx = (lcg.get01() * 4.0 - 2.0) * sampleScale;
+ double ny = (lcg.get01() * 4.0 - 2.0) * sampleScale;
+ double nz = (lcg.get01() * 4.0 - 2.0) * sampleScale;
+ double nw = (lcg.get01() * 4.0 - 2.0) * sampleScale;
+
+ double v = source.get(nx, ny, nz, nw);
+ if (v < mn) mn = v;
+ if (v > mx) mx = v;
+ }
+ scale4 = (high - low) / (mx - mn);
+ offset4 = low - mn * scale4;
+
+ // Calculate 6D
+ mn = 10000.0;
+ mx = -10000.0;
+ for (int c = 0; c < samples; c++) {
+ double nx = (lcg.get01() * 4.0 - 2.0) * sampleScale;
+ double ny = (lcg.get01() * 4.0 - 2.0) * sampleScale;
+ double nz = (lcg.get01() * 4.0 - 2.0) * sampleScale;
+ double nw = (lcg.get01() * 4.0 - 2.0) * sampleScale;
+ double nu = (lcg.get01() * 4.0 - 2.0) * sampleScale;
+ double nv = (lcg.get01() * 4.0 - 2.0) * sampleScale;
+
+ double v = source.get(nx, ny, nz, nw, nu, nv);
+ if (v < mn) mn = v;
+ if (v > mx) mx = v;
+ }
+ scale6 = (high - low) / (mx - mn);
+ offset6 = low - mn * scale6;
+
+ }
+
+ @Override
+ public double get(double x, double y) {
+ double v = source.get(x, y);
+ return clamp(v * scale2 + offset2, low, high);
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ double v = source.get(x, y, z);
+ return clamp(v * scale3 + offset3, low, high);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ double v = source.get(x, y, z, w);
+ return clamp(v * scale4 + offset4, low, high);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ double val = source.get(x, y, z, w, u, v);
+ return clamp(val * scale6 + offset6, low, high);
+ }
+
+ public double getOffset2D() {
+ return offset2;
+ }
+
+ public double getOffset3D() {
+ return offset3;
+ }
+
+ public double getOffset4D() {
+ return offset4;
+ }
+
+ public double getOffset6D() {
+ return offset6;
+ }
+
+ public double getScale2D() {
+ return scale2;
+ }
+
+ public double getScale3D() {
+ return scale3;
+ }
+
+ public double getScale4D() {
+ return scale4;
+ }
+
+ public double getScale6D() {
+ return scale6;
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeDouble("low", low, props);
+ writeDouble("high", high, props);
+ writeLong("samples", samples, props);
+ writeDouble("sampleScale", sampleScale, props);
+ writeBoolean("locked", locked, props);
+
+ if (locked) {
+ writeDouble("scale2", scale2, props);
+ writeDouble("offset2", offset2, props);
+ writeDouble("scale3", scale3, props);
+ writeDouble("offset3", offset3, props);
+ writeDouble("scale4", scale4, props);
+ writeDouble("offset4", offset4, props);
+ writeDouble("scale6", scale6, props);
+ writeDouble("offset6", offset6, props);
+ }
+
+ writeSource(props, map);
+
+ map.put(getId(), props);
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readDouble("low", "setLow", props);
+ readDouble("high", "setHigh", props);
+ readLong("samples", "setSamples", props);
+ readDouble("sampleScale", "setSampleScale", props);
+ readBoolean("locked", "setLocked", props);
+
+ if (locked) {
+ scale2 = props.getAsDouble("scale2");
+ offset2 = props.getAsDouble("offset2");
+ scale3 = props.getAsDouble("scale3");
+ offset3 = props.getAsDouble("offset3");
+ scale4 = props.getAsDouble("scale4");
+ offset4 = props.getAsDouble("offset4");
+ scale6 = props.getAsDouble("scale6");
+ offset6 = props.getAsDouble("offset6");
+ }
+
+ readSource(props, map);
+ calculate();
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleBasisFunction.java b/src/com/sudoplay/joise/module/ModuleBasisFunction.java
new file mode 100755
index 000000000..0f27bb3a9
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleBasisFunction.java
@@ -0,0 +1,334 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+import com.sudoplay.joise.generator.LCG;
+import com.sudoplay.joise.noise.Interpolator;
+import com.sudoplay.joise.noise.Noise;
+
+public class ModuleBasisFunction extends SeedableModule {
+
+ public enum BasisType {
+ VALUE, GRADIENT, GRADVAL, SIMPLEX, WHITE
+ }
+
+ public enum InterpolationType {
+ NONE, LINEAR, CUBIC, QUINTIC
+ }
+
+ protected double[] scale = new double[4];
+ protected double[] offset = new double[4];
+ protected double[][] rotMatrix = new double[3][3];
+ protected double cos2d, sin2d;
+
+ protected Noise.Function2D func2D;
+ protected Noise.Function3D func3D;
+ protected Noise.Function4D func4D;
+ protected Noise.Function6D func6D;
+
+ protected Interpolator interpolator;
+
+ protected BasisType basisType;
+ protected InterpolationType interpolationType;
+
+ public ModuleBasisFunction() {
+ this(BasisType.GRADIENT, InterpolationType.QUINTIC, 10000);
+ }
+
+ public ModuleBasisFunction(BasisType type) {
+ this(type, InterpolationType.QUINTIC, 10000);
+ }
+
+ public ModuleBasisFunction(BasisType type, InterpolationType interpolationType) {
+ this(type, interpolationType, 10000);
+ }
+
+ public ModuleBasisFunction(BasisType type,
+ InterpolationType interpolationType, long seed) {
+ setType(type);
+ setInterpolation(interpolationType);
+ setSeed(seed);
+ }
+
+ public void setType(BasisType type) {
+ basisType = type;
+ switch (type) {
+ case GRADVAL:
+ func2D = Noise.Function2D.GRADVAL;
+ func3D = Noise.Function3D.GRADVAL;
+ func4D = Noise.Function4D.GRADVAL;
+ func6D = Noise.Function6D.GRADVAL;
+ break;
+ case SIMPLEX:
+ func2D = Noise.Function2D.SIMPLEX;
+ func3D = Noise.Function3D.SIMPLEX;
+ func4D = Noise.Function4D.SIMPLEX;
+ func6D = Noise.Function6D.SIMPLEX;
+ break;
+ case VALUE:
+ func2D = Noise.Function2D.VALUE;
+ func3D = Noise.Function3D.VALUE;
+ func4D = Noise.Function4D.VALUE;
+ func6D = Noise.Function6D.VALUE;
+ break;
+ case WHITE:
+ func2D = Noise.Function2D.WHITE;
+ func3D = Noise.Function3D.WHITE;
+ func4D = Noise.Function4D.WHITE;
+ func6D = Noise.Function6D.WHITE;
+ break;
+ case GRADIENT:
+ // fallthrough intentional
+ default:
+ func2D = Noise.Function2D.GRADIENT;
+ func3D = Noise.Function3D.GRADIENT;
+ func4D = Noise.Function4D.GRADIENT;
+ func6D = Noise.Function6D.GRADIENT;
+ break;
+ }
+ setMagicNumbers(type);
+ }
+
+ public BasisType getBasisType() {
+ return basisType;
+ }
+
+ public void setInterpolation(InterpolationType type) {
+ interpolationType = type;
+ switch (type) {
+ case CUBIC:
+ this.interpolator = Interpolator.HERMITE;
+ break;
+ case LINEAR:
+ this.interpolator = Interpolator.LINEAR;
+ break;
+ case NONE:
+ this.interpolator = Interpolator.NONE;
+ break;
+ default:
+ this.interpolator = Interpolator.QUINTIC;
+ break;
+ }
+ }
+
+ public InterpolationType getInterpolationType() {
+ return interpolationType;
+ }
+
+ /**
+ * Set the rotation axis and angle to use for 3D, 4D and 6D noise.
+ *
+ * @param x
+ * @param y
+ * @param z
+ * @param angle
+ */
+ public void setRotationAngle(double x, double y, double z, double angle) {
+ double sin = Math.sin(angle);
+ double cos = Math.cos(angle);
+
+ rotMatrix[0][0] = 1 + (1 - cos) * (x * x - 1);
+ rotMatrix[1][0] = -z * sin + (1 - cos) * x * y;
+ rotMatrix[2][0] = y * sin + (1 - cos) * x * z;
+
+ rotMatrix[0][1] = z * sin + (1 - cos) * x * y;
+ rotMatrix[1][1] = 1 + (1 - cos) * (y * y - 1);
+ rotMatrix[2][1] = -x * sin + (1 - cos) * y * z;
+
+ rotMatrix[0][2] = -y * sin + (1 - cos) * x * z;
+ rotMatrix[1][2] = x * sin + (1 - cos) * y * z;
+ rotMatrix[2][2] = 1 + (1 - cos) * (z * z - 1);
+ }
+
+ @Override
+ public void setSeed(long seed) {
+ super.setSeed(seed);
+
+ LCG lcg = new LCG();
+ lcg.setSeed(seed);
+
+ double ax, ay, az;
+ double len;
+
+ ax = lcg.get01();
+ ay = lcg.get01();
+ az = lcg.get01();
+ len = Math.sqrt(ax * ax + ay * ay + az * az);
+ ax /= len;
+ ay /= len;
+ az /= len;
+ setRotationAngle(ax, ay, az, lcg.get01() * 3.141592 * 2.0);
+ double angle = lcg.get01() * 3.141592 * 2.0;
+ cos2d = Math.cos(angle);
+ sin2d = Math.sin(angle);
+ }
+
+ @Override
+ public double get(double x, double y) {
+ double nx, ny;
+ nx = x * cos2d - y * sin2d;
+ ny = y * cos2d + x * sin2d;
+ return func2D.get(nx, ny, seed, interpolator);
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ double nx, ny, nz;
+ nx = (rotMatrix[0][0] * x) + (rotMatrix[1][0] * y) + (rotMatrix[2][0] * z);
+ ny = (rotMatrix[0][1] * x) + (rotMatrix[1][1] * y) + (rotMatrix[2][1] * z);
+ nz = (rotMatrix[0][2] * x) + (rotMatrix[1][2] * y) + (rotMatrix[2][2] * z);
+ return func3D.get(nx, ny, nz, seed, interpolator);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ double nx, ny, nz;
+ nx = (rotMatrix[0][0] * x) + (rotMatrix[1][0] * y) + (rotMatrix[2][0] * z);
+ ny = (rotMatrix[0][1] * x) + (rotMatrix[1][1] * y) + (rotMatrix[2][1] * z);
+ nz = (rotMatrix[0][2] * x) + (rotMatrix[1][2] * y) + (rotMatrix[2][2] * z);
+ return func4D.get(nx, ny, nz, w, seed, interpolator);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ double nx, ny, nz;
+ nx = (rotMatrix[0][0] * x) + (rotMatrix[1][0] * y) + (rotMatrix[2][0] * z);
+ ny = (rotMatrix[0][1] * x) + (rotMatrix[1][1] * y) + (rotMatrix[2][1] * z);
+ nz = (rotMatrix[0][2] * x) + (rotMatrix[1][2] * y) + (rotMatrix[2][2] * z);
+ return func6D.get(nx, ny, nz, w, u, v, seed, interpolator);
+ }
+
+ protected void setMagicNumbers(BasisType type) {
+ switch (type) {
+ case VALUE:
+ scale[0] = 1.0;
+ offset[0] = 0.0;
+ scale[1] = 1.0;
+ offset[1] = 0.0;
+ scale[2] = 1.0;
+ offset[2] = 0.0;
+ scale[3] = 1.0;
+ offset[3] = 0.0;
+ break;
+
+ case GRADIENT:
+ scale[0] = 1.86848;
+ offset[0] = -0.000118;
+ scale[1] = 1.85148;
+ offset[1] = -0.008272;
+ scale[2] = 1.64127;
+ offset[2] = -0.01527;
+ scale[3] = 1.92517;
+ offset[3] = 0.03393;
+ break;
+
+ case GRADVAL:
+ scale[0] = 0.6769;
+ offset[0] = -0.00151;
+ scale[1] = 0.6957;
+ offset[1] = -0.133;
+ scale[2] = 0.74622;
+ offset[2] = 0.01916;
+ scale[3] = 0.7961;
+ offset[3] = -0.0352;
+ break;
+
+ case WHITE:
+ scale[0] = 1.0;
+ offset[0] = 0.0;
+ scale[1] = 1.0;
+ offset[1] = 0.0;
+ scale[2] = 1.0;
+ offset[2] = 0.0;
+ scale[3] = 1.0;
+ offset[3] = 0.0;
+ break;
+
+ default:
+ scale[0] = 1.0;
+ offset[0] = 0.0;
+ scale[1] = 1.0;
+ offset[1] = 0.0;
+ scale[2] = 1.0;
+ offset[2] = 0.0;
+ scale[3] = 1.0;
+ offset[3] = 0.0;
+ break;
+ }
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeEnum("basis", getBasisType(), props);
+ writeEnum("interpolation", getInterpolationType(), props);
+ writeSeed(props);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readEnum("basis", "setType", BasisType.class, props);
+ readEnum("interpolation", "setInterpolation", InterpolationType.class,
+ props);
+ readSeed(props);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleBias.java b/src/com/sudoplay/joise/module/ModuleBias.java
new file mode 100755
index 000000000..128ee36d0
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleBias.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import static com.sudoplay.joise.noise.Util.bias;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleBias extends SourcedModule {
+
+ protected ScalarParameter bias = new ScalarParameter(0.5);
+
+ public ModuleBias() {}
+
+ public ModuleBias(double bias) {
+ this.bias.set(bias);
+ }
+
+ public ModuleBias(Module bias) {
+ this.bias.set(bias);
+ }
+
+ public void setBias(double bias) {
+ this.bias.set(bias);
+ }
+
+ public void setBias(Module bias) {
+ this.bias.set(bias);
+ }
+
+ @Override
+ public double get(double x, double y) {
+ double val = source.get(x, y);
+ return bias(bias.get(x, y), val);
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ double val = source.get(x, y, z);
+ return bias(bias.get(x, y, z), val);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ double val = source.get(x, y, z, w);
+ return bias(bias.get(x, y, z, w), val);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ double val = source.get(x, y, z, w, u, v);
+ return bias(bias.get(x, y, z, w, u, v), val);
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeScalar("bias", bias, props, map);
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readScalar("bias", "setBias", props, map);
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleBlend.java b/src/com/sudoplay/joise/module/ModuleBlend.java
new file mode 100755
index 000000000..849144755
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleBlend.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import static com.sudoplay.joise.noise.Util.lerp;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleBlend extends Module {
+
+ protected ScalarParameter low = new ScalarParameter(0.0);
+ protected ScalarParameter high = new ScalarParameter(1.0);
+ protected ScalarParameter control = new ScalarParameter(0.5);
+
+ public void setLowSource(Module source) {
+ low.set(source);
+ }
+
+ public void setLowSource(double source) {
+ low.set(source);
+ }
+
+ public void setHighSource(Module source) {
+ high.set(source);
+ }
+
+ public void setHighSource(double source) {
+ high.set(source);
+ }
+
+ public void setControlSource(Module source) {
+ control.set(source);
+ }
+
+ public void setControlSource(double source) {
+ control.set(source);
+ }
+
+ @Override
+ public double get(double x, double y) {
+ double v1 = low.get(x, y);
+ double v2 = high.get(x, y);
+ double bl = control.get(x, y);
+ bl = (bl + 1.0) * 0.5;
+ return lerp(bl, v1, v2);
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ double v1 = low.get(x, y, z);
+ double v2 = high.get(x, y, z);
+ double bl = control.get(x, y, z);
+ return lerp(bl, v1, v2);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ double v1 = low.get(x, y, z, w);
+ double v2 = high.get(x, y, z, w);
+ double bl = control.get(x, y, z, w);
+ return lerp(bl, v1, v2);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ double v1 = low.get(x, y, z, w, u, v);
+ double v2 = high.get(x, y, z, w, u, v);
+ double bl = control.get(x, y, z, w, u, v);
+ return lerp(bl, v1, v2);
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeScalar("high", high, props, map);
+ writeScalar("low", low, props, map);
+ writeScalar("control", control, props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readScalar("high", "setHighSource", props, map);
+ readScalar("low", "setLowSource", props, map);
+ readScalar("control", "setControlSource", props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleBrightContrast.java b/src/com/sudoplay/joise/module/ModuleBrightContrast.java
new file mode 100755
index 000000000..f80d975eb
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleBrightContrast.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleBrightContrast extends SourcedModule {
+
+ protected ScalarParameter bright = new ScalarParameter(0.0);
+ protected ScalarParameter threshold = new ScalarParameter(0.0);
+ protected ScalarParameter factor = new ScalarParameter(1.0);
+
+ public void setBrightness(double b) {
+ bright.set(b);
+ }
+
+ public void setBrightness(Module source) {
+ bright.set(source);
+ }
+
+ public void setContrastThreshold(double t) {
+ threshold.set(t);
+ }
+
+ public void setContrastThreshold(Module source) {
+ threshold.set(source);
+ }
+
+ public void setContrastFactor(double f) {
+ factor.set(f);
+ }
+
+ public void setContrastFactor(Module source) {
+ factor.set(source);
+ }
+
+ @Override
+ public double get(double x, double y) {
+ double val = source.get(x, y);
+ // apply brightness
+ val += bright.get(x, y);
+ // subtract threshold, scale by factor, add threshold
+ double t = threshold.get(x, y);
+ val -= t;
+ val *= factor.get(x, y);
+ val += t;
+ return val;
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ double val = source.get(x, y, z);
+ // apply brightness
+ val += bright.get(x, y, z);
+ // subtract threshold, scale by factor, add threshold
+ double t = threshold.get(x, y, z);
+ val -= t;
+ val *= factor.get(x, y, z);
+ val += t;
+ return val;
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ double val = source.get(x, y, z, w);
+ // apply brightness
+ val += bright.get(x, y, z, w);
+ // subtract threshold, scale by factor, add threshold
+ double t = threshold.get(x, y, z, w);
+ val -= t;
+ val *= factor.get(x, y, z, w);
+ val += t;
+ return val;
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ double val = source.get(x, y, z, w, u, v);
+ // apply brightness
+ val += bright.get(x, y, z, w, u, v);
+ // subtract threshold, scale by factor, add threshold
+ double t = threshold.get(x, y, z, w, u, v);
+ val -= t;
+ val *= factor.get(x, y, z, w, u, v);
+ val += t;
+ return val;
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeScalar("brightness", bright, props, map);
+ writeScalar("contrastFactor", factor, props, map);
+ writeScalar("contrastThreshold", threshold, props, map);
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readScalar("brightness", "setBrightness", props, map);
+ readScalar("contrastFactor", "setContrastFactor", props, map);
+ readScalar("contrastThreshold", "setContrastThreshold", props, map);
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleCache.java b/src/com/sudoplay/joise/module/ModuleCache.java
new file mode 100755
index 000000000..09b187447
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleCache.java
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleCache extends SourcedModule {
+
+ class Cache {
+ double x, y, z, w, u, v;
+ double val;
+ boolean valid = false;
+ }
+
+ protected Cache c2 = new Cache();
+ protected Cache c3 = new Cache();
+ protected Cache c4 = new Cache();
+ protected Cache c6 = new Cache();
+
+ @Override
+ public double get(double x, double y) {
+ if (!c2.valid || c2.x != x || c2.y != y) {
+ c2.x = x;
+ c2.y = y;
+ c2.valid = true;
+ c2.val = source.get(x, y);
+ }
+ return c2.val;
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ if (!c3.valid || c3.x != x || c3.y != y || c3.z != z) {
+ c3.x = x;
+ c3.y = y;
+ c3.z = z;
+ c3.valid = true;
+ c3.val = source.get(x, y, z);
+ }
+ return c3.val;
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ if (!c4.valid || c4.x != x || c4.y != y || c4.z != z || c4.w != w) {
+ c4.x = x;
+ c4.y = y;
+ c4.z = z;
+ c4.w = w;
+ c4.valid = true;
+ c4.val = source.get(x, y, z, w);
+ }
+ return c4.val;
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ if (!c6.valid || c6.x != x || c6.y != y || c6.z != z || c6.w != w
+ || c6.u != u || c6.v != v) {
+ c6.x = x;
+ c6.y = y;
+ c6.z = z;
+ c6.w = w;
+ c6.u = u;
+ c6.v = v;
+ c6.valid = true;
+ c6.val = source.get(x, y, z, w, u, v);
+ }
+ return c6.val;
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleCellGen.java b/src/com/sudoplay/joise/module/ModuleCellGen.java
new file mode 100755
index 000000000..8a766a8b7
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleCellGen.java
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+import com.sudoplay.joise.noise.Noise;
+
+public class ModuleCellGen extends SeedableModule {
+
+ private int id = Module.nextId.incrementAndGet();
+
+ public class CellularCache {
+ double[] f = new double[4];
+ double[] d = new double[4];
+ double x, y, z, w, u, v;
+ boolean valid = false;
+ }
+
+ protected CellularCache c2 = new CellularCache();
+ protected CellularCache c3 = new CellularCache();
+ protected CellularCache c4 = new CellularCache();
+ protected CellularCache c6 = new CellularCache();
+
+ @Override
+ public String getId() {
+ return "func_" + id;
+ }
+
+ @Override
+ public void setSeed(long seed) {
+ super.setSeed(seed);
+
+ c2.valid = false;
+ c3.valid = false;
+ c4.valid = false;
+ c6.valid = false;
+ }
+
+ public CellularCache getCache(double x, double y) {
+ if (!c2.valid || c2.x != x || c2.y != y) {
+ Noise.cellularFunction2D(x, y, seed, c2.f, c2.d);
+ c2.x = x;
+ c2.y = y;
+ c2.valid = true;
+ }
+ return c2;
+ }
+
+ public CellularCache getCache(double x, double y, double z) {
+ if (!c3.valid || c3.x != x || c3.y != y || c3.z != z) {
+ Noise.cellularFunction3D(x, y, z, seed, c3.f, c3.d);
+ c3.x = x;
+ c3.y = y;
+ c3.z = z;
+ c3.valid = true;
+ }
+ return c3;
+ }
+
+ public CellularCache getCache(double x, double y, double z, double w) {
+ if (!c4.valid || c4.x != x || c4.y != y || c4.z != z || c4.w != w) {
+ Noise.cellularFunction4D(x, y, z, w, seed, c4.f, c4.d);
+ c4.x = x;
+ c4.y = y;
+ c4.z = z;
+ c4.w = w;
+ c4.valid = true;
+ }
+ return c4;
+ }
+
+ public CellularCache getCache(double x, double y, double z, double w,
+ double u, double v) {
+ if (!c6.valid || c6.x != x || c6.y != y || c6.z != z || c6.w != w
+ || c6.u != u || c6.v != v) {
+ Noise.cellularFunction6D(x, y, z, w, u, v, seed, c6.f, c6.d);
+ c6.x = x;
+ c6.y = y;
+ c6.z = z;
+ c6.w = w;
+ c6.u = u;
+ c6.v = v;
+ c6.valid = true;
+ }
+ return c6;
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeSeed(props);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public ModuleCellGen buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readSeed(props);
+
+ return this;
+ }
+
+ @Override
+ public double get(double x, double y) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleCellular.java b/src/com/sudoplay/joise/module/ModuleCellular.java
new file mode 100755
index 000000000..b5870a0ce
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleCellular.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+import com.sudoplay.joise.module.ModuleCellGen.CellularCache;
+
+public class ModuleCellular extends Module {
+
+ protected double[] coefficients = new double[4];
+ protected ModuleCellGen generator;
+
+ public ModuleCellular() {
+ setCoefficients(1, 0, 0, 0);
+ }
+
+ public void setCellularSource(ModuleCellGen generator) {
+ this.generator = generator;
+ }
+
+ public void setCoefficients(double a, double b, double c, double d) {
+ coefficients[0] = a;
+ coefficients[1] = b;
+ coefficients[2] = c;
+ coefficients[3] = d;
+ }
+
+ public void setCoefficient(int index, double val) {
+ if (index > 3 || index < 0) {
+ throw new IllegalArgumentException();
+ }
+ coefficients[index] = val;
+ }
+
+ @Override
+ public double get(double x, double y) {
+ if (generator == null) {
+ return 0.0;
+ }
+ CellularCache c = generator.getCache(x, y);
+ return c.f[0] * coefficients[0] + c.f[1] * coefficients[1] + c.f[2]
+ * coefficients[2] + c.f[3] * coefficients[3];
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ if (generator == null) {
+ return 0.0;
+ }
+ CellularCache c = generator.getCache(x, y, z);
+ return c.f[0] * coefficients[0] + c.f[1] * coefficients[1] + c.f[2]
+ * coefficients[2] + c.f[3] * coefficients[3];
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ if (generator == null) {
+ return 0.0;
+ }
+ CellularCache c = generator.getCache(x, y, z, w);
+ return c.f[0] * coefficients[0] + c.f[1] * coefficients[1] + c.f[2]
+ * coefficients[2] + c.f[3] * coefficients[3];
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ if (generator == null) {
+ return 0.0;
+ }
+ CellularCache c = generator.getCache(x, y, z, w, u, v);
+ return c.f[0] * coefficients[0] + c.f[1] * coefficients[1] + c.f[2]
+ * coefficients[2] + c.f[3] * coefficients[3];
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ if (generator != null) {
+ props.put("generator", generator.getId());
+ generator._writeToMap(map);
+ } else {
+ props.put("generator", 0);
+ }
+
+ StringBuilder sb = new StringBuilder();
+ for (double d : coefficients) {
+ sb.append(String.valueOf(d)).append(" ");
+ }
+ props.put("coefficients", sb.toString().trim());
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ String coeff = props.getAsString("coefficients");
+ String[] arr = coeff.split(" ");
+ for (int i = 0; i < 4; i++) {
+ coefficients[i] = Double.parseDouble(arr[i]);
+ }
+
+ String gen = props.getAsString("generator");
+ setCellularSource((ModuleCellGen) map.get(gen));
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleClamp.java b/src/com/sudoplay/joise/module/ModuleClamp.java
new file mode 100755
index 000000000..e7beae514
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleClamp.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import static com.sudoplay.joise.noise.Util.clamp;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleClamp extends SourcedModule {
+
+ protected double low;
+ protected double high;
+
+ public ModuleClamp() {
+ setRange(-1.0, 1.0);
+ }
+
+ public ModuleClamp(double low, double high) {
+ setRange(low, high);
+ }
+
+ public void setRange(double low, double high) {
+ this.low = low;
+ this.high = high;
+ }
+
+ public void setLow(double low) {
+ this.low = low;
+ }
+
+ public void setHigh(double high) {
+ this.high = high;
+ }
+
+ @Override
+ public double get(double x, double y) {
+ return clamp(source.get(x, y), low, high);
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ return clamp(source.get(x, y, z), low, high);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ return clamp(source.get(x, y, z, w), low, high);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ return clamp(source.get(x, y, z, w, u, v), low, high);
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeDouble("low", low, props);
+ writeDouble("high", high, props);
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readDouble("low", "setLow", props);
+ readDouble("high", "setHigh", props);
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleCombiner.java b/src/com/sudoplay/joise/module/ModuleCombiner.java
new file mode 100755
index 000000000..ec0e1e1ac
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleCombiner.java
@@ -0,0 +1,489 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleCombiner extends Module {
+
+ public static enum CombinerType {
+ ADD, MULT, MAX, MIN, AVG
+ }
+
+ protected ScalarParameter[] sources = new ScalarParameter[MAX_SOURCES];
+ protected CombinerType type;
+
+ public ModuleCombiner(CombinerType type) {
+ setType(type);
+ }
+
+ public ModuleCombiner() {
+ // serialization
+ }
+
+ public void setType(CombinerType type) {
+ this.type = type;
+ }
+
+ public void setSource(int index, Module source) {
+ sources[index] = new ScalarParameter(source);
+ }
+
+ public void setSource(int index, double source) {
+ sources[index] = new ScalarParameter(source);
+ }
+
+ public void clearAllSources() {
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ sources[i] = null;
+ }
+ }
+
+ @Override
+ public double get(double x, double y) {
+ switch (type) {
+ case ADD:
+ return addGet(x, y);
+ case AVG:
+ return avgGet(x, y);
+ case MAX:
+ return maxGet(x, y);
+ case MIN:
+ return minGet(x, y);
+ case MULT:
+ return multGet(x, y);
+ default:
+ return 0.0;
+ }
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ switch (type) {
+ case ADD:
+ return addGet(x, y, z);
+ case AVG:
+ return avgGet(x, y, z);
+ case MAX:
+ return maxGet(x, y, z);
+ case MIN:
+ return minGet(x, y, z);
+ case MULT:
+ return multGet(x, y, z);
+ default:
+ return 0.0;
+ }
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ switch (type) {
+ case ADD:
+ return addGet(x, y, z, w);
+ case AVG:
+ return avgGet(x, y, z, w);
+ case MAX:
+ return maxGet(x, y, z, w);
+ case MIN:
+ return minGet(x, y, z, w);
+ case MULT:
+ return multGet(x, y, z, w);
+ default:
+ return 0.0;
+ }
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ switch (type) {
+ case ADD:
+ return addGet(x, y, z, w, u, v);
+ case AVG:
+ return avgGet(x, y, z, w, u, v);
+ case MAX:
+ return maxGet(x, y, z, w, u, v);
+ case MIN:
+ return minGet(x, y, z, w, u, v);
+ case MULT:
+ return multGet(x, y, z, w, u, v);
+ default:
+ return 0.0;
+ }
+ }
+
+ // ==========================================================================
+ // = ADD
+ // ==========================================================================
+
+ protected double addGet(double x, double y) {
+ double value = 0.0;
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ if (sources[i] != null) value += sources[i].get(x, y);
+ }
+ return value;
+ }
+
+ protected double addGet(double x, double y, double z) {
+ double value = 0.0;
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ if (sources[i] != null) value += sources[i].get(x, y, z);
+ }
+ return value;
+ }
+
+ protected double addGet(double x, double y, double z, double w) {
+ double value = 0.0;
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ if (sources[i] != null) value += sources[i].get(x, y, z, w);
+ }
+ return value;
+ }
+
+ protected double addGet(double x, double y, double z, double w, double u,
+ double v) {
+ double value = 0.0;
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ if (sources[i] != null) value += sources[i].get(x, y, z, w, u, v);
+ }
+ return value;
+ }
+
+ // ==========================================================================
+ // = AVG
+ // ==========================================================================
+
+ protected double avgGet(double x, double y) {
+ int count = 0;
+ double value = 0;
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ if (sources[i] != null) {
+ value += sources[i].get(x, y);
+ count++;
+ }
+ }
+ if (count == 0) return 0.0;
+ return value / (double) count;
+ }
+
+ protected double avgGet(double x, double y, double z) {
+ int count = 0;
+ double value = 0;
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ if (sources[i] != null) {
+ value += sources[i].get(x, y, z);
+ count++;
+ }
+ }
+ if (count == 0) return 0.0;
+ return value / (double) count;
+ }
+
+ protected double avgGet(double x, double y, double z, double w) {
+ int count = 0;
+ double value = 0;
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ if (sources[i] != null) {
+ value += sources[i].get(x, y, z, w);
+ count++;
+ }
+ }
+ if (count == 0) return 0.0;
+ return value / (double) count;
+ }
+
+ protected double avgGet(double x, double y, double z, double w, double u,
+ double v) {
+ int count = 0;
+ double value = 0;
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ if (sources[i] != null) {
+ value += sources[i].get(x, y, z, w, u, v);
+ count++;
+ }
+ }
+ if (count == 0) return 0.0;
+ return value / (double) count;
+ }
+
+ // ==========================================================================
+ // = MAX
+ // ==========================================================================
+
+ protected double maxGet(double x, double y) {
+ double mx;
+ int c = 0;
+ while (c < MAX_SOURCES && sources[c] == null) {
+ c++;
+ }
+ if (c == MAX_SOURCES) return 0.0;
+ mx = sources[c].get(x, y);
+
+ for (int d = c; d < MAX_SOURCES; d++) {
+ if (sources[d] != null) {
+ double val = sources[d].get(x, y);
+ if (val > mx) mx = val;
+ }
+ }
+
+ return mx;
+ }
+
+ protected double maxGet(double x, double y, double z) {
+ double mx;
+ int c = 0;
+ while (c < MAX_SOURCES && sources[c] == null) {
+ c++;
+ }
+ if (c == MAX_SOURCES) return 0.0;
+ mx = sources[c].get(x, y, z);
+
+ for (int d = c; d < MAX_SOURCES; d++) {
+ if (sources[d] != null) {
+ double val = sources[d].get(x, y, z);
+ if (val > mx) mx = val;
+ }
+ }
+
+ return mx;
+ }
+
+ protected double maxGet(double x, double y, double z, double w) {
+ double mx;
+ int c = 0;
+ while (c < MAX_SOURCES && sources[c] == null) {
+ c++;
+ }
+ if (c == MAX_SOURCES) return 0.0;
+ mx = sources[c].get(x, y, z, w);
+
+ for (int d = c; d < MAX_SOURCES; d++) {
+ if (sources[d] != null) {
+ double val = sources[d].get(x, y, z, w);
+ if (val > mx) mx = val;
+ }
+ }
+
+ return mx;
+ }
+
+ protected double maxGet(double x, double y, double z, double w, double u,
+ double v) {
+ double mx;
+ int c = 0;
+ while (c < MAX_SOURCES && sources[c] == null) {
+ c++;
+ }
+ if (c == MAX_SOURCES) return 0.0;
+ mx = sources[c].get(x, y, z, w, u, v);
+
+ for (int d = c; d < MAX_SOURCES; d++) {
+ if (sources[d] != null) {
+ double val = sources[d].get(x, y, z, w, u, v);
+ if (val > mx) mx = val;
+ }
+ }
+
+ return mx;
+ }
+
+ // ==========================================================================
+ // = MIN
+ // ==========================================================================
+
+ protected double minGet(double x, double y) {
+ double mn;
+ int c = 0;
+ while (c < MAX_SOURCES && sources[c] == null) {
+ c++;
+ }
+ if (c == MAX_SOURCES) return 0.0;
+ mn = sources[c].get(x, y);
+
+ for (int d = c; d < MAX_SOURCES; d++) {
+ if (sources[d] != null) {
+ double val = sources[d].get(x, y);
+ if (val < mn) mn = val;
+ }
+ }
+
+ return mn;
+ }
+
+ protected double minGet(double x, double y, double z) {
+ double mn;
+ int c = 0;
+ while (c < MAX_SOURCES && sources[c] == null) {
+ c++;
+ }
+ if (c == MAX_SOURCES) return 0.0;
+ mn = sources[c].get(x, y, z);
+
+ for (int d = c; d < MAX_SOURCES; d++) {
+ if (sources[d] != null) {
+ double val = sources[d].get(x, y, z);
+ if (val < mn) mn = val;
+ }
+ }
+
+ return mn;
+ }
+
+ protected double minGet(double x, double y, double z, double w) {
+ double mn;
+ int c = 0;
+ while (c < MAX_SOURCES && sources[c] == null) {
+ c++;
+ }
+ if (c == MAX_SOURCES) return 0.0;
+ mn = sources[c].get(x, y, z, w);
+
+ for (int d = c; d < MAX_SOURCES; d++) {
+ if (sources[d] != null) {
+ double val = sources[d].get(x, y, z, w);
+ if (val < mn) mn = val;
+ }
+ }
+
+ return mn;
+ }
+
+ protected double minGet(double x, double y, double z, double w, double u,
+ double v) {
+ double mn;
+ int c = 0;
+ while (c < MAX_SOURCES && sources[c] == null) {
+ c++;
+ }
+ if (c == MAX_SOURCES) return 0.0;
+ mn = sources[c].get(x, y, z, w, u, v);
+
+ for (int d = c; d < MAX_SOURCES; d++) {
+ if (sources[d] != null) {
+ double val = sources[d].get(x, y, z, w, u, v);
+ if (val < mn) mn = val;
+ }
+ }
+
+ return mn;
+ }
+
+ // ==========================================================================
+ // = MULT
+ // ==========================================================================
+
+ protected double multGet(double x, double y) {
+ double value = 1.0;
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ if (sources[i] != null) value *= sources[i].get(x, y);
+ }
+ return value;
+ }
+
+ protected double multGet(double x, double y, double z) {
+ double value = 1.0;
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ if (sources[i] != null) value *= sources[i].get(x, y, z);
+ }
+ return value;
+ }
+
+ protected double multGet(double x, double y, double z, double w) {
+ double value = 1.0;
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ if (sources[i] != null) value *= sources[i].get(x, y, z, w);
+ }
+ return value;
+ }
+
+ protected double multGet(double x, double y, double z, double w, double u,
+ double v) {
+ double value = 1.0;
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ if (sources[i] != null) value *= sources[i].get(x, y, z, w, u, v);
+ }
+ return value;
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeEnum("type", type, props);
+
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ writeScalar("source" + i, sources[i], props, map);
+ }
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readEnum("type", "setType", CombinerType.class, props);
+
+ String name;
+ Object o;
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ o = props.get("source" + i);
+ if (o != null) {
+ name = o.toString();
+ setSource(i, map.get(name));
+ }
+ }
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleCos.java b/src/com/sudoplay/joise/module/ModuleCos.java
new file mode 100755
index 000000000..d0fbe8ee5
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleCos.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleCos extends SourcedModule {
+
+ @Override
+ public double get(double x, double y) {
+ return Math.cos(source.get(x, y));
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ return Math.cos(source.get(x, y, z));
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ return Math.cos(source.get(x, y, z, w));
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ return Math.cos(source.get(x, y, z, w, u, v));
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleFloor.java b/src/com/sudoplay/joise/module/ModuleFloor.java
new file mode 100755
index 000000000..e463749d7
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleFloor.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleFloor extends SourcedModule {
+
+ @Override
+ public double get(double x, double y) {
+ return Math.floor(source.get(x, y));
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ return Math.floor(source.get(x, y, z));
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ return Math.floor(source.get(x, y, z, w));
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ return Math.floor(source.get(x, y, z, w, u, v));
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleFractal.java b/src/com/sudoplay/joise/module/ModuleFractal.java
new file mode 100755
index 000000000..41c841999
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleFractal.java
@@ -0,0 +1,1035 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+import com.sudoplay.joise.module.ModuleBasisFunction.BasisType;
+import com.sudoplay.joise.module.ModuleBasisFunction.InterpolationType;
+import com.sudoplay.joise.noise.Util;
+
+public class ModuleFractal extends SeedableModule {
+
+ public static final FractalType DEFAULT_FRACTAL_TYPE = FractalType.FBM;
+ public static final BasisType DEFAULT_BASIS_TYPE = BasisType.GRADVAL;
+ public static final InterpolationType DEFAULT_INTERPOLATION_TYPE = InterpolationType.QUINTIC;
+ public static final int DEFAULT_OCTAVES = 2;
+ public static final double DEFAULT_FREQUENCY = 1.0;
+ public static final double DEFAULT_LACUNARITY = 2.0;
+
+ public static enum FractalType {
+ FBM, RIDGEMULTI, BILLOW, MULTI, HYBRIDMULTI, DECARPENTIERSWISS
+ }
+
+ protected ModuleBasisFunction[] basis = new ModuleBasisFunction[MAX_SOURCES];
+ protected Module[] source = new Module[MAX_SOURCES];
+
+ protected double[] exparray = new double[MAX_SOURCES];
+ protected double[][] correct = new double[MAX_SOURCES][2];
+
+ protected double offset, gain, H;
+ protected double frequency, lacunarity;
+ protected int numOctaves;
+ protected FractalType type;
+
+ public ModuleFractal() {
+ this(DEFAULT_FRACTAL_TYPE, DEFAULT_BASIS_TYPE, DEFAULT_INTERPOLATION_TYPE);
+ }
+
+ public ModuleFractal(FractalType type, BasisType basisType,
+ InterpolationType interpolationType) {
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ basis[i] = new ModuleBasisFunction();
+ }
+ setNumOctaves(2);
+ setFrequency(1.0);
+ setLacunarity(2.0);
+ setType(type);
+ setAllSourceTypes(basisType, interpolationType);
+ resetAllSources();
+ }
+
+ public void setNumOctaves(long n) {
+ if (n > MAX_SOURCES) {
+ throw new IllegalArgumentException("number of octaves must be <= "
+ + MAX_SOURCES);
+ }
+ numOctaves = (int) n;
+ }
+
+ public void setFrequency(double f) {
+ frequency = f;
+ }
+
+ public void setLacunarity(double l) {
+ lacunarity = l;
+ }
+
+ public void setGain(double g) {
+ gain = g;
+ }
+
+ public void setOffset(double o) {
+ offset = o;
+ }
+
+ public void setH(double h) {
+ H = h;
+ }
+
+ public void setType(FractalType type) {
+ this.type = type;
+ switch (type) {
+ case BILLOW:
+ H = 1.0;
+ gain = 0.5;
+ offset = 0.0;
+ break;
+ case DECARPENTIERSWISS:
+ H = 0.9;
+ gain = 1.0;
+ offset = 0.7;
+ break;
+ case FBM:
+ H = 1.0;
+ gain = 0.5;
+ offset = 0.0;
+ break;
+ case HYBRIDMULTI:
+ H = 0.25;
+ gain = 1.0;
+ offset = 0.7;
+ break;
+ case MULTI:
+ H = 1.0;
+ gain = 0.0;
+ offset = 0.0;
+ break;
+ case RIDGEMULTI:
+ H = 0.9;
+ gain = 0.5;
+ offset = 1.0;
+ break;
+ default:
+ throw new AssertionError();
+ }
+ calcWeights(type);
+ }
+
+ public void setAllSourceTypes(BasisType basisType,
+ InterpolationType interpolationType) {
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ basis[i].setType(basisType);
+ basis[i].setInterpolation(interpolationType);
+ }
+ }
+
+ public void setAllSourceBasisTypes(BasisType basisType) {
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ basis[i].setType(basisType);
+ }
+ }
+
+ public void setAllSourceInterpolationTypes(InterpolationType interpolationType) {
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ basis[i].setInterpolation(interpolationType);
+ }
+ }
+
+ public void setSourceType(int index, BasisType basisType,
+ InterpolationType interpolationType) {
+ assertMaxSources(index);
+ basis[index].setType(basisType);
+ basis[index].setInterpolation(interpolationType);
+ }
+
+ public void overrideSource(int index, Module source) {
+ if (index < 0 || index >= MAX_SOURCES) {
+ throw new IllegalArgumentException("expecting index < " + MAX_SOURCES
+ + " but was " + index);
+ }
+ this.source[index] = source;
+ }
+
+ public void resetSource(int index) {
+ assertMaxSources(index);
+ source[index] = basis[index];
+ }
+
+ public void resetAllSources() {
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ source[i] = basis[i];
+ }
+ }
+
+ @Override
+ public void setSeed(long seed) {
+ super.setSeed(seed);
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ if (source[i] instanceof SeedableModule) {
+ ((SeedableModule) source[i]).setSeed(seed);
+ }
+ }
+ }
+
+ public ModuleBasisFunction getBasis(int index) {
+ assertMaxSources(index);
+ return basis[index];
+ }
+
+ @Override
+ public double get(double x, double y) {
+ switch (type) {
+ case BILLOW:
+ return getBillow(x, y);
+ case DECARPENTIERSWISS:
+ return getDeCarpentierSwiss(x, y);
+ case FBM:
+ return getFBM(x, y);
+ case HYBRIDMULTI:
+ return getHybridMulti(x, y);
+ case MULTI:
+ return getMulti(x, y);
+ case RIDGEMULTI:
+ return getRidgedMulti(x, y);
+ default:
+ throw new AssertionError();
+ }
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ switch (type) {
+ case BILLOW:
+ return getBillow(x, y, z);
+ case DECARPENTIERSWISS:
+ return getDeCarpentierSwiss(x, y, z);
+ case FBM:
+ return getFBM(x, y, z);
+ case HYBRIDMULTI:
+ return getHybridMulti(x, y, z);
+ case MULTI:
+ return getMulti(x, y, z);
+ case RIDGEMULTI:
+ return getRidgedMulti(x, y, z);
+ default:
+ throw new AssertionError();
+ }
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ switch (type) {
+ case BILLOW:
+ return getBillow(x, y, z, w);
+ case DECARPENTIERSWISS:
+ return getDeCarpentierSwiss(x, y, z, w);
+ case FBM:
+ return getFBM(x, y, z, w);
+ case HYBRIDMULTI:
+ return getHybridMulti(x, y, z, w);
+ case MULTI:
+ return getMulti(x, y, z, w);
+ case RIDGEMULTI:
+ return getRidgedMulti(x, y, z, w);
+ default:
+ throw new AssertionError();
+ }
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ switch (type) {
+ case BILLOW:
+ return getBillow(x, y, z, w, u, v);
+ case DECARPENTIERSWISS:
+ return getDeCarpentierSwiss(x, y, z, w, u, v);
+ case FBM:
+ return getFBM(x, y, z, w, u, v);
+ case HYBRIDMULTI:
+ return getHybridMulti(x, y, z, w, u, v);
+ case MULTI:
+ return getMulti(x, y, z, w, u, v);
+ case RIDGEMULTI:
+ return getRidgedMulti(x, y, z, w, u, v);
+ default:
+ throw new AssertionError();
+ }
+ }
+
+ protected double getFBM(double x, double y) {
+ double sum = 0;
+ double amp = 1.0;
+
+ x *= frequency;
+ y *= frequency;
+
+ for (int i = 0; i < numOctaves; ++i) {
+ double n = source[i].get(x, y);
+ sum += n * amp;
+ amp *= gain;
+
+ x *= lacunarity;
+ y *= lacunarity;
+ }
+ return sum;
+ }
+
+ protected double getFBM(double x, double y, double z) {
+ double sum = 0;
+ double amp = 1.0;
+
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+
+ for (int i = 0; i < numOctaves; ++i) {
+ double n = source[i].get(x, y, z);
+ sum += n * amp;
+ amp *= gain;
+
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ }
+ return sum;
+ }
+
+ protected double getFBM(double x, double y, double z, double w) {
+ double sum = 0;
+ double amp = 1.0;
+
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+ w *= frequency;
+
+ for (int i = 0; i < numOctaves; ++i) {
+ double n = source[i].get(x, y, z, w);
+ sum += n * amp;
+ amp *= gain;
+
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ w *= lacunarity;
+ }
+ return sum;
+ }
+
+ protected double getFBM(double x, double y, double z, double w, double u,
+ double v) {
+ double sum = 0;
+ double amp = 1.0;
+
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+ w *= frequency;
+ u *= frequency;
+ v *= frequency;
+
+ for (int i = 0; i < numOctaves; ++i) {
+ double n = source[i].get(x, y, z, w);
+ sum += n * amp;
+ amp *= gain;
+
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ w *= lacunarity;
+ u *= lacunarity;
+ v *= lacunarity;
+ }
+ return sum;
+ }
+
+ protected double getMulti(double x, double y) {
+ double value = 1.0;
+ x *= frequency;
+ y *= frequency;
+ for (int i = 0; i < numOctaves; ++i) {
+ value *= source[i].get(x, y) * exparray[i] + 1.0;
+ x *= lacunarity;
+ y *= lacunarity;
+ }
+ return value * correct[numOctaves - 1][0] + correct[numOctaves - 1][1];
+ }
+
+ protected double getMulti(double x, double y, double z) {
+ double value = 1.0;
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+ for (int i = 0; i < numOctaves; ++i) {
+ value *= source[i].get(x, y, z) * exparray[i] + 1.0;
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ }
+ return value * correct[numOctaves - 1][0] + correct[numOctaves - 1][1];
+ }
+
+ protected double getMulti(double x, double y, double z, double w) {
+ double value = 1.0;
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+ w *= frequency;
+ for (int i = 0; i < numOctaves; ++i) {
+ value *= source[i].get(x, y, z, w) * exparray[i] + 1.0;
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ w *= lacunarity;
+ }
+ return value * correct[numOctaves - 1][0] + correct[numOctaves - 1][1];
+ }
+
+ protected double getMulti(double x, double y, double z, double w, double u,
+ double v) {
+ double value = 1.0;
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+ w *= frequency;
+ u *= frequency;
+ v *= frequency;
+ for (int i = 0; i < numOctaves; ++i) {
+ value *= source[i].get(x, y, z, w, u, v) * exparray[i] + 1.0;
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ w *= lacunarity;
+ u *= lacunarity;
+ v *= lacunarity;
+ }
+ return value * correct[numOctaves - 1][0] + correct[numOctaves - 1][1];
+ }
+
+ protected double getBillow(double x, double y) {
+ double sum = 0.0;
+ double amp = 1.0;
+
+ x *= frequency;
+ y *= frequency;
+
+ for (int i = 0; i < numOctaves; ++i) {
+ double n = source[i].get(x, y);
+ sum += (2.0 * Math.abs(n) - 1.0) * amp;
+ amp *= gain;
+
+ x *= lacunarity;
+ y *= lacunarity;
+ }
+ return sum;
+ }
+
+ protected double getBillow(double x, double y, double z) {
+ double sum = 0.0;
+ double amp = 1.0;
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+ for (int i = 0; i < numOctaves; ++i) {
+ double n = source[i].get(x, y, z);
+ sum += (2.0 * Math.abs(n) - 1.0) * amp;
+ amp *= gain;
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ }
+ return sum;
+ }
+
+ protected double getBillow(double x, double y, double z, double w) {
+ double sum = 0.0;
+ double amp = 1.0;
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+ w *= frequency;
+ for (int i = 0; i < numOctaves; ++i) {
+ double n = source[i].get(x, y, z, w);
+ sum += (2.0 * Math.abs(n) - 1.0) * amp;
+ amp *= gain;
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ w *= lacunarity;
+ }
+ return sum;
+ }
+
+ protected double getBillow(double x, double y, double z, double w, double u,
+ double v) {
+ double sum = 0.0;
+ double amp = 1.0;
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+ w *= frequency;
+ u *= frequency;
+ v *= frequency;
+ for (int i = 0; i < numOctaves; ++i) {
+ double n = source[i].get(x, y, z, w, u, v);
+ sum += (2.0 * Math.abs(n) - 1.0) * amp;
+ amp *= gain;
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ w *= lacunarity;
+ u *= lacunarity;
+ v *= lacunarity;
+ }
+ return sum;
+ }
+
+ protected double getRidgedMulti(double x, double y) {
+ double sum = 0;
+ double amp = 1.0;
+ x *= frequency;
+ y *= frequency;
+ for (int i = 0; i < numOctaves; ++i) {
+ double n = source[i].get(x, y);
+ n = 1.0 - Math.abs(n);
+ sum += amp * n;
+ amp *= gain;
+ x *= lacunarity;
+ y *= lacunarity;
+ }
+ return sum;
+ }
+
+ protected double getRidgedMulti(double x, double y, double z) {
+ double sum = 0;
+ double amp = 1.0;
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+ for (int i = 0; i < numOctaves; ++i) {
+ double n = source[i].get(x, y, z);
+ n = 1.0 - Math.abs(n);
+ sum += amp * n;
+ amp *= gain;
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ }
+ return sum;
+ }
+
+ protected double getRidgedMulti(double x, double y, double z, double w) {
+ double result = 0.0, signal;
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+ w *= frequency;
+ for (int i = 0; i < numOctaves; ++i) {
+ signal = source[i].get(x, y, z, w);
+ signal = offset - Math.abs(signal);
+ signal *= signal;
+ result += signal * exparray[i];
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ w *= lacunarity;
+ }
+ return result * correct[numOctaves - 1][0] + correct[numOctaves - 1][1];
+ }
+
+ protected double getRidgedMulti(double x, double y, double z, double w,
+ double u, double v) {
+ double result = 0.0, signal;
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+ w *= frequency;
+ u *= frequency;
+ v *= frequency;
+ for (int i = 0; i < numOctaves; ++i) {
+ signal = source[i].get(x, y, z, w, u, v);
+ signal = offset - Math.abs(signal);
+ signal *= signal;
+ result += signal * exparray[i];
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ w *= lacunarity;
+ u *= lacunarity;
+ v *= lacunarity;
+ }
+ return result * correct[numOctaves - 1][0] + correct[numOctaves - 1][1];
+ }
+
+ protected double getHybridMulti(double x, double y) {
+ double value, signal, weight;
+ x *= frequency;
+ y *= frequency;
+ value = source[0].get(x, y) + offset;
+ weight = gain * value;
+ x *= lacunarity;
+ y *= lacunarity;
+ for (int i = 1; i < numOctaves; ++i) {
+ if (weight > 1.0) weight = 1.0;
+ signal = (source[i].get(x, y) + offset) * exparray[i];
+ value += weight * signal;
+ weight *= gain * signal;
+ x *= lacunarity;
+ y *= lacunarity;
+ }
+ return value * correct[numOctaves - 1][0] + correct[numOctaves - 1][1];
+ }
+
+ protected double getHybridMulti(double x, double y, double z) {
+ double value, signal, weight;
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+ value = source[0].get(x, y, z) + offset;
+ weight = gain * value;
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ for (int i = 1; i < numOctaves; ++i) {
+ if (weight > 1.0) weight = 1.0;
+ signal = (source[i].get(x, y, z) + offset) * exparray[i];
+ value += weight * signal;
+ weight *= gain * signal;
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ }
+ return value * correct[numOctaves - 1][0] + correct[numOctaves - 1][1];
+ }
+
+ protected double getHybridMulti(double x, double y, double z, double w) {
+ double value, signal, weight;
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+ w *= frequency;
+ value = source[0].get(x, y, z, w) + offset;
+ weight = gain * value;
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ w *= lacunarity;
+ for (int i = 1; i < numOctaves; ++i) {
+ if (weight > 1.0) weight = 1.0;
+ signal = (source[i].get(x, y, z, w) + offset) * exparray[i];
+ value += weight * signal;
+ weight *= gain * signal;
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ w *= lacunarity;
+ }
+ return value * correct[numOctaves - 1][0] + correct[numOctaves - 1][1];
+ }
+
+ protected double getHybridMulti(double x, double y, double z, double w,
+ double u, double v) {
+ double value, signal, weight;
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+ w *= frequency;
+ u *= frequency;
+ v *= frequency;
+ value = source[0].get(x, y, z, w, u, v) + offset;
+ weight = gain * value;
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ w *= lacunarity;
+ u *= lacunarity;
+ v *= lacunarity;
+ for (int i = 1; i < numOctaves; ++i) {
+ if (weight > 1.0) weight = 1.0;
+ signal = (source[i].get(x, y, z, w, u, v) + offset) * exparray[i];
+ value += weight * signal;
+ weight *= gain * signal;
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ w *= lacunarity;
+ u *= lacunarity;
+ v *= lacunarity;
+ }
+ return value * correct[numOctaves - 1][0] + correct[numOctaves - 1][1];
+ }
+
+ protected double getDeCarpentierSwiss(double x, double y) {
+ double sum = 0;
+ double amp = 1.0;
+ double dx_sum = 0;
+ double dy_sum = 0;
+ x *= frequency;
+ y *= frequency;
+ for (int i = 0; i < numOctaves; ++i) {
+ double n = source[i].get(x + offset * dx_sum, y + offset * dy_sum);
+ double dx = source[i].getDX(x + offset * dx_sum, y + offset * dy_sum);
+ double dy = source[i].getDY(x + offset * dx_sum, y + offset * dy_sum);
+ sum += amp * (1.0 - Math.abs(n));
+ dx_sum += amp * dx * -n;
+ dy_sum += amp * dy * -n;
+ amp *= gain * Util.clamp(sum, 0.0, 1.0);
+ x *= lacunarity;
+ y *= lacunarity;
+ }
+ return sum;
+ }
+
+ protected double getDeCarpentierSwiss(double x, double y, double z) {
+ double sum = 0;
+ double amp = 1.0;
+ double dx_sum = 0;
+ double dy_sum = 0;
+ double dz_sum = 0;
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+ for (int i = 0; i < numOctaves; ++i) {
+ double n = source[i].get(x + offset * dx_sum, y + offset * dy_sum, z
+ + offset * dz_sum);
+ double dx = source[i].getDX(x + offset * dx_sum, y + offset * dy_sum, z
+ + offset * dz_sum);
+ double dy = source[i].getDY(x + offset * dx_sum, y + offset * dy_sum, z
+ + offset * dz_sum);
+ double dz = source[i].getDZ(x + offset * dx_sum, y + offset * dy_sum, z
+ + offset * dz_sum);
+ sum += amp * (1.0 - Math.abs(n));
+ dx_sum += amp * dx * -n;
+ dy_sum += amp * dy * -n;
+ dz_sum += amp * dz * -n;
+ amp *= gain * Util.clamp(sum, 0.0, 1.0);
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ }
+ return sum;
+ }
+
+ protected double getDeCarpentierSwiss(double x, double y, double z, double w) {
+ double sum = 0;
+ double amp = 1.0;
+ double dx_sum = 0;
+ double dy_sum = 0;
+ double dz_sum = 0;
+ double dw_sum = 0;
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+ w *= frequency;
+ for (int i = 0; i < numOctaves; ++i) {
+ double n = source[i].get(x + offset * dx_sum, y + offset * dy_sum, z
+ + offset * dz_sum, w + offset * dw_sum);
+ double dx = source[i].getDX(x + offset * dx_sum, y + offset * dy_sum, z
+ + offset * dz_sum, w + offset * dw_sum);
+ double dy = source[i].getDY(x + offset * dx_sum, y + offset * dy_sum, z
+ + offset * dz_sum, w + offset * dw_sum);
+ double dz = source[i].getDZ(x + offset * dx_sum, y + offset * dy_sum, z
+ + offset * dz_sum, w + offset * dw_sum);
+ double dw = source[i].getDW(x + offset * dx_sum, y + offset * dy_sum, z
+ + offset * dz_sum, w + offset * dw_sum);
+ sum += amp * (1.0 - Math.abs(n));
+ dx_sum += amp * dx * -n;
+ dy_sum += amp * dy * -n;
+ dz_sum += amp * dz * -n;
+ dw_sum += amp * dw * -n;
+ amp *= gain * Util.clamp(sum, 0.0, 1.0);
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ w *= lacunarity;
+ }
+ return sum;
+ }
+
+ protected double getDeCarpentierSwiss(double x, double y, double z, double w,
+ double u, double v) {
+ double sum = 0;
+ double amp = 1.0;
+ double dx_sum = 0;
+ double dy_sum = 0;
+ double dz_sum = 0;
+ double dw_sum = 0;
+ double du_sum = 0;
+ double dv_sum = 0;
+ x *= frequency;
+ y *= frequency;
+ z *= frequency;
+ w *= frequency;
+ u *= frequency;
+ v *= frequency;
+ for (int i = 0; i < numOctaves; ++i) {
+ double n = source[i].get(x + offset * dx_sum, y + offset * dy_sum, z
+ + offset * dz_sum);
+ double dx = source[i].getDX(x + offset * dx_sum, y + offset * dy_sum, z
+ + offset * dx_sum, w + offset * dw_sum, u + offset * du_sum, v
+ + offset * dv_sum);
+ double dy = source[i].getDY(x + offset * dx_sum, y + offset * dy_sum, z
+ + offset * dz_sum, w + offset * dw_sum, u + offset * du_sum, v
+ + offset * dv_sum);
+ double dz = source[i].getDZ(x + offset * dx_sum, y + offset * dy_sum, z
+ + offset * dz_sum, w + offset * dw_sum, u + offset * du_sum, v
+ + offset * dv_sum);
+ double dw = source[i].getDW(x + offset * dx_sum, y + offset * dy_sum, z
+ + offset * dz_sum, w + offset * dw_sum, u + offset * du_sum, v
+ + offset * dv_sum);
+ double du = source[i].getDU(x + offset * dx_sum, y + offset * dy_sum, z
+ + offset * dz_sum, w + offset * dw_sum, u + offset * du_sum, v
+ + offset * dv_sum);
+ double dv = source[i].getDV(x + offset * dx_sum, y + offset * dy_sum, z
+ + offset * dz_sum, w + offset * dw_sum, u + offset * du_sum, v
+ + offset * dv_sum);
+ sum += amp * (1.0 - Math.abs(n));
+ dx_sum += amp * dx * -n;
+ dy_sum += amp * dy * -n;
+ dz_sum += amp * dz * -n;
+ dw_sum += amp * dw * -n;
+ du_sum += amp * du * -n;
+ dv_sum += amp * dv * -n;
+ amp *= gain * Util.clamp(sum, 0.0, 1.0);
+ x *= lacunarity;
+ y *= lacunarity;
+ z *= lacunarity;
+ w *= lacunarity;
+ u *= lacunarity;
+ v *= lacunarity;
+ }
+ return sum;
+ }
+
+ protected void calcWeights(FractalType type) {
+ double minvalue, maxvalue;
+ switch (type) {
+ case FBM:
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ exparray[i] = Math.pow(lacunarity, -i * H);
+ }
+ minvalue = 0.0;
+ maxvalue = 0.0;
+ for (int i = 0; i < MAX_SOURCES; i++) {
+ minvalue += -1.0 * exparray[i];
+ maxvalue += 1.0 * exparray[i];
+
+ double A = -1.0, B = 1.0;
+ double scale = (B - A) / (maxvalue - minvalue);
+ double bias = A - minvalue * scale;
+ correct[i][0] = scale;
+ correct[i][1] = bias;
+ }
+ break;
+
+ case RIDGEMULTI:
+ for (int i = 0; i < MAX_SOURCES; ++i) {
+ exparray[i] = Math.pow(lacunarity, -i * H);
+ }
+ minvalue = 0.0;
+ maxvalue = 0.0;
+ for (int i = 0; i < MAX_SOURCES; ++i) {
+ minvalue += (offset - 1.0) * (offset - 1.0) * exparray[i];
+ maxvalue += (offset) * (offset) * exparray[i];
+
+ double A = -1.0, B = 1.0;
+ double scale = (B - A) / (maxvalue - minvalue);
+ double bias = A - minvalue * scale;
+ correct[i][0] = scale;
+ correct[i][1] = bias;
+ }
+ break;
+
+ case DECARPENTIERSWISS:
+ for (int i = 0; i < MAX_SOURCES; ++i) {
+ exparray[i] = Math.pow(lacunarity, -i * H);
+ }
+ minvalue = 0.0;
+ maxvalue = 0.0;
+ for (int i = 0; i < MAX_SOURCES; ++i) {
+ minvalue += (offset - 1.0) * (offset - 1.0) * exparray[i];
+ maxvalue += (offset) * (offset) * exparray[i];
+
+ double A = -1.0, B = 1.0;
+ double scale = (B - A) / (maxvalue - minvalue);
+ double bias = A - minvalue * scale;
+ correct[i][0] = scale;
+ correct[i][1] = bias;
+ }
+ break;
+
+ case BILLOW:
+ for (int i = 0; i < MAX_SOURCES; ++i) {
+ exparray[i] = Math.pow(lacunarity, -i * H);
+ }
+ minvalue = 0.0;
+ maxvalue = 0.0;
+ for (int i = 0; i < MAX_SOURCES; ++i) {
+ minvalue += -1.0 * exparray[i];
+ maxvalue += 1.0 * exparray[i];
+
+ double A = -1.0, B = 1.0;
+ double scale = (B - A) / (maxvalue - minvalue);
+ double bias = A - minvalue * scale;
+ correct[i][0] = scale;
+ correct[i][1] = bias;
+ }
+ break;
+
+ case MULTI:
+ for (int i = 0; i < MAX_SOURCES; ++i) {
+ exparray[i] = Math.pow(lacunarity, -i * H);
+ }
+ minvalue = 1.0;
+ maxvalue = 1.0;
+ for (int i = 0; i < MAX_SOURCES; ++i) {
+ minvalue *= -1.0 * exparray[i] + 1.0;
+ maxvalue *= 1.0 * exparray[i] + 1.0;
+
+ double A = -1.0, B = 1.0;
+ double scale = (B - A) / (maxvalue - minvalue);
+ double bias = A - minvalue * scale;
+ correct[i][0] = scale;
+ correct[i][1] = bias;
+ }
+ break;
+
+ case HYBRIDMULTI:
+ for (int i = 0; i < MAX_SOURCES; ++i) {
+ exparray[i] = Math.pow(lacunarity, -i * H);
+ }
+ minvalue = 1.0;
+ maxvalue = 1.0;
+ double weightmin,
+ weightmax;
+ double A = -1.0,
+ B = 1.0,
+ scale,
+ bias;
+
+ minvalue = offset - 1.0;
+ maxvalue = offset + 1.0;
+ weightmin = gain * minvalue;
+ weightmax = gain * maxvalue;
+
+ scale = (B - A) / (maxvalue - minvalue);
+ bias = A - minvalue * scale;
+ correct[0][0] = scale;
+ correct[0][1] = bias;
+
+ for (int i = 1; i < MAX_SOURCES; ++i) {
+ if (weightmin > 1.0) weightmin = 1.0;
+ if (weightmax > 1.0) weightmax = 1.0;
+
+ double signal = (offset - 1.0) * exparray[i];
+ minvalue += signal * weightmin;
+ weightmin *= gain * signal;
+
+ signal = (offset + 1.0) * exparray[i];
+ maxvalue += signal * weightmax;
+ weightmax *= gain * signal;
+
+ scale = (B - A) / (maxvalue - minvalue);
+ bias = A - minvalue * scale;
+ correct[i][0] = scale;
+ correct[i][1] = bias;
+ }
+ break;
+ }
+
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeEnum("type", type, props);
+ writeLong("octaves", numOctaves, props);
+ writeDouble("frequency", frequency, props);
+ writeDouble("lacunarity", lacunarity, props);
+ writeDouble("gain", gain, props);
+ writeDouble("H", H, props);
+ writeDouble("offset", offset, props);
+ for (int i = 0; i < numOctaves; i++) {
+ props.put("source_" + i, source[i].getId());
+ source[i]._writeToMap(map);
+ }
+
+ writeSeed(props);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readEnum("type", "setType", FractalType.class, props);
+ readLong("octaves", "setNumOctaves", props);
+ readDouble("frequency", "setFrequency", props);
+ readDouble("lacunarity", "setLacunarity", props);
+ readDouble("gain", "setGain", props);
+ readDouble("H", "setH", props);
+ readDouble("offset", "setOffset", props);
+
+ readSeed(props);
+
+ // must override sources after seed has been set
+ for (int i = 0; i < numOctaves; i++) {
+ overrideSource(i, map.get(props.get("source_" + i)));
+ }
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleFunctionGradient.java b/src/com/sudoplay/joise/module/ModuleFunctionGradient.java
new file mode 100755
index 000000000..237c23d9f
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleFunctionGradient.java
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleFunctionGradient extends SourcedModule {
+
+ public static final double DEFAULT_SPACING = 0.01;
+
+ public static enum FunctionGradientAxis {
+ X_AXIS, Y_AXIS, Z_AXIS, W_AXIS, U_AXIS, V_AXIS
+ }
+
+ protected FunctionGradientAxis axis;
+ protected double spacing;
+ protected double invSpacing;
+
+ public ModuleFunctionGradient() {
+ setAxis(FunctionGradientAxis.X_AXIS);
+ setSpacing(DEFAULT_SPACING);
+ }
+
+ public void setAxis(FunctionGradientAxis axis) {
+ this.axis = axis;
+ }
+
+ public void setSpacing(double s) {
+ spacing = s;
+ invSpacing = 1.0 / spacing;
+ }
+
+ @Override
+ public double get(double x, double y) {
+ switch (axis) {
+ case X_AXIS:
+ return (source.get(x - spacing, y) - source.get(x + spacing, y))
+ * invSpacing;
+ case Y_AXIS:
+ return (source.get(x, y - spacing) - source.get(x, y + spacing))
+ * invSpacing;
+ case Z_AXIS:
+ return 0.0;
+ case W_AXIS:
+ return 0.0;
+ case U_AXIS:
+ return 0.0;
+ case V_AXIS:
+ return 0.0;
+ }
+ return 0.0;
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ switch (axis) {
+ case X_AXIS:
+ return (source.get(x - spacing, y, z) - source.get(x + spacing, y, z))
+ * invSpacing;
+ case Y_AXIS:
+ return (source.get(x, y - spacing, z) - source.get(x, y + spacing, z))
+ * invSpacing;
+ case Z_AXIS:
+ return (source.get(x, y, z - spacing) - source.get(x, y, z + spacing))
+ * invSpacing;
+ case W_AXIS:
+ return 0.0;
+ case U_AXIS:
+ return 0.0;
+ case V_AXIS:
+ return 0.0;
+ }
+ return 0.0;
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ switch (axis) {
+ case X_AXIS:
+ return (source.get(x - spacing, y, z, w) - source.get(x + spacing, y, z,
+ w)) * invSpacing;
+
+ case Y_AXIS:
+ return (source.get(x, y - spacing, z, w) - source.get(x, y + spacing, z,
+ w)) * invSpacing;
+
+ case Z_AXIS:
+ return (source.get(x, y, z - spacing, w) - source.get(x, y, z + spacing,
+ w)) * invSpacing;
+
+ case W_AXIS:
+ return (source.get(x, y, z, w - spacing) - source.get(x, y, z, w
+ + spacing))
+ * invSpacing;
+ case U_AXIS:
+ return 0.0;
+ case V_AXIS:
+ return 0.0;
+ }
+ return 0.0;
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ switch (axis) {
+ case X_AXIS:
+ return (source.get(x - spacing, y, z, w, u, v) - source.get(x + spacing,
+ y, z, w, u, v)) * invSpacing;
+
+ case Y_AXIS:
+ return (source.get(x, y - spacing, z, w, u, v) - source.get(x, y
+ + spacing, z, w, u, v))
+ * invSpacing;
+ case Z_AXIS:
+ return (source.get(x, y, z - spacing, w, u, v) - source.get(x, y, z
+ + spacing, w, u, v))
+ * invSpacing;
+ case W_AXIS:
+ return (source.get(x, y, z, w - spacing, u, v) - source.get(x, y, z, w
+ + spacing, u, v))
+ * invSpacing;
+ case U_AXIS:
+ return (source.get(x, y, z, w, u - spacing, v) - source.get(x, y, z, w, u
+ + spacing, v))
+ * invSpacing;
+ case V_AXIS:
+ return (source.get(x, y, z, w, u, v - spacing) - source.get(x, y, z, w,
+ u, v + spacing)) * invSpacing;
+
+ }
+ return 0.0;
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeEnum("axis", axis, props);
+ writeDouble("spacing", spacing, props);
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readEnum("axis", "setAxis", FunctionGradientAxis.class, props);
+ readDouble("spacing", "setSpacing", props);
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleGain.java b/src/com/sudoplay/joise/module/ModuleGain.java
new file mode 100755
index 000000000..74ad975c4
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleGain.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+import com.sudoplay.joise.noise.Util;
+
+public class ModuleGain extends SourcedModule {
+
+ public static final double DEFAULT_GAIN = 0.5;
+
+ protected ScalarParameter gain = new ScalarParameter(DEFAULT_GAIN);
+
+ public ModuleGain() {
+ setGain(DEFAULT_GAIN);
+ }
+
+ public ModuleGain(double gain) {
+ setGain(gain);
+ }
+
+ public void setGain(double gain) {
+ this.gain.set(gain);
+ }
+
+ public void setGain(Module gain) {
+ this.gain.set(gain);
+ }
+
+ @Override
+ public double get(double x, double y) {
+ return Util.gain(gain.get(x, y), source.get(x, y));
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ return Util.gain(gain.get(x, y, z), source.get(x, y, z));
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ return Util.gain(gain.get(x, y, z, w), source.get(x, y, z, w));
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ return Util.gain(gain.get(x, y, z, w, u, v), source.get(x, y, z, w, u, v));
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeScalar("gain", gain, props, map);
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readScalar("gain", "setGain", props, map);
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleGradient.java b/src/com/sudoplay/joise/module/ModuleGradient.java
new file mode 100755
index 000000000..fea7268cb
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleGradient.java
@@ -0,0 +1,204 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleGradient extends Module {
+
+ public static final double DEFAULT_X1 = 0.0;
+ public static final double DEFAULT_X2 = 1.0;
+ public static final double DEFAULT_Y1 = 0.0;
+ public static final double DEFAULT_Y2 = 1.0;
+ public static final double DEFAULT_Z1 = 0.0;
+ public static final double DEFAULT_Z2 = 0.0;
+ public static final double DEFAULT_W1 = 0.0;
+ public static final double DEFAULT_W2 = 0.0;
+ public static final double DEFAULT_U1 = 0.0;
+ public static final double DEFAULT_U2 = 0.0;
+ public static final double DEFAULT_V1 = 0.0;
+ public static final double DEFAULT_V2 = 0.0;
+
+ protected double gx1, gx2, gy1, gy2, gz1, gz2, gw1, gw2, gu1, gu2, gv1, gv2;
+ protected double x, y, z, w, u, v;
+ protected double vlen;
+
+ public ModuleGradient() {
+ setGradient(DEFAULT_X1, DEFAULT_X2, DEFAULT_Y1, DEFAULT_Y2, DEFAULT_Z1,
+ DEFAULT_Z2, DEFAULT_W1, DEFAULT_W2, DEFAULT_U1, DEFAULT_U2, DEFAULT_V1,
+ DEFAULT_V2);
+ }
+
+ public void setGradient(double x1, double x2, double y1, double y2) {
+ setGradient(x1, x2, y1, y2, 0, 0, 0, 0, 0, 0, 0, 0);
+ }
+
+ public void setGradient(double x1, double x2, double y1, double y2,
+ double z1, double z2) {
+ setGradient(x1, x2, y1, y2, z1, z2, 0, 0, 0, 0, 0, 0);
+ }
+
+ public void setGradient(double x1, double x2, double y1, double y2,
+ double z1, double z2, double w1, double w2) {
+ setGradient(x1, x2, y1, y2, z1, z2, w1, w2, 0, 0, 0, 0);
+ }
+
+ public void setGradient(double x1, double x2, double y1, double y2,
+ double z1, double z2, double w1, double w2, double u1, double u2,
+ double v1, double v2) {
+ gx1 = x1;
+ gx2 = x2;
+ gy1 = y1;
+ gy2 = y2;
+ gz1 = z1;
+ gz2 = z2;
+ gw1 = w1;
+ gw2 = w2;
+ gu1 = u1;
+ gu2 = u2;
+ gv1 = v1;
+ gv2 = v2;
+
+ x = x2 - x1;
+ y = y2 - y1;
+ z = z2 - z1;
+ w = w2 - w1;
+ u = u2 - u1;
+ v = v2 - v1;
+
+ vlen = (x * x + y * y + z * z + w * w + u * u + v * v);
+ }
+
+ @Override
+ public double get(double x, double y) {
+ double dx = x - gx1;
+ double dy = y - gy1;
+ double dp = dx * this.x + dy * this.y;
+ dp /= vlen;
+ return dp;
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ double dx = x - gx1;
+ double dy = y - gy1;
+ double dz = z - gz1;
+ double dp = dx * this.x + dy * this.y + dz * this.z;
+ dp /= vlen;
+ return dp;
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ double dx = x - gx1;
+ double dy = y - gy1;
+ double dz = z - gz1;
+ double dw = w - gw1;
+ double dp = dx * this.x + dy * this.y + dz * this.z + dw * this.w;
+ dp /= vlen;
+ return dp;
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ double dx = x - gx1;
+ double dy = y - gy1;
+ double dz = z - gz1;
+ double dw = w - gw1;
+ double du = u - gu1;
+ double dv = v - gv1;
+ double dp = dx * this.x + dy * this.y + dz * this.z + dw * this.w + du
+ * this.u + dv * this.v;
+ dp /= vlen;
+ return dp;
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ StringBuffer sb = new StringBuffer();
+ sb.append(gx1).append(" ");
+ sb.append(gx2).append(" ");
+ sb.append(gy1).append(" ");
+ sb.append(gy2).append(" ");
+ sb.append(gz1).append(" ");
+ sb.append(gz2).append(" ");
+ sb.append(gw1).append(" ");
+ sb.append(gw2).append(" ");
+ sb.append(gu1).append(" ");
+ sb.append(gu2).append(" ");
+ sb.append(gv1).append(" ");
+ sb.append(gv2);
+ props.put("gradient", sb.toString());
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ String buf = props.getAsString("gradient");
+ String[] arr = buf.split(" ");
+ double[] d = new double[12];
+ for (int i = 0; i < 12; i++) {
+ d[i] = Double.parseDouble(arr[i]);
+ }
+ setGradient(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9],
+ d[10], d[11]);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleInvert.java b/src/com/sudoplay/joise/module/ModuleInvert.java
new file mode 100755
index 000000000..2d97d8287
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleInvert.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleInvert extends SourcedModule {
+
+ @Override
+ public double get(double x, double y) {
+ return -source.get(x, y);
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ return -source.get(x, y, z);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ return -source.get(x, y, z, w);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ return -source.get(x, y, z, w, u, v);
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleMagnitude.java b/src/com/sudoplay/joise/module/ModuleMagnitude.java
new file mode 100755
index 000000000..54d14952d
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleMagnitude.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleMagnitude extends Module {
+
+ protected ScalarParameter sX = new ScalarParameter(0);
+ protected ScalarParameter sY = new ScalarParameter(0);
+ protected ScalarParameter sZ = new ScalarParameter(0);
+ protected ScalarParameter sW = new ScalarParameter(0);
+ protected ScalarParameter sU = new ScalarParameter(0);
+ protected ScalarParameter sV = new ScalarParameter(0);
+
+ public void setX(double source) {
+ sX.set(source);
+ }
+
+ public void setY(double source) {
+ sY.set(source);
+ }
+
+ public void setZ(double source) {
+ sZ.set(source);
+ }
+
+ public void setW(double source) {
+ sW.set(source);
+ }
+
+ public void setU(double source) {
+ sU.set(source);
+ }
+
+ public void setV(double source) {
+ sV.set(source);
+ }
+
+ public void setX(Module source) {
+ sX.set(source);
+ }
+
+ public void setY(Module source) {
+ sY.set(source);
+ }
+
+ public void setZ(Module source) {
+ sZ.set(source);
+ }
+
+ public void setW(Module source) {
+ sW.set(source);
+ }
+
+ public void setU(Module source) {
+ sU.set(source);
+ }
+
+ public void setV(Module source) {
+ sV.set(source);
+ }
+
+ @Override
+ public double get(double x, double y) {
+ double xx = sX.get(x, y);
+ double yy = sY.get(x, y);
+ return Math.sqrt(xx * xx + yy * yy);
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ double xx = sX.get(x, y, z);
+ double yy = sY.get(x, y, z);
+ double zz = sZ.get(x, y, z);
+ return Math.sqrt(xx * xx + yy * yy + zz * zz);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ double xx = sX.get(x, y, z, w);
+ double yy = sY.get(x, y, z, w);
+ double zz = sZ.get(x, y, z, w);
+ double ww = sW.get(x, y, z, w);
+ return Math.sqrt(xx * xx + yy * yy + zz * zz + ww * ww);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ double xx = sX.get(x, y, z, w, u, v);
+ double yy = sY.get(x, y, z, w, u, v);
+ double zz = sZ.get(x, y, z, w, u, v);
+ double ww = sW.get(x, y, z, w, u, v);
+ double uu = sU.get(x, y, z, w, u, v);
+ double vv = sV.get(x, y, z, w, u, v);
+ return Math.sqrt(xx * xx + yy * yy + zz * zz + ww * ww + uu * uu + vv * vv);
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeScalar("X", sX, props, map);
+ writeScalar("Y", sY, props, map);
+ writeScalar("Z", sZ, props, map);
+ writeScalar("W", sW, props, map);
+ writeScalar("U", sU, props, map);
+ writeScalar("V", sV, props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readScalar("X", "setX", props, map);
+ readScalar("Y", "setY", props, map);
+ readScalar("Z", "setZ", props, map);
+ readScalar("W", "setW", props, map);
+ readScalar("U", "setU", props, map);
+ readScalar("V", "setV", props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleNormalizedCoords.java b/src/com/sudoplay/joise/module/ModuleNormalizedCoords.java
new file mode 100755
index 000000000..48f847bc2
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleNormalizedCoords.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleNormalizedCoords extends SourcedModule {
+
+ public static final double DEFAULT_LENGTH = 1.0;
+
+ protected ScalarParameter length = new ScalarParameter(DEFAULT_LENGTH);
+
+ public ModuleNormalizedCoords() {
+ this(DEFAULT_LENGTH);
+ }
+
+ public ModuleNormalizedCoords(double length) {
+ setLength(length);
+ }
+
+ public void setLength(double source) {
+ length.set(source);
+ }
+
+ public void setLength(Module source) {
+ length.set(source);
+ }
+
+ @Override
+ public double get(double x, double y) {
+ if (x == 0 && y == 0) return source.get(x, y);
+
+ double len = Math.sqrt(x * x + y * y);
+ double r = length.get(x, y);
+ return source.get(x / len * r, y / len * r);
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ if (x == 0 && y == 0 && z == 0) return source.get(x, y, z);
+
+ double len = Math.sqrt(x * x + y * y + z * z);
+ double r = length.get(x, y, z);
+ return source.get(x / len * r, y / len * r, z / len * r);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ if (x == 0 && y == 0 && z == 0 && w == 0) return source.get(x, y, z, w);
+
+ double len = Math.sqrt(x * x + y * y + z * z + w * w);
+ double r = length.get(x, y, z, w);
+ return source.get(x / len * r, y / len * r, z / len * r, w / len * r);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ if (x == 0 && y == 0 && z == 0 && w == 0 && u == 0 && v == 0)
+ return source.get(x, y, z, w, u, v);
+
+ double len = Math.sqrt(x * x + y * y + z * z + w * w + u * u + v * v);
+ double r = length.get(x, y, z, w, u, v);
+ return source.get(x / len * r, y / len * r, z / len * r, w / len * r, u
+ / len * r, v / len * r);
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeScalar("length", length, props, map);
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readScalar("length", "setLength", props, map);
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModulePow.java b/src/com/sudoplay/joise/module/ModulePow.java
new file mode 100755
index 000000000..c5b41f1d5
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModulePow.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModulePow extends SourcedModule {
+
+ public static final double DEFAULT_POWER = 1.0;
+
+ protected ScalarParameter power = new ScalarParameter(DEFAULT_POWER);
+
+ public void setPower(double v) {
+ power.set(v);
+ }
+
+ public void setPower(Module source) {
+ power.set(source);
+ }
+
+ @Override
+ public double get(double x, double y) {
+ return Math.pow(source.get(x, y), power.get(x, y));
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ return Math.pow(source.get(x, y, z), power.get(x, y, z));
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ return Math.pow(source.get(x, y, z, w), power.get(x, y, z, w));
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ return Math.pow(source.get(x, y, z, w, u, v), power.get(x, y, z, w, u, v));
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeScalar("power", power, props, map);
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readScalar("power", "setPower", props, map);
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleRotateDomain.java b/src/com/sudoplay/joise/module/ModuleRotateDomain.java
new file mode 100755
index 000000000..6a4053c29
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleRotateDomain.java
@@ -0,0 +1,227 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+import com.sudoplay.joise.noise.Util;
+
+public class ModuleRotateDomain extends SourcedModule {
+
+ protected double[][] rotmatrix = new double[3][3];
+ protected ScalarParameter ax = new ScalarParameter(0);
+ protected ScalarParameter ay = new ScalarParameter(0);
+ protected ScalarParameter az = new ScalarParameter(0);
+ protected ScalarParameter axisangle = new ScalarParameter(0);
+
+ public void setAxis(double ax, double ay, double az) {
+ this.ax.set(ax);
+ this.ay.set(ay);
+ this.az.set(az);
+ }
+
+ public void setAxis(Module ax, Module ay, Module az) {
+ this.ax.set(ax);
+ this.ay.set(ay);
+ this.az.set(az);
+ }
+
+ public void setAxisX(double ax) {
+ this.ax.set(ax);
+ }
+
+ public void setAxisX(Module ax) {
+ this.ax.set(ax);
+ }
+
+ public void setAxisY(double ay) {
+ this.ay.set(ay);
+ }
+
+ public void setAxisY(Module ay) {
+ this.ay.set(ay);
+ }
+
+ public void setAxisZ(double az) {
+ this.az.set(az);
+ }
+
+ public void setAxisZ(Module az) {
+ this.az.set(az);
+ }
+
+ public void setAngle(double a) {
+ this.axisangle.set(a);
+ }
+
+ public void setAngle(Module a) {
+ this.axisangle.set(a);
+ }
+
+ @Override
+ public double get(double x, double y) {
+ double nx, ny;
+ double angle = axisangle.get(x, y) * Util.TWO_PI;
+ double cos2d = Math.cos(angle);
+ double sin2d = Math.sin(angle);
+ nx = x * cos2d - y * sin2d;
+ ny = y * cos2d + x * sin2d;
+ return source.get(nx, ny);
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ calculateRotMatrix(x, y, z);
+ double nx, ny, nz;
+ nx = (rotmatrix[0][0] * x) + (rotmatrix[1][0] * y) + (rotmatrix[2][0] * z);
+ ny = (rotmatrix[0][1] * x) + (rotmatrix[1][1] * y) + (rotmatrix[2][1] * z);
+ nz = (rotmatrix[0][2] * x) + (rotmatrix[1][2] * y) + (rotmatrix[2][2] * z);
+ return source.get(nx, ny, nz);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ calculateRotMatrix(x, y, z, w);
+ double nx, ny, nz;
+ nx = (rotmatrix[0][0] * x) + (rotmatrix[1][0] * y) + (rotmatrix[2][0] * z);
+ ny = (rotmatrix[0][1] * x) + (rotmatrix[1][1] * y) + (rotmatrix[2][1] * z);
+ nz = (rotmatrix[0][2] * x) + (rotmatrix[1][2] * y) + (rotmatrix[2][2] * z);
+ return source.get(nx, ny, nz, w);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ calculateRotMatrix(x, y, z, w, u, v);
+ double nx, ny, nz;
+ nx = (rotmatrix[0][0] * x) + (rotmatrix[1][0] * y) + (rotmatrix[2][0] * z);
+ ny = (rotmatrix[0][1] * x) + (rotmatrix[1][1] * y) + (rotmatrix[2][1] * z);
+ nz = (rotmatrix[0][2] * x) + (rotmatrix[1][2] * y) + (rotmatrix[2][2] * z);
+ return source.get(nx, ny, nz, w, u, v);
+ }
+
+ protected void calculateRotMatrix(double x, double y) {
+ double angle = axisangle.get(x, y) * Util.TWO_PI;
+ double ax = this.ax.get(x, y);
+ double ay = this.ay.get(x, y);
+ double az = this.az.get(x, y);
+ calc(angle, ax, ay, az);
+ }
+
+ protected void calculateRotMatrix(double x, double y, double z) {
+ double angle = axisangle.get(x, y, z) * Util.TWO_PI;
+ double ax = this.ax.get(x, y, z);
+ double ay = this.ay.get(x, y, z);
+ double az = this.az.get(x, y, z);
+ calc(angle, ax, ay, az);
+ }
+
+ protected void calculateRotMatrix(double x, double y, double z, double w) {
+ double angle = axisangle.get(x, y, z, w) * Util.TWO_PI;
+ double ax = this.ax.get(x, y, z, w);
+ double ay = this.ay.get(x, y, z, w);
+ double az = this.az.get(x, y, z, w);
+ calc(angle, ax, ay, az);
+ }
+
+ protected void calculateRotMatrix(double x, double y, double z, double w,
+ double u, double v) {
+ double angle = axisangle.get(x, y, z, w, u, v) * Util.TWO_PI;
+ double ax = this.ax.get(x, y, z, w, u, v);
+ double ay = this.ay.get(x, y, z, w, u, v);
+ double az = this.az.get(x, y, z, w, u, v);
+ calc(angle, ax, ay, az);
+ }
+
+ protected void calc(double angle, double ax, double ay, double az) {
+ double cosangle = Math.cos(angle);
+ double sinangle = Math.sin(angle);
+
+ rotmatrix[0][0] = 1.0 + (1.0 - cosangle) * (ax * ax - 1.0);
+ rotmatrix[1][0] = -az * sinangle + (1.0 - cosangle) * ax * ay;
+ rotmatrix[2][0] = ay * sinangle + (1.0 - cosangle) * ax * az;
+
+ rotmatrix[0][1] = az * sinangle + (1.0 - cosangle) * ax * ay;
+ rotmatrix[1][1] = 1.0 + (1.0 - cosangle) * (ay * ay - 1.0);
+ rotmatrix[2][1] = -ax * sinangle + (1.0 - cosangle) * ay * az;
+
+ rotmatrix[0][2] = -ay * sinangle + (1.0 - cosangle) * ax * az;
+ rotmatrix[1][2] = ax * sinangle + (1.0 - cosangle) * ay * az;
+ rotmatrix[2][2] = 1.0 + (1.0 - cosangle) * (az * az - 1.0);
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeScalar("axisX", ax, props, map);
+ writeScalar("axisY", ay, props, map);
+ writeScalar("axisZ", az, props, map);
+ writeScalar("angle", axisangle, props, map);
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readScalar("axisX", "setAxisX", props, map);
+ readScalar("axisY", "setAxisY", props, map);
+ readScalar("axisZ", "setAxisZ", props, map);
+ readScalar("angle", "setAngle", props, map);
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleSawtooth.java b/src/com/sudoplay/joise/module/ModuleSawtooth.java
new file mode 100755
index 000000000..d973022be
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleSawtooth.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleSawtooth extends SourcedModule {
+
+ protected ScalarParameter period = new ScalarParameter(0);
+
+ public void setPeriod(double p) {
+ period.set(p);
+ }
+
+ public void setPeriod(Module p) {
+ period.set(p);
+ }
+
+ @Override
+ public double get(double x, double y) {
+ double val = source.get(x, y) / period.get(x, y);
+ return 2.0 * (val - Math.floor(0.5 + val));
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ double val = source.get(x, y, z) / period.get(x, y, z);
+ return 2.0 * (val - Math.floor(0.5 + val));
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ double val = source.get(x, y, z, w) / period.get(x, y, z, w);
+ return 2.0 * (val - Math.floor(0.5 + val));
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ double val = source.get(x, y, z, w, u, v) / period.get(x, y, z, w, u, v);
+ return 2.0 * (val - Math.floor(0.5 + val));
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeScalar("period", period, props, map);
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readScalar("period", "setPeriod", props, map);
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleScaleDomain.java b/src/com/sudoplay/joise/module/ModuleScaleDomain.java
new file mode 100755
index 000000000..3515c1211
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleScaleDomain.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleScaleDomain extends SourcedModule {
+
+ public static final double DEFAULT_SCALE = 1.0;
+
+ protected ScalarParameter sx = new ScalarParameter(1.0);
+ protected ScalarParameter sy = new ScalarParameter(1.0);
+ protected ScalarParameter sz = new ScalarParameter(1.0);
+ protected ScalarParameter sw = new ScalarParameter(1.0);
+ protected ScalarParameter su = new ScalarParameter(1.0);
+ protected ScalarParameter sv = new ScalarParameter(1.0);
+
+ public void setScaleX(double x) {
+ sx.set(x);
+ }
+
+ public void setScaleY(double y) {
+ sy.set(y);
+ }
+
+ public void setScaleZ(double z) {
+ sz.set(z);
+ }
+
+ public void setScaleW(double w) {
+ sw.set(w);
+ }
+
+ public void setScaleU(double u) {
+ su.set(u);
+ }
+
+ public void setScaleV(double v) {
+ sv.set(v);
+ }
+
+ public void setScaleX(Module x) {
+ sx.set(x);
+ }
+
+ public void setScaleY(Module y) {
+ sy.set(y);
+ }
+
+ public void setScaleZ(Module z) {
+ sz.set(z);
+ }
+
+ public void setScaleW(Module w) {
+ sw.set(w);
+ }
+
+ public void setScaleU(Module u) {
+ su.set(u);
+ }
+
+ public void setScaleV(Module v) {
+ sv.set(v);
+ }
+
+ @Override
+ public double get(double x, double y) {
+ return source.get(x * sx.get(x, y), y * sy.get(x, y));
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ return source.get(x * sx.get(x, y, z), y * sy.get(x, y, z),
+ z * sz.get(x, y, z));
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ return source.get(x * sx.get(x, y, z, w), y * sy.get(x, y, z, w),
+ z * sz.get(x, y, z, w), w * sw.get(x, y, z, w));
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ return source.get(x * sx.get(x, y, z, w, u, v),
+ y * sy.get(x, y, z, w, u, v), z * sz.get(x, y, z, w, u, v),
+ w * sw.get(x, y, z, w, u, v), u * su.get(x, y, z, w, u, v),
+ v * sv.get(x, y, z, w, u, v));
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeScalar("x", sx, props, map);
+ writeScalar("y", sy, props, map);
+ writeScalar("z", sz, props, map);
+ writeScalar("w", sw, props, map);
+ writeScalar("u", su, props, map);
+ writeScalar("v", sv, props, map);
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readScalar("x", "setScaleX", props, map);
+ readScalar("y", "setScaleY", props, map);
+ readScalar("z", "setScaleZ", props, map);
+ readScalar("w", "setScaleW", props, map);
+ readScalar("u", "setScaleU", props, map);
+ readScalar("v", "setScaleV", props, map);
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleScaleOffset.java b/src/com/sudoplay/joise/module/ModuleScaleOffset.java
new file mode 100755
index 000000000..3c8f72064
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleScaleOffset.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleScaleOffset extends SourcedModule {
+
+ protected ScalarParameter scale = new ScalarParameter(1.0);
+ protected ScalarParameter offset = new ScalarParameter(0.0);
+
+ public void setScale(double s) {
+ scale.set(s);
+ }
+
+ public void setScale(Module s) {
+ scale.set(s);
+ }
+
+ public void setOffset(double o) {
+ offset.set(o);
+ }
+
+ public void setOffset(Module o) {
+ offset.set(o);
+ }
+
+ @Override
+ public double get(double x, double y) {
+ return source.get(x, y) * scale.get(x, y) + offset.get(x, y);
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ return source.get(x, y, z) * scale.get(x, y, z) + offset.get(x, y, z);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ return source.get(x, y, z, w) * scale.get(x, y, z, w)
+ + offset.get(x, y, z, w);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ return source.get(x, y, z, w, u, v) * scale.get(x, y, z, w, u, v)
+ + offset.get(x, y, z, w, u, v);
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeScalar("offset", offset, props, map);
+ writeScalar("scale", scale, props, map);
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readScalar("offset", "setOffset", props, map);
+ readScalar("scale", "setScale", props, map);
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleSelect.java b/src/com/sudoplay/joise/module/ModuleSelect.java
new file mode 100755
index 000000000..c5beac715
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleSelect.java
@@ -0,0 +1,245 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+import com.sudoplay.joise.noise.Util;
+
+public class ModuleSelect extends Module {
+
+ protected ScalarParameter low = new ScalarParameter(0);
+ protected ScalarParameter high = new ScalarParameter(0);
+ protected ScalarParameter control = new ScalarParameter(0);
+ protected ScalarParameter threshold = new ScalarParameter(0);
+ protected ScalarParameter falloff = new ScalarParameter(0);
+
+ public void setLowSource(double source) {
+ low.set(source);
+ }
+
+ public void setHighSource(double source) {
+ high.set(source);
+ }
+
+ public void setControlSource(double source) {
+ control.set(source);
+ }
+
+ public void setThreshold(double source) {
+ threshold.set(source);
+ }
+
+ public void setFalloff(double source) {
+ falloff.set(source);
+ }
+
+ public void setLowSource(Module source) {
+ low.set(source);
+ }
+
+ public void setHighSource(Module source) {
+ high.set(source);
+ }
+
+ public void setControlSource(Module source) {
+ control.set(source);
+ }
+
+ public void setThreshold(Module source) {
+ threshold.set(source);
+ }
+
+ public void setFalloff(Module source) {
+ falloff.set(source);
+ }
+
+ @Override
+ public double get(double x, double y) {
+ double c = control.get(x, y);
+ double f = falloff.get(x, y);
+ double t = threshold.get(x, y);
+
+ if (f > 0.0) {
+
+ if (c < (t - f)) {
+ return low.get(x, y);
+ } else if (c > (t + f)) {
+ return high.get(x, y);
+ } else {
+ double lower = t - f;
+ double upper = t + f;
+ double blend = Util.quinticBlend((c - lower) / (upper - lower));
+ return Util.lerp(blend, low.get(x, y), high.get(x, y));
+ }
+
+ } else {
+ if (c < t) {
+ return low.get(x, y);
+ } else {
+ return high.get(x, y);
+ }
+ }
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ double c = control.get(x, y, z);
+ double f = falloff.get(x, y, z);
+ double t = threshold.get(x, y, z);
+
+ if (f > 0.0) {
+
+ if (c < (t - f)) {
+ return low.get(x, y, z);
+ } else if (c > (t + f)) {
+ return high.get(x, y, z);
+ } else {
+ double lower = t - f;
+ double upper = t + f;
+ double blend = Util.quinticBlend((c - lower) / (upper - lower));
+ return Util.lerp(blend, low.get(x, y, z), high.get(x, y, z));
+ }
+
+ } else {
+ if (c < t) {
+ return low.get(x, y, z);
+ } else {
+ return high.get(x, y, z);
+ }
+ }
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ double c = control.get(x, y, z, w);
+ double f = falloff.get(x, y, z, w);
+ double t = threshold.get(x, y, z, w);
+
+ if (f > 0.0) {
+
+ if (c < (t - f)) {
+ return low.get(x, y, z, w);
+ } else if (c > (t + f)) {
+ return high.get(x, y, z, w);
+ } else {
+ double lower = t - f;
+ double upper = t + f;
+ double blend = Util.quinticBlend((c - lower) / (upper - lower));
+ return Util.lerp(blend, low.get(x, y, z, w), high.get(x, y, z, w));
+ }
+
+ } else {
+ if (c < t) {
+ return low.get(x, y, z, w);
+ } else {
+ return high.get(x, y, z, w);
+ }
+ }
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ double c = control.get(x, y, z, w, u, v);
+ double f = falloff.get(x, y, z, w, u, v);
+ double t = threshold.get(x, y, z, w, u, v);
+
+ if (f > 0.0) {
+
+ if (c < (t - f)) {
+ return low.get(x, y, z, w, u, v);
+ } else if (c > (t + f)) {
+ return high.get(x, y, z, w, u, v);
+ } else {
+ double lower = t - f;
+ double upper = t + f;
+ double blend = Util.quinticBlend((c - lower) / (upper - lower));
+ return Util.lerp(blend, low.get(x, y, z, w, u, v),
+ high.get(x, y, z, w, u, v));
+ }
+
+ } else {
+ if (c < t) {
+ return low.get(x, y, z, w, u, v);
+ } else {
+ return high.get(x, y, z, w, u, v);
+ }
+ }
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeScalar("low", low, props, map);
+ writeScalar("high", high, props, map);
+ writeScalar("control", control, props, map);
+ writeScalar("threshold", threshold, props, map);
+ writeScalar("falloff", falloff, props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readScalar("low", "setLowSource", props, map);
+ readScalar("high", "setHighSource", props, map);
+ readScalar("control", "setControlSource", props, map);
+ readScalar("threshold", "setThreshold", props, map);
+ readScalar("falloff", "setFalloff", props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleSin.java b/src/com/sudoplay/joise/module/ModuleSin.java
new file mode 100755
index 000000000..c9d2b2e15
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleSin.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleSin extends SourcedModule {
+
+ @Override
+ public double get(double x, double y) {
+ return Math.sin(source.get(x, y));
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ return Math.sin(source.get(x, y, z));
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ return Math.sin(source.get(x, y, z, w));
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ return Math.sin(source.get(x, y, z, w, u, v));
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleSphere.java b/src/com/sudoplay/joise/module/ModuleSphere.java
new file mode 100755
index 000000000..ca271e052
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleSphere.java
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleSphere extends Module {
+
+ protected ScalarParameter cx = new ScalarParameter(0);
+ protected ScalarParameter cy = new ScalarParameter(0);
+ protected ScalarParameter cz = new ScalarParameter(0);
+ protected ScalarParameter cw = new ScalarParameter(0);
+ protected ScalarParameter cu = new ScalarParameter(0);
+ protected ScalarParameter cv = new ScalarParameter(0);
+ protected ScalarParameter radius = new ScalarParameter(1);
+
+ public void setCenterX(double source) {
+ cx.set(source);
+ }
+
+ public void setCenterY(double source) {
+ cy.set(source);
+ }
+
+ public void setCenterZ(double source) {
+ cz.set(source);
+ }
+
+ public void setCenterW(double source) {
+ cw.set(source);
+ }
+
+ public void setCenterU(double source) {
+ cu.set(source);
+ }
+
+ public void setCenterV(double source) {
+ cv.set(source);
+ }
+
+ public void setRadius(double source) {
+ radius.set(source);
+ }
+
+ public void setCenterX(Module source) {
+ cx.set(source);
+ }
+
+ public void setCenterY(Module source) {
+ cy.set(source);
+ }
+
+ public void setCenterZ(Module source) {
+ cz.set(source);
+ }
+
+ public void setCenterW(Module source) {
+ cw.set(source);
+ }
+
+ public void setCenterU(Module source) {
+ cu.set(source);
+ }
+
+ public void setCenterV(Module source) {
+ cv.set(source);
+ }
+
+ public void setRadius(Module source) {
+ radius.set(source);
+ }
+
+ @Override
+ public double get(double x, double y) {
+ double dx = x - cx.get(x, y), dy = y - cy.get(x, y);
+ double len = Math.sqrt(dx * dx + dy * dy);
+ double r = radius.get(x, y);
+ double i = (r - len) / r;
+ if (i < 0) i = 0;
+ if (i > 1) i = 1;
+
+ return i;
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ double dx = x - cx.get(x, y, z), dy = y - cy.get(x, y, z), dz = z
+ - cz.get(x, y, z);
+ double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
+ double r = radius.get(x, y, z);
+ double i = (r - len) / r;
+ if (i < 0) i = 0;
+ if (i > 1) i = 1;
+
+ return i;
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ double dx = x - cx.get(x, y, z, w), dy = y - cy.get(x, y, z, w), dz = z
+ - cz.get(x, y, z, w), dw = w - cw.get(x, y, z, w);
+ double len = Math.sqrt(dx * dx + dy * dy + dz * dz + dw * dw);
+ double r = radius.get(x, y, z, w);
+ double i = (r - len) / r;
+ if (i < 0) i = 0;
+ if (i > 1) i = 1;
+
+ return i;
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ double dx = x - cx.get(x, y, z, w, u, v), dy = y - cy.get(x, y, z, w, u, v), dz = z
+ - cz.get(x, y, z, w, u, v), dw = w - cw.get(x, y, z, w, u, v), du = u
+ - cu.get(x, y, z, w, u, v), dv = v - cv.get(x, y, z, w, u, v);
+ double len = Math.sqrt(dx * dx + dy * dy + dz * dz + dw * dw + du * du + dv
+ * dv);
+ double r = radius.get(x, y, z, w, u, v);
+ double i = (r - len) / r;
+ if (i < 0) i = 0;
+ if (i > 1) i = 1;
+
+ return i;
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeScalar("cx", cx, props, map);
+ writeScalar("cy", cy, props, map);
+ writeScalar("cz", cz, props, map);
+ writeScalar("cw", cw, props, map);
+ writeScalar("cu", cu, props, map);
+ writeScalar("cv", cv, props, map);
+ writeScalar("radius", radius, props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readScalar("cx", "setCenterX", props, map);
+ readScalar("cy", "setCenterY", props, map);
+ readScalar("cz", "setCenterZ", props, map);
+ readScalar("cw", "setCenterW", props, map);
+ readScalar("cu", "setCenterU", props, map);
+ readScalar("cv", "setCenterV", props, map);
+ readScalar("radius", "setRadius", props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleTiers.java b/src/com/sudoplay/joise/module/ModuleTiers.java
new file mode 100755
index 000000000..6e9e64fda
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleTiers.java
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+import com.sudoplay.joise.noise.Util;
+import com.sudoplay.util.Checked;
+
+public class ModuleTiers extends SourcedModule {
+
+ public static final int DEFAULT_NUM_TIERS = 0;
+ public static final boolean DEFAULT_SMOOTH = true;
+
+ protected int numTiers = DEFAULT_NUM_TIERS;
+ protected boolean smooth = DEFAULT_SMOOTH;
+
+ public void setNumTiers(long n) {
+ numTiers = Checked.safeLongToInt(n);
+ }
+
+ public void setNumTiers(int n) {
+ numTiers = n;
+ }
+
+ public void setSmooth(boolean b) {
+ smooth = b;
+ }
+
+ @Override
+ public double get(double x, double y) {
+ int numsteps = numTiers;
+ if (smooth) --numsteps;
+ double val = source.get(x, y);
+ double Tb = Math.floor(val * (double) (numsteps));
+ double Tt = Tb + 1.0;
+ double t = val * (double) (numsteps) - Tb;
+ Tb /= (double) (numsteps);
+ Tt /= (double) (numsteps);
+ double u;
+ if (smooth)
+ u = Util.quinticBlend(t);
+ else
+ u = 0.0;
+ return Tb + u * (Tt - Tb);
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ int numsteps = numTiers;
+ if (smooth) --numsteps;
+ double val = source.get(x, y, z);
+ double Tb = Math.floor(val * (double) (numsteps));
+ double Tt = Tb + 1.0;
+ double t = val * (double) (numsteps) - Tb;
+ Tb /= (double) (numsteps);
+ Tt /= (double) (numsteps);
+ double u;
+ if (smooth)
+ u = Util.quinticBlend(t);
+ else
+ u = 0.0;
+ return Tb + u * (Tt - Tb);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ int numsteps = numTiers;
+ if (smooth) --numsteps;
+ double val = source.get(x, y, z, w);
+ double Tb = Math.floor(val * (double) (numsteps));
+ double Tt = Tb + 1.0;
+ double t = val * (double) (numsteps) - Tb;
+ Tb /= (double) (numsteps);
+ Tt /= (double) (numsteps);
+ double u;
+ if (smooth)
+ u = Util.quinticBlend(t);
+ else
+ u = 0.0;
+ return Tb + u * (Tt - Tb);
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ int numsteps = numTiers;
+ if (smooth) --numsteps;
+ double val = source.get(x, y, z, w, u, v);
+ double Tb = Math.floor(val * (double) (numsteps));
+ double Tt = Tb + 1.0;
+ double t = val * (double) (numsteps) - Tb;
+ Tb /= (double) (numsteps);
+ Tt /= (double) (numsteps);
+ double s;
+ if (smooth)
+ s = Util.quinticBlend(t);
+ else
+ s = 0.0;
+ return Tb + s * (Tt - Tb);
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeLong("tiers", numTiers, props);
+ writeBoolean("smooth", smooth, props);
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readLong("tiers", "setNumTiers", props);
+ readBoolean("smooth", "setSmooth", props);
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleTranslateDomain.java b/src/com/sudoplay/joise/module/ModuleTranslateDomain.java
new file mode 100755
index 000000000..d69dca6c4
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleTranslateDomain.java
@@ -0,0 +1,169 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public class ModuleTranslateDomain extends SourcedModule {
+
+ protected ScalarParameter ax = new ScalarParameter(0);
+ protected ScalarParameter ay = new ScalarParameter(0);
+ protected ScalarParameter az = new ScalarParameter(0);
+ protected ScalarParameter aw = new ScalarParameter(0);
+ protected ScalarParameter au = new ScalarParameter(0);
+ protected ScalarParameter av = new ScalarParameter(0);
+
+ public void setAxisXSource(double source) {
+ ax.set(source);
+ }
+
+ public void setAxisYSource(double source) {
+ ay.set(source);
+ }
+
+ public void setAxisZSource(double source) {
+ az.set(source);
+ }
+
+ public void setAxisWSource(double source) {
+ aw.set(source);
+ }
+
+ public void setAxisUSource(double source) {
+ au.set(source);
+ }
+
+ public void setAxisVSource(double source) {
+ av.set(source);
+ }
+
+ public void setAxisXSource(Module source) {
+ ax.set(source);
+ }
+
+ public void setAxisYSource(Module source) {
+ ay.set(source);
+ }
+
+ public void setAxisZSource(Module source) {
+ az.set(source);
+ }
+
+ public void setAxisWSource(Module source) {
+ aw.set(source);
+ }
+
+ public void setAxisUSource(Module source) {
+ au.set(source);
+ }
+
+ public void setAxisVSource(Module source) {
+ av.set(source);
+ }
+
+ @Override
+ public double get(double x, double y) {
+ return source.get(x + ax.get(x, y), y + ay.get(x, y));
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ return source.get(x + ax.get(x, y, z), y + ay.get(x, y, z),
+ z + az.get(x, y, z));
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ return source.get(x + ax.get(x, y, z, w), y + ay.get(x, y, z, w),
+ z + az.get(x, y, z, w), w + aw.get(x, y, z, w));
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ return source.get(x + ax.get(x, y, z, w, u, v),
+ y + ay.get(x, y, z, w, u, v), z + az.get(x, y, z, w, u, v),
+ w + aw.get(x, y, z, w, u, v), u + au.get(x, y, z, w, u, v),
+ v + av.get(x, y, z, w, u, v));
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeScalar("axisX", ax, props, map);
+ writeScalar("axisY", ay, props, map);
+ writeScalar("axisZ", az, props, map);
+ writeScalar("axisW", aw, props, map);
+ writeScalar("axisU", au, props, map);
+ writeScalar("axisV", av, props, map);
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readScalar("axisX", "setAxisXSource", props, map);
+ readScalar("axisY", "setAxisYSource", props, map);
+ readScalar("axisZ", "setAxisZSource", props, map);
+ readScalar("axisW", "setAxisWSource", props, map);
+ readScalar("axisU", "setAxisUSource", props, map);
+ readScalar("axisV", "setAxisVSource", props, map);
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ModuleTriangle.java b/src/com/sudoplay/joise/module/ModuleTriangle.java
new file mode 100755
index 000000000..7bb1ee2d1
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ModuleTriangle.java
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+import com.sudoplay.joise.noise.Util;
+
+public class ModuleTriangle extends SourcedModule {
+
+ public static final double DEFAULT_PERIOD = 0;
+ public static final double DEFAULT_OFFSET = 0;
+
+ protected ScalarParameter period = new ScalarParameter(DEFAULT_PERIOD);
+ protected ScalarParameter offset = new ScalarParameter(DEFAULT_OFFSET);
+
+ public void setPeriod(double source) {
+ period.set(source);
+ }
+
+ public void setOffset(double source) {
+ offset.set(source);
+ }
+
+ public void setPeriod(Module source) {
+ period.set(source);
+ }
+
+ public void setOffset(Module source) {
+ offset.set(source);
+ }
+
+ @Override
+ public double get(double x, double y) {
+ double val = source.get(x, y);
+ double p = period.get(x, y);
+ double o = offset.get(x, y);
+
+ if (o >= 1)
+ return Util.sawtooth(val, p);
+ else if (o <= 0)
+ return 1.0 - Util.sawtooth(val, p);
+ else {
+ double s1 = (o - Util.sawtooth(val, p)) >= 0 ? 1.0 : 0.0;
+ double s2 = ((1.0 - o) - (Util.sawtooth(-val, p))) >= 0 ? 1.0 : 0.0;
+ return Util.sawtooth(val, p) * s1 / o + Util.sawtooth(-val, p) * s2
+ / (1.0 - o);
+ }
+ }
+
+ @Override
+ public double get(double x, double y, double z) {
+ double val = source.get(x, y, z);
+ double p = period.get(x, y, z);
+ double o = offset.get(x, y, z);
+
+ if (o >= 1)
+ return Util.sawtooth(val, p);
+ else if (o <= 0)
+ return 1.0 - Util.sawtooth(val, p);
+ else {
+ double s1 = (o - Util.sawtooth(val, p)) >= 0 ? 1.0 : 0.0;
+ double s2 = ((1.0 - o) - (Util.sawtooth(-val, p))) >= 0 ? 1.0 : 0.0;
+ return Util.sawtooth(val, p) * s1 / o + Util.sawtooth(-val, p) * s2
+ / (1.0 - o);
+ }
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w) {
+ double val = source.get(x, y, z, w);
+ double p = period.get(x, y, z, w);
+ double o = offset.get(x, y, z, w);
+
+ if (o >= 1)
+ return Util.sawtooth(val, p);
+ else if (o <= 0)
+ return 1.0 - Util.sawtooth(val, p);
+ else {
+ double s1 = (o - Util.sawtooth(val, p)) >= 0 ? 1.0 : 0.0;
+ double s2 = ((1.0 - o) - (Util.sawtooth(-val, p))) >= 0 ? 1.0 : 0.0;
+ return Util.sawtooth(val, p) * s1 / o + Util.sawtooth(-val, p) * s2
+ / (1.0 - o);
+ }
+ }
+
+ @Override
+ public double get(double x, double y, double z, double w, double u, double v) {
+ double val = source.get(x, y, z, w, u, v);
+ double p = period.get(x, y, z, w, u, v);
+ double o = offset.get(x, y, z, w, u, v);
+
+ if (o >= 1)
+ return Util.sawtooth(val, p);
+ else if (o <= 0)
+ return 1.0 - Util.sawtooth(val, p);
+ else {
+ double s1 = (o - Util.sawtooth(val, p)) >= 0 ? 1.0 : 0.0;
+ double s2 = ((1.0 - o) - (Util.sawtooth(-val, p))) >= 0 ? 1.0 : 0.0;
+ return Util.sawtooth(val, p) * s1 / o + Util.sawtooth(-val, p) * s2
+ / (1.0 - o);
+ }
+ }
+
+ @Override
+ protected void _writeToMap(ModuleMap map) {
+
+ ModulePropertyMap props = new ModulePropertyMap(this);
+
+ writeScalar("offset", offset, props, map);
+ writeScalar("period", period, props, map);
+ writeSource(props, map);
+
+ map.put(getId(), props);
+
+ }
+
+ @Override
+ public Module buildFromPropertyMap(ModulePropertyMap props,
+ ModuleInstanceMap map) {
+
+ readScalar("offset", "setOffset", props, map);
+ readScalar("period", "setPeriod", props, map);
+ readSource(props, map);
+
+ return this;
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/ScalarParameter.java b/src/com/sudoplay/joise/module/ScalarParameter.java
new file mode 100755
index 000000000..bc533e44d
--- /dev/null
+++ b/src/com/sudoplay/joise/module/ScalarParameter.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+public class ScalarParameter {
+
+ private Module module;
+ private double value;
+
+ public ScalarParameter(Module source) {
+ set(source);
+ }
+
+ public ScalarParameter(double source) {
+ set(source);
+ }
+
+ public void set(Module source) {
+ module = source;
+ }
+
+ public void set(double source) {
+ module = null;
+ value = source;
+ }
+
+ public boolean isModule() {
+ return module != null;
+ }
+
+ public Module getModule() {
+ return module;
+ }
+
+ public double getValue() {
+ return value;
+ }
+
+ public double get(double x, double y) {
+ if (module != null) return module.get(x, y);
+ return value;
+ }
+
+ public double get(double x, double y, double z) {
+ if (module != null) return module.get(x, y, z);
+ return value;
+ }
+
+ public double get(double x, double y, double z, double w) {
+ if (module != null) return module.get(x, y, z, w);
+ return value;
+ }
+
+ public double get(double x, double y, double z, double w, double u, double v) {
+ if (module != null) return module.get(x, y, z, w, u, v);
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ if (module != null) {
+ return module.getId();
+ } else {
+ return String.valueOf(value);
+ }
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/SeedableModule.java b/src/com/sudoplay/joise/module/SeedableModule.java
new file mode 100755
index 000000000..f57598773
--- /dev/null
+++ b/src/com/sudoplay/joise/module/SeedableModule.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModulePropertyMap;
+
+public abstract class SeedableModule extends Module {
+
+ protected long seed = DEFAULT_SEED;
+
+ protected String seedName;
+
+ public void setSeed(long seed) {
+ this.seed = seed;
+ }
+
+ public long getSeed() {
+ return seed;
+ }
+
+ public void setSeedName(String name) {
+ seedName = name;
+ }
+
+ public String getSeedName() {
+ return seedName;
+ }
+
+ public boolean hasSeedName() {
+ return seedName != null;
+ }
+
+ protected void readSeed(ModulePropertyMap props) {
+ String sn = (String) props.get("seedName");
+ if (sn != null) {
+ seedName = sn;
+ }
+ setSeed(props.getAsLong("seed"));
+ }
+
+ protected void writeSeed(ModulePropertyMap props) {
+ if (seedName != null) {
+ props.put("seedName", seedName);
+ }
+ props.put("seed", seed);
+ }
+
+}
diff --git a/src/com/sudoplay/joise/module/SourcedModule.java b/src/com/sudoplay/joise/module/SourcedModule.java
new file mode 100755
index 000000000..52d694898
--- /dev/null
+++ b/src/com/sudoplay/joise/module/SourcedModule.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.module;
+
+import com.sudoplay.joise.ModuleInstanceMap;
+import com.sudoplay.joise.ModuleMap;
+import com.sudoplay.joise.ModulePropertyMap;
+
+public abstract class SourcedModule extends Module {
+
+ protected ScalarParameter source = new ScalarParameter(0.0);
+
+ public void setSource(double source) {
+ this.source.set(source);
+ }
+
+ public void setSource(Module source) {
+ this.source.set(source);
+ }
+
+ public ScalarParameter getSource() {
+ return source;
+ }
+
+ protected void writeSource(ModulePropertyMap props, ModuleMap map) {
+ writeScalar("source", source, props, map);
+ }
+
+ protected void readSource(ModulePropertyMap props, ModuleInstanceMap map) {
+ readScalar("source", "setSource", props, map);
+ }
+
+}
diff --git a/src/com/sudoplay/joise/noise/Interpolator.java b/src/com/sudoplay/joise/noise/Interpolator.java
new file mode 100755
index 000000000..5c57d5906
--- /dev/null
+++ b/src/com/sudoplay/joise/noise/Interpolator.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.noise;
+
+public interface Interpolator {
+
+ public static final Interpolator NONE = new Interpolator() {
+ @Override
+ public double interpolate(double t) {
+ return 0;
+ }
+ };
+
+ public static final Interpolator LINEAR = new Interpolator() {
+ @Override
+ public double interpolate(double t) {
+ return t;
+ }
+ };
+
+ public static final Interpolator HERMITE = new Interpolator() {
+ @Override
+ public double interpolate(double t) {
+ return (t * t * (3 - 2 * t));
+ }
+ };
+
+ public static final Interpolator QUINTIC = new Interpolator() {
+ @Override
+ public double interpolate(double t) {
+ return t * t * t * (t * (t * 6 - 15) + 10);
+ }
+ };
+
+ public double interpolate(double t);
+
+}
diff --git a/src/com/sudoplay/joise/noise/Noise.java b/src/com/sudoplay/joise/noise/Noise.java
new file mode 100755
index 000000000..e05808c83
--- /dev/null
+++ b/src/com/sudoplay/joise/noise/Noise.java
@@ -0,0 +1,1387 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.noise;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+public class Noise {
+
+ private static final long INIT32 = 0x811c9dc5L;
+ private static final int PRIME32 = 0x01000193;
+ private static final int FNV_MASK_8 = (1 << 8) - 1;
+
+ private static final double INV_BYTEVAL = 1.0 / 255.0;
+
+ private static final double F2 = 0.36602540378443864676372317075294;
+ private static final double G2 = 0.21132486540518711774542560974902;
+ private static final double F3 = 1.0 / 3.0;
+ private static final double G3 = 1.0 / 6.0;
+
+ private static final ThreadLocal buf16 = new ThreadLocal() {
+ @Override
+ protected ByteBuffer initialValue() {
+ return ByteBuffer.allocate(16);
+ }
+ };
+
+ private static final ThreadLocal buf20 = new ThreadLocal() {
+ @Override
+ protected ByteBuffer initialValue() {
+ return ByteBuffer.allocate(20);
+ }
+ };
+
+ private static final ThreadLocal buf24 = new ThreadLocal() {
+ @Override
+ protected ByteBuffer initialValue() {
+ return ByteBuffer.allocate(24);
+ }
+ };
+
+ private static final ThreadLocal buf32 = new ThreadLocal() {
+ @Override
+ protected ByteBuffer initialValue() {
+ return ByteBuffer.allocate(32);
+ }
+ };
+
+ private static final ThreadLocal buf40 = new ThreadLocal() {
+ @Override
+ protected ByteBuffer initialValue() {
+ return ByteBuffer.allocate(40);
+ }
+ };
+
+ private static final ThreadLocal buf56 = new ThreadLocal() {
+ @Override
+ protected ByteBuffer initialValue() {
+ return ByteBuffer.allocate(56);
+ }
+ };
+
+ // ==========================================================================
+ // = Worker noise functions
+ // ==========================================================================
+
+ private static interface WorkerNoise2 {
+
+ public static final WorkerNoise2 VALUE = new WorkerNoise2() {
+ @Override
+ public double calculate(double x, double y, int ix, int iy, long seed) {
+ int n = (hashCoords2(ix, iy, seed));
+ double noise = (double) n * INV_BYTEVAL;
+ return noise * 2.0 - 1.0;
+ }
+ };
+
+ public static final WorkerNoise2 GRADIENT = new WorkerNoise2() {
+ @Override
+ public double calculate(double x, double y, int ix, int iy, long seed) {
+ int hash = hashCoords2(ix, iy, seed);
+ double[] vec = NoiseLUT.gradient2DLUT[hash];
+ double dx = x - (double) ix;
+ double dy = y - (double) iy;
+ return dx * vec[0] + dy * vec[1];
+ }
+ };
+
+ public double calculate(double x, double y, int ix, int iy, long seed);
+ }
+
+ private static interface WorkerNoise3 {
+
+ public static final WorkerNoise3 VALUE = new WorkerNoise3() {
+ @Override
+ public double calculate(double x, double y, double z, int ix, int iy,
+ int iz, long seed) {
+ int n = (hashCoords3(ix, iy, iz, seed));
+ double noise = (double) n * INV_BYTEVAL;
+ return noise * 2.0 - 1.0;
+ }
+ };
+
+ public static final WorkerNoise3 GRADIENT = new WorkerNoise3() {
+ @Override
+ public double calculate(double x, double y, double z, int ix, int iy,
+ int iz, long seed) {
+ int hash = hashCoords3(ix, iy, iz, seed);
+ double[] vec = NoiseLUT.gradient3DLUT[hash];
+ double dx = x - (double) ix;
+ double dy = y - (double) iy;
+ double dz = z - (double) iz;
+ return (dx * vec[0] + dy * vec[1] + dz * vec[2]);
+ }
+ };
+
+ public double calculate(double x, double y, double z, int ix, int iy,
+ int iz, long seed);
+ }
+
+ private static interface WorkerNoise4 {
+
+ public static final WorkerNoise4 VALUE = new WorkerNoise4() {
+ @Override
+ public double calculate(double x, double y, double z, double w, int ix,
+ int iy, int iz, int iw, long seed) {
+ int n = (hashCoords4(ix, iy, iz, iw, seed));
+ double noise = (double) n * INV_BYTEVAL;
+ return noise * 2.0 - 1.0;
+ }
+ };
+
+ public static final WorkerNoise4 GRADIENT = new WorkerNoise4() {
+ @Override
+ public double calculate(double x, double y, double z, double w, int ix,
+ int iy, int iz, int iw, long seed) {
+ int hash = hashCoords4(ix, iy, iz, iw, seed);
+ double[] vec = NoiseLUT.gradient4DLUT[hash];
+ double dx = x - (double) ix;
+ double dy = y - (double) iy;
+ double dz = z - (double) iz;
+ double dw = w - (double) iw;
+ return (dx * vec[0] + dy * vec[1] + dz * vec[2] + dw * vec[3]);
+ }
+ };
+
+ public double calculate(double x, double y, double z, double w, int ix,
+ int iy, int iz, int iw, long seed);
+ }
+
+ private static interface WorkerNoise6 {
+
+ public static final WorkerNoise6 VALUE = new WorkerNoise6() {
+ @Override
+ public double calculate(double x, double y, double z, double w, double u,
+ double v, int ix, int iy, int iz, int iw, int iu, int iv, long seed) {
+ int n = (hashCoords6(ix, iy, iz, iw, iu, iv, seed));
+ double noise = (double) n * INV_BYTEVAL;
+ return noise * 2.0 - 1.0;
+ }
+ };
+
+ public static final WorkerNoise6 GRADIENT = new WorkerNoise6() {
+ @Override
+ public double calculate(double x, double y, double z, double w, double u,
+ double v, int ix, int iy, int iz, int iw, int iu, int iv, long seed) {
+ int hash = hashCoords6(ix, iy, iz, iw, iu, iv, seed);
+ double[] vec = NoiseLUT.gradient6DLUT[hash];
+
+ double dx = x - (double) ix;
+ double dy = y - (double) iy;
+ double dz = z - (double) iz;
+ double dw = w - (double) iw;
+ double du = u - (double) iu;
+ double dv = v - (double) iv;
+
+ return (dx * vec[0] + dy * vec[1] + dz * vec[2] + dw * vec[3] + du
+ * vec[4] + dv * vec[5]);
+ }
+ };
+
+ public double calculate(double x, double y, double z, double w, double u,
+ double v, int ix, int iy, int iz, int iw, int iu, int iv, long seed);
+ }
+
+ // ==========================================================================
+ // = Common
+ // ==========================================================================
+
+ private static double lerp(double s, double v1, double v2) {
+ return v1 + s * (v2 - v1);
+ }
+
+ private static int fastFloor(double t) {
+ return t > 0 ? (int) t : (int) t - 1;
+ }
+
+ private static double arrayDot2(double[] arr, double a, double b) {
+ return a * arr[0] + b * arr[1];
+ }
+
+ private static double arrayDot3(double[] arr, double a, double b, double c) {
+ return a * arr[0] + b * arr[1] + c * arr[2];
+ }
+
+ private static double arrayDot4(double[] arr, double x, double y, double z,
+ double w) {
+ return x * arr[0] + y * arr[1] + z * arr[2] + w * arr[3];
+ }
+
+ private static void addDist(double[] f, double[] disp, double testDist,
+ double testDisp) {
+ int index;
+ if (testDist < f[3]) {
+ index = 3;
+ while (index > 0 && testDist < f[index - 1])
+ index--;
+ for (int i = 3; i-- > index;) {
+ f[i + 1] = f[i];
+ disp[i + 1] = disp[i];
+ }
+ f[index] = testDist;
+ disp[index] = testDisp;
+ }
+ }
+
+ private static class SVectorOrdering implements Comparable {
+ public double val;
+ public int axis;
+
+ public SVectorOrdering(double v, int a) {
+ val = v;
+ axis = a;
+ }
+
+ @Override
+ public int compareTo(SVectorOrdering o) {
+ if (val > o.val) {
+ return 1;
+ }
+ return -1;
+ }
+ }
+
+ private static void sortBy6(double[] l1, int[] l2) {
+ SVectorOrdering[] a = new SVectorOrdering[6];
+ for (int i = 0; i < 6; i++) {
+ a[i] = new SVectorOrdering(l1[i], l2[i]);
+ }
+ Arrays.sort(a);
+ for (int i = 0; i < 6; i++) {
+ l2[i] = a[i].axis;
+ }
+ }
+
+ // ==========================================================================
+ // = Hashing functions
+ // ==========================================================================
+
+ private static int fnv32ABuf(byte[] buf) {
+ long hval = INIT32;
+ for (int i = 0; i < buf.length; i++) {
+ hval ^= buf[i];
+ hval *= PRIME32;
+ }
+ return (int) (hval & 0x00000000ffffffffL);
+ }
+
+ private static int xorFoldHash(int hash) {
+ return ((byte) ((hash >> 8) ^ (hash & FNV_MASK_8))) & 0xFF;
+ }
+
+ private static int hashCoords2(int x, int y, long seed) {
+ ByteBuffer buf = buf16.get();
+ buf.clear();
+ buf.putInt(x).putInt(y).putLong(seed);
+ return xorFoldHash(fnv32ABuf(buf.array()));
+ }
+
+ private static int hashCoords3(int x, int y, int z, long seed) {
+ ByteBuffer buf = buf20.get();
+ buf.clear();
+ buf.putInt(x).putInt(y).putInt(z).putLong(seed);
+ return xorFoldHash(fnv32ABuf(buf.array()));
+ }
+
+ private static int hashCoords4(int x, int y, int z, int w, long seed) {
+ ByteBuffer buf = buf24.get();
+ buf.clear();
+ buf.putInt(x).putInt(y).putInt(z).putInt(w).putLong(seed);
+ return xorFoldHash(fnv32ABuf(buf.array()));
+ }
+
+ private static int hashCoords6(int x, int y, int z, int w, int u, int v,
+ long seed) {
+ ByteBuffer buf = buf32.get();
+ buf.clear();
+ buf.putInt(x).putInt(y).putInt(z);
+ buf.putInt(w).putInt(u).putInt(v).putLong(seed);
+ return xorFoldHash(fnv32ABuf(buf.array()));
+ }
+
+ private static int computeHashDouble2(double x, double y, long seed) {
+ ByteBuffer buf = buf24.get();
+ buf.clear();
+ buf.putDouble(x).putDouble(y).putLong(seed);
+ return xorFoldHash(fnv32ABuf(buf.array()));
+ }
+
+ private static int computeHashDouble3(double x, double y, double z, long seed) {
+ ByteBuffer buf = buf32.get();
+ buf.clear();
+ buf.putDouble(x).putDouble(y).putDouble(z).putLong(seed);
+ return xorFoldHash(fnv32ABuf(buf.array()));
+ }
+
+ private static int computeHashDouble4(double x, double y, double z, double w,
+ long seed) {
+ ByteBuffer buf = buf40.get();
+ buf.clear();
+ buf.putDouble(x).putDouble(y).putDouble(z).putDouble(w).putLong(seed);
+ return xorFoldHash(fnv32ABuf(buf.array()));
+ }
+
+ private static int computeHashDouble6(double x, double y, double z, double w,
+ double u, double v, long seed) {
+ ByteBuffer buf = buf56.get();
+ buf.clear();
+ buf.putDouble(x).putDouble(y).putDouble(z);
+ buf.putDouble(w).putDouble(u).putDouble(v).putLong(seed);
+ return xorFoldHash(fnv32ABuf(buf.array()));
+ }
+
+ // ==========================================================================
+ // = Interpolation functions
+ // ==========================================================================
+
+ private static double interpolateX2(double x, double y, double xs, int x0,
+ int x1, int iy, long seed, WorkerNoise2 noisefunc) {
+ double v1 = noisefunc.calculate(x, y, x0, iy, seed);
+ double v2 = noisefunc.calculate(x, y, x1, iy, seed);
+ return lerp(xs, v1, v2);
+ }
+
+ private static double interpolateXY2(double x, double y, double xs,
+ double ys, int x0, int x1, int y0, int y1, long seed,
+ WorkerNoise2 noisefunc) {
+ double v1 = interpolateX2(x, y, xs, x0, x1, y0, seed, noisefunc);
+ double v2 = interpolateX2(x, y, xs, x0, x1, y1, seed, noisefunc);
+ return lerp(ys, v1, v2);
+ }
+
+ private static double interpolateX3(double x, double y, double z, double xs,
+ int x0, int x1, int iy, int iz, long seed, WorkerNoise3 noisefunc) {
+ double v1 = noisefunc.calculate(x, y, z, x0, iy, iz, seed);
+ double v2 = noisefunc.calculate(x, y, z, x1, iy, iz, seed);
+ return lerp(xs, v1, v2);
+ }
+
+ private static double interpolateXY3(double x, double y, double z, double xs,
+ double ys, int x0, int x1, int y0, int y1, int iz, long seed,
+ WorkerNoise3 noisefunc) {
+ double v1 = interpolateX3(x, y, z, xs, x0, x1, y0, iz, seed, noisefunc);
+ double v2 = interpolateX3(x, y, z, xs, x0, x1, y1, iz, seed, noisefunc);
+ return lerp(ys, v1, v2);
+ }
+
+ private static double interpolateXYZ3(double x, double y, double z,
+ double xs, double ys, double zs, int x0, int x1, int y0, int y1, int z0,
+ int z1, long seed, WorkerNoise3 noisefunc) {
+ double v1 = interpolateXY3(x, y, z, xs, ys, x0, x1, y0, y1, z0, seed,
+ noisefunc);
+ double v2 = interpolateXY3(x, y, z, xs, ys, x0, x1, y0, y1, z1, seed,
+ noisefunc);
+ return lerp(zs, v1, v2);
+ }
+
+ private static double interpolateX4(double x, double y, double z, double w,
+ double xs, int x0, int x1, int iy, int iz, int iw, long seed,
+ WorkerNoise4 noisefunc) {
+ double v1 = noisefunc.calculate(x, y, z, w, x0, iy, iz, iw, seed);
+ double v2 = noisefunc.calculate(x, y, z, w, x1, iy, iz, iw, seed);
+ return lerp(xs, v1, v2);
+ }
+
+ private static double interpolateXY4(double x, double y, double z, double w,
+ double xs, double ys, int x0, int x1, int y0, int y1, int iz, int iw,
+ long seed, WorkerNoise4 noisefunc) {
+ double v1 = interpolateX4(x, y, z, w, xs, x0, x1, y0, iz, iw, seed,
+ noisefunc);
+ double v2 = interpolateX4(x, y, z, w, xs, x0, x1, y1, iz, iw, seed,
+ noisefunc);
+ return lerp(ys, v1, v2);
+ }
+
+ private static double interpolateXYZ4(double x, double y, double z, double w,
+ double xs, double ys, double zs, int x0, int x1, int y0, int y1, int z0,
+ int z1, int iw, long seed, WorkerNoise4 noisefunc) {
+ double v1 = interpolateXY4(x, y, z, w, xs, ys, x0, x1, y0, y1, z0, iw,
+ seed, noisefunc);
+ double v2 = interpolateXY4(x, y, z, w, xs, ys, x0, x1, y0, y1, z1, iw,
+ seed, noisefunc);
+ return lerp(zs, v1, v2);
+ }
+
+ private static double interpolateXYZW4(double x, double y, double z,
+ double w, double xs, double ys, double zs, double ws, int x0, int x1,
+ int y0, int y1, int z0, int z1, int w0, int w1, long seed,
+ WorkerNoise4 noisefunc) {
+ double v1 = interpolateXYZ4(x, y, z, w, xs, ys, zs, x0, x1, y0, y1, z0, z1,
+ w0, seed, noisefunc);
+ double v2 = interpolateXYZ4(x, y, z, w, xs, ys, zs, x0, x1, y0, y1, z0, z1,
+ w1, seed, noisefunc);
+ return lerp(ws, v1, v2);
+ }
+
+ private static double interpolateX6(double x, double y, double z, double w,
+ double u, double v, double xs, int x0, int x1, int iy, int iz, int iw,
+ int iu, int iv, long seed, WorkerNoise6 noisefunc) {
+ double v1 = noisefunc.calculate(x, y, z, w, u, v, x0, iy, iz, iw, iu, iv,
+ seed);
+ double v2 = noisefunc.calculate(x, y, z, w, u, v, x1, iy, iz, iw, iu, iv,
+ seed);
+ return lerp(xs, v1, v2);
+ }
+
+ private static double interpolateXY6(double x, double y, double z, double w,
+ double u, double v, double xs, double ys, int x0, int x1, int y0, int y1,
+ int iz, int iw, int iu, int iv, long seed, WorkerNoise6 noisefunc) {
+ double v1 = interpolateX6(x, y, z, w, u, v, xs, x0, x1, y0, iz, iw, iu, iv,
+ seed, noisefunc);
+ double v2 = interpolateX6(x, y, z, w, u, v, xs, x0, x1, y1, iz, iw, iu, iv,
+ seed, noisefunc);
+ return lerp(ys, v1, v2);
+ }
+
+ private static double interpolateXYZ6(double x, double y, double z, double w,
+ double u, double v, double xs, double ys, double zs, int x0, int x1,
+ int y0, int y1, int z0, int z1, int iw, int iu, int iv, long seed,
+ WorkerNoise6 noisefunc) {
+ double v1 = interpolateXY6(x, y, z, w, u, v, xs, ys, x0, x1, y0, y1, z0,
+ iw, iu, iv, seed, noisefunc);
+ double v2 = interpolateXY6(x, y, z, w, u, v, xs, ys, x0, x1, y0, y1, z1,
+ iw, iu, iv, seed, noisefunc);
+ return lerp(zs, v1, v2);
+ }
+
+ private static double interpolateXYZW6(double x, double y, double z,
+ double w, double u, double v, double xs, double ys, double zs, double ws,
+ int x0, int x1, int y0, int y1, int z0, int z1, int w0, int w1, int iu,
+ int iv, long seed, WorkerNoise6 noisefunc) {
+ double v1 = interpolateXYZ6(x, y, z, w, u, v, xs, ys, zs, x0, x1, y0, y1,
+ z0, z1, w0, iu, iv, seed, noisefunc);
+ double v2 = interpolateXYZ6(x, y, z, w, u, v, xs, ys, zs, x0, x1, y0, y1,
+ z0, z1, w1, iu, iv, seed, noisefunc);
+ return lerp(ws, v1, v2);
+ }
+
+ private static double interpolateXYZWU6(double x, double y, double z,
+ double w, double u, double v, double xs, double ys, double zs, double ws,
+ double us, int x0, int x1, int y0, int y1, int z0, int z1, int w0,
+ int w1, int u0, int u1, int iv, long seed, WorkerNoise6 noisefunc) {
+ double v1 = interpolateXYZW6(x, y, z, w, u, v, xs, ys, zs, ws, x0, x1, y0,
+ y1, z0, z1, w0, w1, u0, iv, seed, noisefunc);
+ double v2 = interpolateXYZW6(x, y, z, w, u, v, xs, ys, zs, ws, x0, x1, y0,
+ y1, z0, z1, w0, w1, u1, iv, seed, noisefunc);
+ return lerp(us, v1, v2);
+ }
+
+ private static double interpolateXYZWUV6(double x, double y, double z,
+ double w, double u, double v, double xs, double ys, double zs, double ws,
+ double us, double vs, int x0, int x1, int y0, int y1, int z0, int z1,
+ int w0, int w1, int u0, int u1, int v0, int v1, long seed,
+ WorkerNoise6 noisefunc) {
+ double val1 = interpolateXYZWU6(x, y, z, w, u, v, xs, ys, zs, ws, us, x0,
+ x1, y0, y1, z0, z1, w0, w1, u0, u1, v0, seed, noisefunc);
+ double val2 = interpolateXYZWU6(x, y, z, w, u, v, xs, ys, zs, ws, us, x0,
+ x1, y0, y1, z0, z1, w0, w1, u0, u1, v1, seed, noisefunc);
+ return lerp(vs, val1, val2);
+ }
+
+ // ==========================================================================
+ // = 2D noise functions
+ // ==========================================================================
+
+ public static interface Function2D {
+
+ public static Function2D VALUE = new Function2D() {
+ @Override
+ public double get(double x, double y, long seed, Interpolator interpolator) {
+ int x0 = fastFloor(x);
+ int y0 = fastFloor(y);
+ int x1 = x0 + 1;
+ int y1 = y0 + 1;
+ double xs = interpolator.interpolate(x - (double) x0);
+ double ys = interpolator.interpolate(y - (double) y0);
+ return interpolateXY2(x, y, xs, ys, x0, x1, y0, y1, seed,
+ WorkerNoise2.VALUE);
+ }
+ };
+
+ public static Function2D GRADIENT = new Function2D() {
+ @Override
+ public double get(double x, double y, long seed, Interpolator interpolator) {
+ int x0 = fastFloor(x);
+ int y0 = fastFloor(y);
+ int x1 = x0 + 1;
+ int y1 = y0 + 1;
+ double xs = interpolator.interpolate(x - (double) x0);
+ double ys = interpolator.interpolate(y - (double) y0);
+ return interpolateXY2(x, y, xs, ys, x0, x1, y0, y1, seed,
+ WorkerNoise2.GRADIENT);
+ }
+ };
+
+ public static Function2D GRADVAL = new Function2D() {
+ @Override
+ public double get(double x, double y, long seed, Interpolator interpolator) {
+ return Function2D.VALUE.get(x, y, seed, interpolator)
+ + Function2D.GRADIENT.get(x, y, seed, interpolator);
+ }
+ };
+
+ public static Function2D WHITE = new Function2D() {
+ @Override
+ public double get(double x, double y, long seed, Interpolator interpolator) {
+ int hash = computeHashDouble2(x, y, seed);
+ return NoiseLUT.whitenoiseLUT[hash];
+ }
+ };
+
+ public static Function2D SIMPLEX = new Function2D() {
+ @Override
+ public double get(double x, double y, long seed, Interpolator interpolator) {
+ double s = (x + y) * F2;
+ int i = fastFloor(x + s);
+ int j = fastFloor(y + s);
+ double t = (i + j) * G2;
+ double X0 = i - t;
+ double Y0 = j - t;
+ double x0 = x - X0;
+ double y0 = y - Y0;
+ int i1, j1;
+ if (x0 > y0) {
+ i1 = 1;
+ j1 = 0;
+ } else {
+ i1 = 0;
+ j1 = 1;
+ }
+ double x1 = x0 - (double) i1 + G2;
+ double y1 = y0 - (double) j1 + G2;
+ double x2 = x0 - 1.0 + 2.0 * G2;
+ double y2 = y0 - 1.0 + 2.0 * G2;
+ int h0 = hashCoords2(i, j, seed);
+ int h1 = hashCoords2(i + i1, j + j1, seed);
+ int h2 = hashCoords2(i + 1, j + 1, seed);
+ double[] g0 = NoiseLUT.gradient2DLUT[h0];
+ double[] g1 = NoiseLUT.gradient2DLUT[h1];
+ double[] g2 = NoiseLUT.gradient2DLUT[h2];
+ double n0, n1, n2;
+ double t0 = 0.5 - x0 * x0 - y0 * y0;
+ if (t0 < 0)
+ n0 = 0;
+ else {
+ t0 *= t0;
+ n0 = t0 * t0 * arrayDot2(g0, x0, y0);
+ }
+ double t1 = 0.5 - x1 * x1 - y1 * y1;
+ if (t1 < 0)
+ n1 = 0;
+ else {
+ t1 *= t1;
+ n1 = t1 * t1 * arrayDot2(g1, x1, y1);
+ }
+ double t2 = 0.5 - x2 * x2 - y2 * y2;
+ if (t2 < 0)
+ n2 = 0;
+ else {
+ t2 *= t2;
+ n2 = t2 * t2 * arrayDot2(g2, x2, y2);
+ }
+ return (70.0 * (n0 + n1 + n2)) * 1.42188695 + 0.001054489;
+ }
+ };
+
+ public double get(double x, double y, long seed, Interpolator interpolator);
+ }
+
+ // ==========================================================================
+ // = 3D noise functions
+ // ==========================================================================
+
+ public static interface Function3D {
+
+ public static final Function3D VALUE = new Function3D() {
+ @Override
+ public double get(double x, double y, double z, long seed,
+ Interpolator interpolator) {
+ int x0 = fastFloor(x);
+ int y0 = fastFloor(y);
+ int z0 = fastFloor(z);
+ int x1 = x0 + 1;
+ int y1 = y0 + 1;
+ int z1 = z0 + 1;
+ double xs = interpolator.interpolate(x - (double) x0);
+ double ys = interpolator.interpolate(y - (double) y0);
+ double zs = interpolator.interpolate(z - (double) z0);
+ return interpolateXYZ3(x, y, z, xs, ys, zs, x0, x1, y0, y1, z0, z1,
+ seed, WorkerNoise3.VALUE);
+ }
+ };
+
+ public static final Function3D GRADIENT = new Function3D() {
+ @Override
+ public double get(double x, double y, double z, long seed,
+ Interpolator interpolator) {
+ int x0 = fastFloor(x);
+ int y0 = fastFloor(y);
+ int z0 = fastFloor(z);
+ int x1 = x0 + 1;
+ int y1 = y0 + 1;
+ int z1 = z0 + 1;
+ double xs = interpolator.interpolate(x - (double) x0);
+ double ys = interpolator.interpolate(y - (double) y0);
+ double zs = interpolator.interpolate(z - (double) z0);
+ return interpolateXYZ3(x, y, z, xs, ys, zs, x0, x1, y0, y1, z0, z1,
+ seed, WorkerNoise3.GRADIENT);
+ }
+ };
+
+ public static final Function3D GRADVAL = new Function3D() {
+ @Override
+ public double get(double x, double y, double z, long seed,
+ Interpolator interpolator) {
+ return Function3D.VALUE.get(x, y, z, seed, interpolator)
+ + Function3D.GRADIENT.get(x, y, z, seed, interpolator);
+ }
+ };
+
+ public static final Function3D WHITE = new Function3D() {
+ @Override
+ public double get(double x, double y, double z, long seed,
+ Interpolator interpolator) {
+ int hash = computeHashDouble3(x, y, z, seed);
+ return NoiseLUT.whitenoiseLUT[hash];
+ }
+ };
+
+ public static final Function3D SIMPLEX = new Function3D() {
+ @Override
+ public double get(double x, double y, double z, long seed,
+ Interpolator interpolator) {
+ double n0, n1, n2, n3;
+
+ double s = (x + y + z) * F3;
+ int i = fastFloor(x + s);
+ int j = fastFloor(y + s);
+ int k = fastFloor(z + s);
+
+ double t = (i + j + k) * G3;
+ double X0 = i - t;
+ double Y0 = j - t;
+ double Z0 = k - t;
+
+ double x0 = x - X0;
+ double y0 = y - Y0;
+ double z0 = z - Z0;
+
+ int i1, j1, k1;
+ int i2, j2, k2;
+
+ if (x0 >= y0) {
+ if (y0 >= z0) {
+ i1 = 1;
+ j1 = 0;
+ k1 = 0;
+ i2 = 1;
+ j2 = 1;
+ k2 = 0;
+ } else if (x0 >= z0) {
+ i1 = 1;
+ j1 = 0;
+ k1 = 0;
+ i2 = 1;
+ j2 = 0;
+ k2 = 1;
+ } else {
+ i1 = 0;
+ j1 = 0;
+ k1 = 1;
+ i2 = 1;
+ j2 = 0;
+ k2 = 1;
+ }
+ } else {
+ if (y0 < z0) {
+ i1 = 0;
+ j1 = 0;
+ k1 = 1;
+ i2 = 0;
+ j2 = 1;
+ k2 = 1;
+ } else if (x0 < z0) {
+ i1 = 0;
+ j1 = 1;
+ k1 = 0;
+ i2 = 0;
+ j2 = 1;
+ k2 = 1;
+ } else {
+ i1 = 0;
+ j1 = 1;
+ k1 = 0;
+ i2 = 1;
+ j2 = 1;
+ k2 = 0;
+ }
+ }
+
+ double x1 = x0 - i1 + G3;
+ double y1 = y0 - j1 + G3;
+ double z1 = z0 - k1 + G3;
+ double x2 = x0 - i2 + 2.0 * G3;
+ double y2 = y0 - j2 + 2.0 * G3;
+ double z2 = z0 - k2 + 2.0 * G3;
+ double x3 = x0 - 1.0 + 3.0 * G3;
+ double y3 = y0 - 1.0 + 3.0 * G3;
+ double z3 = z0 - 1.0 + 3.0 * G3;
+
+ int h0, h1, h2, h3;
+
+ h0 = hashCoords3(i, j, k, seed);
+ h1 = hashCoords3(i + i1, j + j1, k + k1, seed);
+ h2 = hashCoords3(i + i2, j + j2, k + k2, seed);
+ h3 = hashCoords3(i + 1, j + 1, k + 1, seed);
+
+ double[] g0 = NoiseLUT.gradient3DLUT[h0];
+ double[] g1 = NoiseLUT.gradient3DLUT[h1];
+ double[] g2 = NoiseLUT.gradient3DLUT[h2];
+ double[] g3 = NoiseLUT.gradient3DLUT[h3];
+
+ double t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0;
+ if (t0 < 0.0)
+ n0 = 0.0;
+ else {
+ t0 *= t0;
+ n0 = t0 * t0 * arrayDot3(g0, x0, y0, z0);
+ }
+
+ double t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1;
+ if (t1 < 0.0)
+ n1 = 0.0;
+ else {
+ t1 *= t1;
+ n1 = t1 * t1 * arrayDot3(g1, 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 * arrayDot3(g2, 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 * arrayDot3(g3, x3, y3, z3);
+ }
+
+ return (32.0 * (n0 + n1 + n2 + n3)) * 1.25086885 + 0.0003194984;
+ }
+ };
+
+ public double get(double x, double y, double z, long seed,
+ Interpolator interpolator);
+ }
+
+ // ==========================================================================
+ // = 4D noise functions
+ // ==========================================================================
+
+ public static interface Function4D {
+
+ public static final Function4D VALUE = new Function4D() {
+ @Override
+ public double get(double x, double y, double z, double w, long seed,
+ Interpolator interpolator) {
+ int x0 = fastFloor(x);
+ int y0 = fastFloor(y);
+ int z0 = fastFloor(z);
+ int w0 = fastFloor(w);
+ int x1 = x0 + 1;
+ int y1 = y0 + 1;
+ int z1 = z0 + 1;
+ int w1 = w0 + 1;
+ double xs = interpolator.interpolate(x - (double) x0);
+ double ys = interpolator.interpolate(y - (double) y0);
+ double zs = interpolator.interpolate(z - (double) z0);
+ double ws = interpolator.interpolate(w - (double) w0);
+ return interpolateXYZW4(x, y, z, w, xs, ys, zs, ws, x0, x1, y0, y1, z0,
+ z1, w0, w1, seed, WorkerNoise4.VALUE);
+ }
+ };
+
+ public static final Function4D GRADIENT = new Function4D() {
+ @Override
+ public double get(double x, double y, double z, double w, long seed,
+ Interpolator interpolator) {
+ int x0 = fastFloor(x);
+ int y0 = fastFloor(y);
+ int z0 = fastFloor(z);
+ int w0 = fastFloor(w);
+ int x1 = x0 + 1;
+ int y1 = y0 + 1;
+ int z1 = z0 + 1;
+ int w1 = w0 + 1;
+ double xs = interpolator.interpolate(x - (double) x0);
+ double ys = interpolator.interpolate(y - (double) y0);
+ double zs = interpolator.interpolate(z - (double) z0);
+ double ws = interpolator.interpolate(w - (double) w0);
+ return interpolateXYZW4(x, y, z, w, xs, ys, zs, ws, x0, x1, y0, y1, z0,
+ z1, w0, w1, seed, WorkerNoise4.GRADIENT);
+ }
+ };
+
+ public static final Function4D GRADVAL = new Function4D() {
+ @Override
+ public double get(double x, double y, double z, double w, long seed,
+ Interpolator interpolator) {
+ return Function4D.VALUE.get(x, y, z, w, seed, interpolator)
+ + Function4D.GRADIENT.get(x, y, z, w, seed, interpolator);
+ }
+ };
+
+ public static final Function4D WHITE = new Function4D() {
+ @Override
+ public double get(double x, double y, double z, double w, long seed,
+ Interpolator interpolator) {
+ int hash = computeHashDouble4(x, y, z, w, seed);
+ return NoiseLUT.whitenoiseLUT[hash];
+ }
+ };
+
+ public static final Function4D SIMPLEX = new Function4D() {
+ @Override
+ public double get(double x, double y, double z, double w, long seed,
+ Interpolator interpolator) {
+ final int[][] simplex = { { 0, 1, 2, 3 }, { 0, 1, 3, 2 },
+ { 0, 0, 0, 0 }, { 0, 2, 3, 1 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 }, { 1, 2, 3, 0 }, { 0, 2, 1, 3 }, { 0, 0, 0, 0 },
+ { 0, 3, 1, 2 }, { 0, 3, 2, 1 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 }, { 1, 3, 2, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 1, 2, 0, 3 }, { 0, 0, 0, 0 },
+ { 1, 3, 0, 2 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
+ { 2, 3, 0, 1 }, { 2, 3, 1, 0 }, { 1, 0, 2, 3 }, { 1, 0, 3, 2 },
+ { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 2, 0, 3, 1 },
+ { 0, 0, 0, 0 }, { 2, 1, 3, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 2, 0, 1, 3 }, { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 3, 0, 1, 2 }, { 3, 0, 2, 1 },
+ { 0, 0, 0, 0 }, { 3, 1, 2, 0 }, { 2, 1, 0, 3 }, { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 3, 1, 0, 2 }, { 0, 0, 0, 0 },
+ { 3, 2, 0, 1 }, { 3, 2, 1, 0 } };
+
+ double F4 = (Math.sqrt(5.0) - 1.0) / 4.0;
+ double G4 = (5.0 - Math.sqrt(5.0)) / 20.0;
+ double n0, n1, n2, n3, n4;
+ double s = (x + y + z + w) * F4;
+ 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;
+ double X0 = i - t;
+ double Y0 = j - t;
+ double Z0 = k - t;
+ double W0 = l - t;
+ double x0 = x - X0;
+ double y0 = y - Y0;
+ double z0 = z - Z0;
+ double w0 = w - W0;
+ int c1 = (x0 > y0) ? 32 : 0;
+ int c2 = (x0 > z0) ? 16 : 0;
+ int c3 = (y0 > z0) ? 8 : 0;
+ int c4 = (x0 > w0) ? 4 : 0;
+ int c5 = (y0 > w0) ? 2 : 0;
+ int c6 = (z0 > w0) ? 1 : 0;
+ int c = c1 + c2 + c3 + c4 + c5 + c6;
+ int i1, j1, k1, l1;
+ int i2, j2, k2, l2;
+ int i3, j3, k3, l3;
+ i1 = simplex[c][0] >= 3 ? 1 : 0;
+ j1 = simplex[c][1] >= 3 ? 1 : 0;
+ k1 = simplex[c][2] >= 3 ? 1 : 0;
+ l1 = simplex[c][3] >= 3 ? 1 : 0;
+ i2 = simplex[c][0] >= 2 ? 1 : 0;
+ j2 = simplex[c][1] >= 2 ? 1 : 0;
+ k2 = simplex[c][2] >= 2 ? 1 : 0;
+ l2 = simplex[c][3] >= 2 ? 1 : 0;
+ i3 = simplex[c][0] >= 1 ? 1 : 0;
+ j3 = simplex[c][1] >= 1 ? 1 : 0;
+ k3 = simplex[c][2] >= 1 ? 1 : 0;
+ l3 = simplex[c][3] >= 1 ? 1 : 0;
+ double x1 = x0 - i1 + G4;
+ double y1 = y0 - j1 + G4;
+ double z1 = z0 - k1 + G4;
+ double w1 = w0 - l1 + G4;
+ double x2 = x0 - i2 + 2.0 * G4;
+ 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;
+ 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;
+ double y4 = y0 - 1.0 + 4.0 * G4;
+ double z4 = z0 - 1.0 + 4.0 * G4;
+ double w4 = w0 - 1.0 + 4.0 * G4;
+ int h0, h1, h2, h3, h4;
+ h0 = hashCoords4(i, j, k, l, seed);
+ h1 = hashCoords4(i + i1, j + j1, k + k1, l + l1, seed);
+ h2 = hashCoords4(i + i2, j + j2, k + k2, l + l2, seed);
+ h3 = hashCoords4(i + i3, j + j3, k + k3, l + l3, seed);
+ h4 = hashCoords4(i + 1, j + 1, k + 1, l + 1, seed);
+ double[] g0 = NoiseLUT.gradient4DLUT[h0];
+ double[] g1 = NoiseLUT.gradient4DLUT[h1];
+ double[] g2 = NoiseLUT.gradient4DLUT[h2];
+ double[] g3 = NoiseLUT.gradient4DLUT[h3];
+ double[] g4 = NoiseLUT.gradient4DLUT[h4];
+ double t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
+ if (t0 < 0)
+ n0 = 0.0;
+ else {
+ t0 *= t0;
+ n0 = t0 * t0 * arrayDot4(g0, 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 * arrayDot4(g1, 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 * arrayDot4(g2, 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 * arrayDot4(g3, 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 * arrayDot4(g4, x4, y4, z4, w4);
+ }
+ return 27.0 * (n0 + n1 + n2 + n3 + n4);
+ }
+ };
+
+ public double get(double x, double y, double z, double w, long seed,
+ Interpolator interpolator);
+ }
+
+ // ==========================================================================
+ // = 6D noise functions
+ // ==========================================================================
+
+ public static interface Function6D {
+
+ public static final Function6D VALUE = new Function6D() {
+ @Override
+ public double get(double x, double y, double z, double w, double u,
+ double v, long seed, Interpolator interpolator) {
+ int x0 = fastFloor(x);
+ int y0 = fastFloor(y);
+ int z0 = fastFloor(z);
+ int w0 = fastFloor(w);
+ int u0 = fastFloor(u);
+ int v0 = fastFloor(v);
+
+ int x1 = x0 + 1;
+ int y1 = y0 + 1;
+ int z1 = z0 + 1;
+ int w1 = w0 + 1;
+ int u1 = u0 + 1;
+ int v1 = v0 + 1;
+
+ double xs = interpolator.interpolate((x - (double) x0));
+ double ys = interpolator.interpolate((y - (double) y0));
+ double zs = interpolator.interpolate((z - (double) z0));
+ double ws = interpolator.interpolate((w - (double) w0));
+ double us = interpolator.interpolate((u - (double) u0));
+ double vs = interpolator.interpolate((v - (double) v0));
+
+ return interpolateXYZWUV6(x, y, z, w, u, v, xs, ys, zs, ws, us, vs, x0,
+ x1, y0, y1, z0, z1, w0, w1, u0, u1, v0, v1, seed,
+ WorkerNoise6.VALUE);
+ }
+ };
+
+ public static final Function6D GRADIENT = new Function6D() {
+ @Override
+ public double get(double x, double y, double z, double w, double u,
+ double v, long seed, Interpolator interpolator) {
+ int x0 = fastFloor(x);
+ int y0 = fastFloor(y);
+ int z0 = fastFloor(z);
+ int w0 = fastFloor(w);
+ int u0 = fastFloor(u);
+ int v0 = fastFloor(v);
+
+ int x1 = x0 + 1;
+ int y1 = y0 + 1;
+ int z1 = z0 + 1;
+ int w1 = w0 + 1;
+ int u1 = u0 + 1;
+ int v1 = v0 + 1;
+
+ double xs = interpolator.interpolate((x - (double) x0));
+ double ys = interpolator.interpolate((y - (double) y0));
+ double zs = interpolator.interpolate((z - (double) z0));
+ double ws = interpolator.interpolate((w - (double) w0));
+ double us = interpolator.interpolate((u - (double) u0));
+ double vs = interpolator.interpolate((v - (double) v0));
+
+ return interpolateXYZWUV6(x, y, z, w, u, v, xs, ys, zs, ws, us, vs, x0,
+ x1, y0, y1, z0, z1, w0, w1, u0, u1, v0, v1, seed,
+ WorkerNoise6.GRADIENT);
+ }
+ };
+
+ public static final Function6D GRADVAL = new Function6D() {
+ @Override
+ public double get(double x, double y, double z, double w, double u,
+ double v, long seed, Interpolator interpolator) {
+ return Function6D.VALUE.get(x, y, z, w, u, v, seed, interpolator)
+ + Function6D.GRADIENT.get(x, y, z, w, u, v, seed, interpolator);
+ }
+ };
+
+ public static final Function6D WHITE = new Function6D() {
+ @Override
+ public double get(double x, double y, double z, double w, double u,
+ double v, long seed, Interpolator interpolator) {
+ int hash = computeHashDouble6(x, y, z, w, u, v, seed);
+ return NoiseLUT.whitenoiseLUT[hash];
+ }
+ };
+
+ public static final Function6D SIMPLEX = new Function6D() {
+ @Override
+ public double get(double x, double y, double z, double w, double u,
+ double v, long seed, Interpolator interpolator) {
+
+ double F4 = (Math.sqrt(7.0) - 1.0) / 6.0;
+ double G4 = F4 / (1.0 + 6.0 * F4);
+
+ double sideLength = Math.sqrt(6.0) / (6.0 * F4 + 1.0);
+ double a = Math.sqrt((sideLength * sideLength)
+ - ((sideLength / 2.0) * (sideLength / 2.0)));
+ double cornerFace = Math.sqrt(a * a + (a / 2.0) * (a / 2.0));
+
+ double cornerFaceSqrd = cornerFace * cornerFace;
+
+ double valueScaler = Math.pow(5.0, -0.5);
+ valueScaler *= Math.pow(5.0, -3.5) * 100 + 13;
+
+ double[] loc = { x, y, z, w, u, v };
+ double s = 0;
+ for (int c = 0; c < 6; ++c)
+ s += loc[c];
+ s *= F4;
+
+ int[] skewLoc = { fastFloor(x + s), fastFloor(y + s), fastFloor(z + s),
+ fastFloor(w + s), fastFloor(u + s), fastFloor(v + s) };
+ int[] intLoc = { fastFloor(x + s), fastFloor(y + s), fastFloor(z + s),
+ fastFloor(w + s), fastFloor(u + s), fastFloor(v + s) };
+ double unskew = 0.0;
+ for (int c = 0; c < 6; ++c)
+ unskew += skewLoc[c];
+ unskew *= G4;
+ double[] cellDist = { loc[0] - (double) skewLoc[0] + unskew,
+ loc[1] - (double) skewLoc[1] + unskew,
+ loc[2] - (double) skewLoc[2] + unskew,
+ loc[3] - (double) skewLoc[3] + unskew,
+ loc[4] - (double) skewLoc[4] + unskew,
+ loc[5] - (double) skewLoc[5] + unskew };
+ int[] distOrder = { 0, 1, 2, 3, 4, 5 };
+ sortBy6(cellDist, distOrder);
+
+ int[] newDistOrder = { -1, distOrder[0], distOrder[1], distOrder[2],
+ distOrder[3], distOrder[4], distOrder[5] };
+
+ double n = 0.0;
+ double skewOffset = 0.0;
+
+ for (int c = 0; c < 7; ++c) {
+ int i = newDistOrder[c];
+ if (i != -1) intLoc[i] += 1;
+
+ double[] m = new double[6];
+ for (int d = 0; d < 6; ++d) {
+ m[d] = cellDist[d] - (intLoc[d] - skewLoc[d]) + skewOffset;
+ }
+
+ double t = cornerFaceSqrd;
+
+ for (int d = 0; d < 6; ++d) {
+ t -= m[d] * m[d];
+ }
+
+ if (t > 0.0) {
+ int h = hashCoords6(intLoc[0], intLoc[1], intLoc[2], intLoc[3],
+ intLoc[4], intLoc[5], seed);
+ double[] vec = NoiseLUT.gradient6DLUT[h];
+ double gr = 0.0;
+ for (int d = 0; d < 6; ++d) {
+ gr += vec[d] * m[d];
+ }
+
+ n += gr * t * t * t * t;
+ }
+ skewOffset += G4;
+ }
+ n *= valueScaler;
+ return n;
+ }
+ };
+
+ public double get(double x, double y, double z, double w, double u,
+ double v, long seed, Interpolator interpolator);
+ }
+
+ // ==========================================================================
+ // = Cellular functions
+ // ==========================================================================
+
+ public static void cellularFunction2D(double x, double y, long seed,
+ double[] f, double[] disp) {
+ int xint = fastFloor(x);
+ int yint = fastFloor(y);
+
+ for (int c = 0; c < 4; ++c) {
+ f[c] = 99999.0;
+ disp[c] = 0.0;
+ }
+
+ for (int ycur = yint - 3; ycur <= yint + 3; ++ycur) {
+ for (int xcur = xint - 3; xcur <= xint + 3; ++xcur) {
+
+ double xpos = (double) xcur
+ + WorkerNoise2.VALUE.calculate(x, y, xcur, ycur, seed);
+ double ypos = (double) ycur
+ + WorkerNoise2.VALUE.calculate(x, y, xcur, ycur, seed + 1);
+ double xdist = xpos - x;
+ double ydist = ypos - y;
+ double dist = (xdist * xdist + ydist * ydist);
+ int xval = fastFloor(xpos);
+ int yval = fastFloor(ypos);
+ double dsp = WorkerNoise2.VALUE.calculate(x, y, xval, yval, seed + 3);
+ addDist(f, disp, dist, dsp);
+ }
+ }
+
+ }
+
+ public static void cellularFunction3D(double x, double y, double z,
+ long seed, double[] f, double[] disp) {
+ int xint = fastFloor(x);
+ int yint = fastFloor(y);
+ int zint = fastFloor(z);
+
+ for (int c = 0; c < 4; ++c) {
+ f[c] = 99999.0;
+ disp[c] = 0.0;
+ }
+
+ 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) {
+ double xpos = (double) xcur
+ + WorkerNoise3.VALUE.calculate(x, y, z, xcur, ycur, zcur, seed);
+ double ypos = (double) ycur
+ + WorkerNoise3.VALUE.calculate(x, y, z, xcur, ycur, zcur,
+ seed + 1);
+ double zpos = (double) zcur
+ + WorkerNoise3.VALUE.calculate(x, y, z, 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);
+ int xval = fastFloor(xpos);
+ int yval = fastFloor(ypos);
+ int zval = fastFloor(zpos);
+ double dsp = WorkerNoise3.VALUE.calculate(x, y, z, xval, yval, zval,
+ seed + 3);
+ addDist(f, disp, dist, dsp);
+ }
+ }
+ }
+ }
+
+ public static void cellularFunction4D(double x, double y, double z, double w,
+ long seed, double[] f, double[] disp) {
+ int xint = fastFloor(x);
+ int yint = fastFloor(y);
+ int zint = fastFloor(z);
+ int wint = fastFloor(w);
+
+ for (int c = 0; c < 4; ++c) {
+ f[c] = 99999.0;
+ disp[c] = 0.0;
+ }
+
+ for (int wcur = wint - 2; wcur <= wint + 2; ++wcur) {
+ 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) {
+ double xpos = (double) xcur
+ + WorkerNoise4.VALUE.calculate(x, y, z, w, xcur, ycur, zcur,
+ wcur, seed);
+ double ypos = (double) ycur
+ + WorkerNoise4.VALUE.calculate(x, y, z, w, xcur, ycur, zcur,
+ wcur, seed + 1);
+ double zpos = (double) zcur
+ + WorkerNoise4.VALUE.calculate(x, y, z, w, xcur, ycur, zcur,
+ wcur, seed + 2);
+ double wpos = (double) wcur
+ + WorkerNoise4.VALUE.calculate(x, y, z, w, xcur, ycur, zcur,
+ wcur, seed + 3);
+ double xdist = xpos - x;
+ double ydist = ypos - y;
+ double zdist = zpos - z;
+ double wdist = wpos - w;
+ double dist = (xdist * xdist + ydist * ydist + zdist * zdist + wdist
+ * wdist);
+ int xval = fastFloor(xpos);
+ int yval = fastFloor(ypos);
+ int zval = fastFloor(zpos);
+ int wval = fastFloor(wpos);
+ double dsp = WorkerNoise4.VALUE.calculate(x, y, z, w, xval, yval,
+ zval, wval, seed + 3);
+ addDist(f, disp, dist, dsp);
+ }
+ }
+ }
+ }
+ }
+
+ public static void cellularFunction6D(double x, double y, double z, double w,
+ double u, double v, long seed, double[] f, double[] disp) {
+ int xint = fastFloor(x);
+ int yint = fastFloor(y);
+ int zint = fastFloor(z);
+ int wint = fastFloor(w);
+ int uint = fastFloor(u);
+ int vint = fastFloor(v);
+
+ for (int c = 0; c < 4; ++c) {
+ f[c] = 99999.0;
+ disp[c] = 0.0;
+ }
+
+ for (int vcur = vint - 1; vcur <= vint + 1; ++vcur) {
+ for (int ucur = uint - 1; ucur <= uint + 1; ++ucur) {
+
+ for (int wcur = wint - 2; wcur <= wint + 2; ++wcur) {
+ 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) {
+ double xpos = (double) xcur
+ + WorkerNoise6.VALUE.calculate(x, y, z, w, u, v, xcur,
+ ycur, zcur, wcur, ucur, vcur, seed);
+ double ypos = (double) ycur
+ + WorkerNoise6.VALUE.calculate(x, y, z, w, u, v, xcur,
+ ycur, zcur, wcur, ucur, vcur, seed + 1);
+ double zpos = (double) zcur
+ + WorkerNoise6.VALUE.calculate(x, y, z, w, u, v, xcur,
+ ycur, zcur, wcur, ucur, vcur, seed + 2);
+ double wpos = (double) wcur
+ + WorkerNoise6.VALUE.calculate(x, y, z, w, u, v, xcur,
+ ycur, zcur, wcur, ucur, vcur, seed + 3);
+ double upos = (double) ucur
+ + WorkerNoise6.VALUE.calculate(x, y, z, w, u, v, xcur,
+ ycur, zcur, wcur, ucur, vcur, seed + 4);
+ double vpos = (double) vcur
+ + WorkerNoise6.VALUE.calculate(x, y, z, w, u, v, xcur,
+ ycur, zcur, wcur, ucur, vcur, seed + 5);
+ double xdist = xpos - x;
+ double ydist = ypos - y;
+ double zdist = zpos - z;
+ double wdist = wpos - w;
+ double udist = upos - u;
+ double vdist = vpos - v;
+ double dist = (xdist * xdist + ydist * ydist + zdist * zdist
+ + wdist * wdist + udist * udist + vdist * vdist);
+ int xval = fastFloor(xpos);
+ int yval = fastFloor(ypos);
+ int zval = fastFloor(zpos);
+ int wval = fastFloor(wpos);
+ int uval = fastFloor(upos);
+ int vval = fastFloor(vpos);
+ double dsp = WorkerNoise6.VALUE.calculate(x, y, z, w, u, v,
+ xval, yval, zval, wval, uval, vval, seed + 6);
+ addDist(f, disp, dist, dsp);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public static double intValueNoise3D(int x, int y, int z, int seed) {
+ int n = (1619 * x + 31337 * y + 6971 * z + 1013 * seed) & 0x7fffffff;
+ n = (n >> 13) ^ n;
+ return (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
+ }
+
+ public static double valueNoise3D(int x, int y, int z, int seed) {
+ return 1.0 - ((double) intValueNoise3D(x, y, z, seed) / 1073741824.0);
+ }
+
+}
diff --git a/src/com/sudoplay/joise/noise/NoiseLUT.java b/src/com/sudoplay/joise/noise/NoiseLUT.java
new file mode 100755
index 000000000..ab5e63ba5
--- /dev/null
+++ b/src/com/sudoplay/joise/noise/NoiseLUT.java
@@ -0,0 +1,1121 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.noise;
+
+public class NoiseLUT {
+
+ private NoiseLUT() {}
+
+ public static final double[][] gradient2DLUT = { { 0, 1 }, { 0, -1 },
+ { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 },
+ { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 },
+ { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 },
+ { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 },
+ { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 },
+ { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 },
+ { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 },
+ { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 },
+ { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 },
+ { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 },
+ { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 },
+ { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 },
+ { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 },
+ { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 },
+ { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 },
+ { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 },
+ { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 },
+ { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 },
+ { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 },
+ { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 },
+ { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 },
+ { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 },
+ { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 },
+ { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 },
+ { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 },
+ { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 },
+ { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 },
+ { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 },
+ { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 },
+ { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 },
+ { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 },
+ { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 },
+ { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 },
+ { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 },
+ { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 },
+ { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 },
+ { 1, 0 }, { -1, 0 } };
+
+ public static final double[][] gradient3DLUT = { { 0, 0, 1 }, { 0, 0, -1 },
+ { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 },
+ { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 },
+ { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 },
+ { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 },
+ { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 },
+ { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 },
+ { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 },
+ { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 },
+ { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 },
+ { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 },
+ { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 },
+ { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 },
+ { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 },
+ { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 },
+ { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 },
+ { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 },
+ { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 },
+ { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 },
+ { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 },
+ { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 },
+ { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 },
+ { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 },
+ { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 },
+ { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 },
+ { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 },
+ { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 },
+ { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 },
+ { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 },
+ { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 },
+ { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 },
+ { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 },
+ { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 },
+ { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 },
+ { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 },
+ { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 },
+ { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 },
+ { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 },
+ { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 },
+ { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 },
+ { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 },
+ { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 },
+ { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 },
+ { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 },
+ { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 },
+ { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 },
+ { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 },
+ { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 },
+ { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 },
+ { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 },
+ { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 },
+ { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 } };
+
+ public static final double[][] gradient4DLUT = {
+ { 0.22552454980774, 0.66749286953929, 0.53967936463105, -0.46080161668515 },
+ { 0.52981737633302, 0.80705123608169, 0.25001068952995, 0.073868160904199 },
+ { 0.2551718844115, 0.40169779308827, -0.87581570003174, 0.080455279577005 },
+ { 0.2446720608745, -0.57667976542766, -0.10969185644738, 0.77171479667222 },
+ { 0.56152621692767, -0.4292067323737, 0.16103874251227, -0.68886603341873 },
+ { -0.47332175931021, 0.093442231646057, -0.75172946705559,
+ 0.44959745313871 },
+ { 0.36614231721753, 0.4625818257178, -0.50122840201262, 0.63303076313402 },
+ { 0.50134394883212, -0.32248055428503, 0.80140206134118,
+ -0.049145428633102 },
+ { 0.23609302357006, 0.78968939092939, 0.46805407624526, -0.31871010618635 },
+ { 0.3566224687564, 0.82280076001748, -0.42198348844058, -0.13322634715498 },
+ { 0.53249173494918, 0.35833499357915, 0.62048711191207, -0.45060440359416 },
+ { -0.10495021075845, -0.57318889402664, -0.51484484295083,
+ -0.62878830516575 },
+ { 0.48320530716683, -0.57172831979762, -0.61957401150899,
+ -0.2361512306338 },
+ { 0.56139247202719, -0.59285009197507, -0.5563962302756, 0.15424167961823 },
+ { -0.12102422542118, -0.49213994645356, 0.4794977231538, -0.7164030593571 },
+ { -0.39415630019406, -0.16750296810702, -0.77313995219119,
+ -0.46780143332237 },
+ { -0.077996875735257, -0.72521264783548, 0.21322391118796,
+ -0.65001435868195 },
+ { 0.36675239692246, -0.32607458507754, -0.86882175267727,
+ -0.065702407816875 },
+ { 0.54875576857984, 0.35330602237706, -0.70129121026282,
+ -0.28676226985181 },
+ { -0.5812728198809, 0.52878141440118, -0.48813116423404,
+ -0.37978953534178 },
+ { -0.22120336443784, -0.50216367205327, 0.23141872050005,
+ -0.80333435992336 },
+ { -0.62382494805532, -0.47276765886765, -0.5623445209171,
+ -0.26664923533941 },
+ { -0.34810294100203, 0.77605534406345, -0.015707133464448,
+ -0.52565742777462 },
+ { 0.69115837887353, -0.3936531009971, 0.089410248049089, 0.59945236585744 },
+ { 0.3133597935846, -0.79750731117234, -0.24841572824554, 0.45174921621572 },
+ { 0.15712455106329, -0.49358619043723, -0.56123861872675,
+ -0.64551976028044 },
+ { 0.12957880127654, -0.537223110548, -0.5612004467528, 0.61616127946936 },
+ { 0.14715736388495, -0.54550513683857, 0.70400607913576, -0.4302839719035 },
+ { -0.27603940501488, 0.66664669430619, -0.20940134756402,
+ -0.65995114022784 },
+ { -0.28542058243422, -0.26629956698313, -0.48526805245045,
+ 0.78239027922032 },
+ { 0.90830597179735, -0.30802834137341, 0.13130250877935,
+ -0.25071588241727 },
+ { -0.68975034153593, 0.29656664042552, 0.66049372644302,
+ -0.0063821209016788 },
+ { 0.23754231359754, 0.86360891835925, -0.37634599141988,
+ -0.23689022800294 },
+ { -0.3008221008451, 0.71840381218331, -0.19107614574202, 0.59740432942188 },
+ { -0.2544530858471, 0.33459224995788, 0.893299034533, 0.15911784398182 },
+ { -0.30908481589984, -0.76069512866564, -0.024337358188341,
+ 0.57027816966892 },
+ { 0.097288831244174, 0.96921511737704, -0.095017157071808,
+ -0.205252720871 },
+ { 0.63294540707629, -0.14805006160837, -0.42005382286916,
+ -0.6332583018104 },
+ { -0.67195172729974, -0.10550185088633, 0.18728512185188,
+ -0.70871328389651 },
+ { -0.69993983031639, -0.27629564601678, 0.47717744770779,
+ 0.45392359855806 },
+ { 0.45229382710377, 0.10953589230206, -0.86039839883114, 0.20771802413423 },
+ { 0.57507084430014, 0.49537901571099, 0.63765893106374, 0.13146954956864 },
+ { 0.49273255198119, 0.7371708819457, -0.29362806469134, 0.35717822253761 },
+ { 0.65308805992157, -0.50561647234808, 0.37455865201808, 0.42134758226026 },
+ { 0.015875966700541, 0.70304296752082, 0.628464130577, 0.3324325135707 },
+ { -0.61291521126741, 0.30295474138901, 0.43959142245302, -0.5825055791773 },
+ { 0.28870150781935, -0.055081790563628, 0.65913922715236,
+ -0.69220872210637 },
+ { -0.079733017226467, -0.22918659811981, 0.95837698208327,
+ -0.15043174338946 },
+ { -0.35025365580024, -0.58440279590723, 0.61398669509432,
+ -0.39851736095375 },
+ { -0.49583300276112, 0.8320520239064, 0.12466582301665, -0.2151685280373 },
+ { -0.57838068316419, -0.20866225618262, -0.25891317127095,
+ 0.74491598044996 },
+ { 0.24517181230967, 0.87106847894657, 0.38643251825943, 0.178326656073 },
+ { -0.032939982735198, 0.72735694715047, 0.59789863494626,
+ 0.33523730594724 },
+ { 0.46839767570091, 0.28725504887534, -0.82223460003592,
+ -0.14838603976579 },
+ { -0.68530688721453, 0.30062191695867, -0.65188139443225,
+ 0.12260334813328 },
+ { -0.09481691601797, -0.72846602189708, -0.47810363374399,
+ -0.48141865645099 },
+ { -0.71095576728456, -0.44889238701561, -0.38663259872485,
+ 0.37888356449908 },
+ { 0.65266817536949, -0.048437131039962, 0.073940142453456,
+ 0.75246990141163 },
+ { -0.58567515556267, 0.80836413944392, -0.052196260915081,
+ 0.028417961999587 },
+ { 0.4307524920894, 0.78828122681196, 0.28407778104785, -0.33520861016616 },
+ { -0.047152592626151, 0.080906814134336, 0.95331289758053,
+ -0.28709796192567 },
+ { -0.092934311395387, -0.93376149171941, -0.1711922375466,
+ -0.30024308177073 },
+ { 0.35964306202515, 0.79090749262634, -0.44772535519024, 0.21133909331798 },
+ { 0.78826512774619, -0.22601198404862, 0.57215985576402,
+ -0.013775735834394 },
+ { 0.090244004443892, -0.73057802155678, -0.077209310249513,
+ -0.6724213682587 },
+ { -0.0054007086447244, 0.64607993441819, -0.46651331454209,
+ 0.60408350254189 },
+ { -0.70185725868085, 0.5369402202072, 0.36637576194925, -0.29130806617212 },
+ { -0.32396804158331, 0.70188757706857, -0.30408596246687,
+ -0.55671380854088 },
+ { 0.56090670073868, -0.48169400187882, -0.66248222629843,
+ 0.12029905011714 },
+ { -0.21148730570035, -0.66324178429788, 0.42537806814415,
+ -0.57830524312938 },
+ { 0.49184121803223, -0.53433759959622, 0.41996352447612,
+ -0.54424827423881 },
+ { -0.62991318148171, 0.6560831504895, -0.018944460160231,
+ -0.41521728151487 },
+ { -0.74278663987202, -0.57070585901822, -0.26473071464775,
+ -0.2290861821062 },
+ { 0.5025495101175, -0.37409188240791, 0.47531478480926, 0.61771766102232 },
+ { -0.22227660391851, 0.082683771800495, -0.17294940947311,
+ 0.95595240833119 },
+ { 0.47549422210941, 0.27384409989549, -0.73038192404162,
+ -0.40676393488884 },
+ { 0.59221657484784, 0.050200153729467, 0.70240850515692, 0.3916398408286 },
+ { 0.89287935537108, -0.18228187488468, 0.20326879532789, 0.35808039835574 },
+ { -0.63303616764545, -0.56090787852805, 0.5182368140323, 0.12679971151219 },
+ { 0.78287411316931, 0.49854614640923, 0.30404279624908, -0.2147506481455 },
+ { -0.41503470490899, -0.6268605824938, -0.35991041023467,
+ 0.55250022664371 },
+ { -0.53157442679059, 0.048919235389262, -0.84511446630526,
+ -0.028584541849774 },
+ { 0.63177262851732, -0.27840711796915, 0.58586252075951,
+ -0.42440302695638 },
+ { -0.44119538483073, 0.5829738945766, -0.51924450975423, 0.44257565425174 },
+ { 0.61392386167432, -0.58465170951844, 0.20613607919186, 0.48865917312527 },
+ { 0.24475051899163, 0.30754543456076, -0.15222721025769, 0.90682956810601 },
+ { 0.41724992835443, -0.13224180301206, 0.89274161403018, 0.10689720951984 },
+ { -0.76873245399282, 0.075325506550414, -0.61855849417628,
+ 0.14408980367632 },
+ { 0.53191194272188, 0.53084656080533, 0.3798738941559, -0.5394139770249 },
+ { 0.75910942848531, 0.39530213014524, -0.29984000888542, 0.4214084367439 },
+ { -0.03541957430639, -0.62483127808284, 0.75776450849439,
+ 0.18472757604531 },
+ { 0.4625891622941, -0.2531420033374, 0.56439885635973, -0.63512543958985 },
+ { 0.660548158654, 0.076935839301002, 0.62489061261352, 0.40898499849916 },
+ { -0.13772992864036, -0.35663701661207, -0.70063282711493,
+ -0.60245675920161 },
+ { 0.3331436864299, 0.15331116273714, -0.48119522685978, 0.79621738565511 },
+ { 0.71571654511597, -0.26028084726799, 0.52940810879996,
+ -0.37380578102748 },
+ { -0.45879392024731, 0.070422886390706, -0.88044825819407,
+ -0.096745131451335 },
+ { -0.3710610095712, 0.49491399293823, -0.19875303607171, 0.76017833264453 },
+ { 0.67521169438188, -0.21089530160678, 0.30499481128614,
+ -0.63764449705041 },
+ { 0.37955387270282, 0.37946220745499, 0.64929517854168, -0.53885346983406 },
+ { -0.76118100241106, -0.2502648698634, -0.48213952651367,
+ 0.35427736796742 },
+ { -0.81826013990967, 0.29678177941379, 0.27395924681324, -0.4090443129155 },
+ { -0.48735224983659, 0.75897371421789, 0.029778664412101,
+ 0.43076666172228 },
+ { -0.42267571253102, -0.28154084743402, -0.55892959867618,
+ 0.65549805261817 },
+ { -0.34623389175769, -0.19627361980202, 0.62165029251141,
+ 0.67464781344685 },
+ { 0.4829697897084, -0.57358816947082, 0.66156267623348,
+ 0.0084628297236668 },
+ { 0.74866979663621, -0.0035805505812814, -0.64318857973023,
+ -0.16059005625143 },
+ { -0.090152317154269, 0.6862809022405, 0.64123846108899, 0.33121642313131 },
+ { -0.78321651600427, -0.19115065168422, -0.56201602070159,
+ 0.18485483465027 },
+ { -0.73377708689206, 0.0284256453642, 0.67360273611538, 0.08380049722821 },
+ { 0.49834502400233, -0.35880739756757, -0.78920001543545,
+ 0.0085337060880708 },
+ { -0.8413442675025, -0.49848949817935, -0.033350567138177,
+ 0.20624205055503 },
+ { 0.62993466610518, -0.0034911977529077, -0.075714594190885,
+ -0.77294076629695 },
+ { -0.17272033203772, -0.29580796453879, -0.37548041615855,
+ -0.86120833257558 },
+ { -0.47432431050844, -0.60995101955389, -0.62418813212925,
+ 0.11560872767599 },
+ { 0.23618736517714, -0.40605404979081, 0.6180271784331, 0.63037928574564 },
+ { 0.55500851198302, 0.41920843999997, -0.40467056584228,
+ -0.59369316031101 },
+ { -0.17861281311101, 0.6681171368602, 0.72039649788735, 0.052400765814444 },
+ { 0.051032005226464, 0.77077381574869, -0.21368401455548,
+ 0.59803227448209 },
+ { -0.27130398085814, -0.2356472352851, 0.54860265705132, 0.75491698560123 },
+ { 0.34863907202149, -0.1008710712593, 0.31299887927802, -0.87767165045574 },
+ { 0.65671708149768, 0.18729913477315, 0.690161625609, 0.23941311476012 },
+ { 0.21543450079531, 0.62368781511756, 0.6740194876821, -0.33211325683525 },
+ { -0.29368781227182, -0.70194271867824, 0.64731835728572,
+ -0.044753021557358 },
+ { 0.47957288380265, -0.48010386819579, -0.41528424196963,
+ -0.60584579163047 },
+ { 0.77465998420784, 0.2064625496211, -0.59762679675591,
+ -0.010832186775088 },
+ { 0.59374912564074, 0.44398057182928, -0.628531238492, -0.23514189307461 },
+ { 0.29933292179378, -0.13849303742408, -0.75484941644759,
+ -0.56694077204253 },
+ { 0.67864785518517, -0.66598612231715, -0.20117390931759,
+ -0.23543286037301 },
+ { 0.41139382663025, -0.50162129081774, 0.76099758294395,
+ -0.0037254210934192 },
+ { -0.63872455601276, 0.22070744447973, -0.66020520498325,
+ -0.32779300299205 },
+ { 0.29418192945737, 0.76084869464354, 0.56579367268056, -0.12018226239594 },
+ { 0.57883638224948, 0.54835864232767, -0.58981423708497,
+ -0.12794689406458 },
+ { -0.49577506786442, -0.40376295003701, 0.74730897396085,
+ -0.18086420237026 },
+ { -0.23542938066082, -0.82998760453564, 0.044423043427579,
+ 0.50370643856465 },
+ { 0.51460246995974, -0.20375144052087, -0.58171443714984,
+ 0.59605197928405 },
+ { -0.57420458168785, 0.50828481072877, -0.64181398835659,
+ -0.0032332492798049 },
+ { -0.59114159943176, -0.70202688911205, 0.3951425902627,
+ -0.039650847978142 },
+ { 0.32348943025434, 0.15426522631209, 0.48865478831089, -0.79547050625742 },
+ { 0.78091367446976, 0.24332864387958, -0.57453483550803,
+ 0.029575782012119 },
+ { 0.29640854502528, 0.81484848881134, 0.33564412795113, 0.36811266494077 },
+ { 0.067881648517454, 0.59549997670039, 0.50990703475037, -0.6170629428644 },
+ { 0.28894916793968, -0.69198564828725, 0.023585472505226,
+ 0.66114141180095 },
+ { -0.48325755685412, 0.44101587160833, 0.32395739272709,
+ -0.68338769555092 },
+ { -0.5710256256505, -0.12907895901829, -0.17172158524436,
+ 0.79232572490761 },
+ { 0.6847915554189, 0.46529665784725, 0.53390899832342, 0.17175775770671 },
+ { 0.42165492939873, 0.79428961452838, 0.38934026723474, 0.19931202943048 },
+ { -0.63847181078, 0.53274793784908, 0.28633773611669, -0.47596647196249 },
+ { 0.19156995438377, -0.77779812107245, -0.14338187979369,
+ -0.58118213322537 },
+ { 0.44339330307, 0.062294908508799, 0.49992742799503, 0.74134626855797 },
+ { 0.11414857945734, -0.80669520663252, -0.039462641492769,
+ 0.57849429152793 },
+ { 0.51140504554998, 0.77475373616074, 0.37094692794394, 0.024897878221959 },
+ { -0.42141421118923, 0.41042157807017, -0.78825942772297,
+ -0.18058589498632 },
+ { -0.61241893151874, -0.31986126390856, 0.71454099453741,
+ 0.10983164978162 },
+ { 0.42647810613114, -0.16890980399214, -0.58321474597059, 0.670407684315 },
+ { -0.62005519270376, 0.24692971568815, 0.55376487937289,
+ -0.49789731058161 },
+ { -0.2357164754471, 0.80976845323815, -0.53339765737773,
+ -0.064805358166192 },
+ { -0.45289067914353, -0.60809715423324, -0.18106295928925,
+ -0.62635779593756 },
+ { -0.60064300362149, -0.55194968809516, 0.27130873161666,
+ 0.51085330199654 },
+ { 0.1788394866438, -0.29721754352243, -0.50108833389719,
+ -0.79283582882688 },
+ { -0.65652402015051, 0.42070413168568, -0.54025124528414,
+ 0.31640612591564 },
+ { 0.43620946470649, -0.1249196094834, -0.27642429463064,
+ -0.84717530854301 },
+ { 0.2543621682741, 0.27962706507339, -0.8372594728531, 0.39510146411661 },
+ { -0.81374681782569, -0.49558273399432, -0.30261128321578,
+ 0.02530378461355 },
+ { -0.67641647228818, 0.48707240260253, 0.33721313271051, 0.43761688012207 },
+ { 0.28572653298411, 0.63329777351537, -0.019774894218509,
+ 0.71895982639366 },
+ { 0.65708200570959, -0.34223476177811, -0.041917555540789,
+ -0.67034433251936 },
+ { 0.071864648185965, -0.59386186862736, 0.59510615312859,
+ 0.53666769964292 },
+ { -0.52113381082923, 0.32294388060376, -0.34686930359901,
+ -0.70979467975741 },
+ { 0.25004346113893, -0.42478362076275, -0.0072114313495278,
+ -0.87004892869956 },
+ { -0.73610460974203, 0.39085477297004, 0.080434514738008,
+ 0.54672921890268 },
+ { -0.096982051782443, 0.12922152423063, 0.59661992662453,
+ -0.78609219717672 },
+ { -0.64487244725608, -0.38386246316229, -0.66001973035734,
+ 0.034104130013256 },
+ { 0.40625275106386, 0.61435583542081, -0.52718551420461,
+ -0.42379363297515 },
+ { 0.35878268156959, -0.54570539388485, 0.533316880214, 0.53763715995969 },
+ { 0.74780942148728, 0.59755384906022, -0.26296181239253, 0.12067125519944 },
+ { 0.011316905138058, 0.067102377315201, -0.065593365654346,
+ 0.99552333423124 },
+ { 0.49827563594909, -0.084377896327059, -0.53850763396471,
+ 0.67424868512491 },
+ { -0.60044976118633, -0.76761748085432, -0.13587914428152,
+ 0.17821432469774 },
+ { -0.089523490602341, 0.050789198860078, 0.84713826909812,
+ 0.52130869447859 },
+ { 0.46769441316167, 0.50567662542845, 0.70334020343911, 0.175686210668 },
+ { -0.072408203487527, -0.31419198049473, 0.093326787268646,
+ -0.94198225155181 },
+ { -0.47533232374788, 0.74785636631068, 0.46059616621554,
+ 0.051197744448182 },
+ { -0.76253271533295, -0.055650486369972, 0.42686845243099,
+ 0.48293913253423 },
+ { 0.55865209759069, 0.49155664008023, -0.11550774589067,
+ -0.65798013958615 },
+ { -0.75641809583475, 0.13770124300455, 0.17748717881056, 0.61430312820838 },
+ { -0.61344640313317, -0.71640963441606, 0.33111243107609,
+ 0.028377881980612 },
+ { -0.031294256698522, -0.56229739591621, -0.75650470039123,
+ -0.3324799938786 },
+ { -0.31717913354911, -0.35531289896521, -0.26284619748583,
+ -0.83908403484825 },
+ { -0.55737524479375, -0.37655617201624, -0.17745250976186,
+ 0.71836543109117 },
+ { 0.48847471582806, 0.27948593392061, 0.6728110320026, -0.4802138897958 },
+ { -0.2401291096457, 0.022664846959043, -0.38631652993552,
+ -0.89027178665375 },
+ { 0.28762309079035, -0.16511988268503, 0.68256059934388,
+ -0.65124450877502 },
+ { -0.70891164838165, 0.31807128215605, -0.3269335982313, 0.53794921377761 },
+ { -0.69925979018203, -0.69254454516254, 0.1409638893828,
+ -0.10745687828272 },
+ { -0.64120757688022, -0.40145811379293, -0.28410809936898,
+ -0.58903889013729 },
+ { 0.55206757527974, 0.3654706551822, -0.61301107780799, -0.43112644434103 },
+ { 0.83974327448309, -0.41693097107897, 0.037330301823741,
+ 0.34584136085972 },
+ { -0.29447692882523, -0.65463017535059, -0.54293549296166,
+ -0.43584827909789 },
+ { -0.05333405362299, 0.9970375499538, 0.047225492146849,
+ -0.029006130347889 },
+ { 0.36963990470761, 0.71417634995674, -0.13865235293535, 0.57800865654045 },
+ { 0.012132225757714, -0.042395617365683, 0.98893274157796,
+ 0.14165963914058 },
+ { -0.58926155813878, -0.12803001087421, 0.79159291473138,
+ -0.098791648242605 },
+ { -0.19438700623313, 0.67901470490797, -0.70701504134766,
+ -0.035811361809222 },
+ { 0.34532714734742, 0.46443499574166, 0.60148495729299, 0.55069514450882 },
+ { 0.081003548026406, 0.72421956716693, -0.17809963017465,
+ 0.66122988851937 },
+ { -0.51806271332971, -0.47124904656651, -0.64746889488023,
+ 0.30053184744748 },
+ { -0.21613493655961, -0.91660583460148, -0.10703233312329,
+ -0.31884716219386 },
+ { 0.51867393084966, -0.4936987587863, 0.46464576962979, -0.52090613146226 },
+ { 0.70188550832442, -0.1818312879146, -0.68784926160938,
+ -0.034022187509377 },
+ { -0.18536271511511, -0.6668126355463, 0.023834990060033,
+ 0.72141074719593 },
+ { -0.15031909443203, -0.33262730296075, -0.48817739687091,
+ -0.79274590907714 },
+ { 0.20243051601476, -0.5429805329116, 0.6054719468901, 0.54552520436194 },
+ { 0.52537152557096, -0.58327808848175, 0.46508915228105, 0.40922305903604 },
+ { 0.31485477581576, 0.73539414558825, -0.57616972550483, 0.16760181440614 },
+ { -0.1026518864305, -0.84929281956374, 0.44243387033807, 0.26910326498838 },
+ { 0.027920771196629, -0.51581324522376, 0.27916735407976,
+ -0.80945828490641 },
+ { 0.52095648805607, -0.31217499797683, 0.78890796559237,
+ -0.093676731451121 },
+ { -0.32665063346977, -0.42237533445303, -0.29678775049627,
+ -0.79171678752876 },
+ { -0.64857997918119, 0.22770551134203, -0.62280006685563,
+ -0.37364995307697 },
+ { -0.60407573890498, -0.71425303787341, -0.057839679785266,
+ 0.34869710494546 },
+ { 0.15576683671559, 0.46059388821688, 0.68108199108405, -0.54746441358124 },
+ { -0.42965263988294, -0.4128555315267, -0.80007348682047,
+ -0.069507803996135 },
+ { 0.62468470253348, -0.55608652633181, 0.44736045231719,
+ -0.31686814821852 },
+ { -0.5887363856243, 0.15029359337305, 0.75607823697339, 0.24320156991324 },
+ { 0.78882247105678, -0.55978440598547, -0.19260987829514,
+ -0.16523305587714 },
+ { -0.2397762652948, 0.50109182594502, 0.26413811744859, 0.7884449121423 },
+ { -0.7830303555834, -0.22084579025076, -0.28393537655337,
+ -0.50741629960512 },
+ { -0.73073108036106, -0.028836092490741, 0.67193346093654,
+ 0.11707259302706 },
+ { 0.024769701828925, -0.022793005056951, -0.61772537208025,
+ -0.78567315435879 },
+ { -0.58543792858876, -0.21000596085194, -0.34309660713653,
+ -0.70387828944198 },
+ { -0.73256166113309, -0.39947841108428, -0.55115200779339,
+ -0.0013696790967066 },
+ { -0.65553402559555, 0.71965699083607, 0.18362339375227, 0.13657015081697 },
+ { 0.21014780367008, 0.93277837816337, 0.091205127277356,
+ -0.27828766160555 },
+ { -0.11787197549632, -0.78483975651814, 0.20342129122119,
+ 0.57336945528955 },
+ { -0.6881964578452, -0.22721428035754, -0.50932656202979,
+ -0.46405361696881 },
+ { -0.30800922001431, 0.76151734782072, 0.45056635743119,
+ -0.34958776709928 },
+ { 0.56307840922658, 0.61616965967068, -0.39982036117689, 0.37871009275244 },
+ { 0.32091099001565, 0.42988923391959, 0.65069385181346, 0.53740942888953 },
+ { -0.65360317449729, 0.21381907132369, -0.37900175759245, 0.6192269073346 },
+ { 0.34144172603729, -0.68022974823899, 0.36172522685587,
+ -0.53838638317427 },
+ { -0.082427387138187, -0.81983951792536, -0.062698716423876,
+ 0.56314985719281 },
+ { 0.53660230478027, -0.10888689641277, 0.49610311211367, 0.67385704154904 },
+ { 0.37828905310898, 0.24829585477921, 0.45837561130552, 0.7649433702946 },
+ { 0.31077471220013, -0.64394458615427, -0.42742602417387,
+ -0.55322820072594 },
+ { -0.74914861903498, -0.44168063108052, -0.42549539767358,
+ 0.2502962909931 },
+ { 0.63772244990386, -0.68871779209415, -0.16359297580573,
+ 0.30366958690097 },
+ { -0.10823423405648, -0.47886043588247, 0.5951258423328, 0.63624151492365 },
+ { -0.58450908643191, -0.23751295715095, 0.68158351804545,
+ -0.37064893226977 },
+ { -0.51170891961924, 0.51317237144319, -0.3868723565637,
+ -0.57020862716758 },
+ { -0.65861950006955, 0.33272485253463, -0.34970834814331,
+ -0.57725089681422 },
+ { 0.67192193031742, 0.52947366261195, 0.23487166423469, -0.46153424737329 },
+ { -0.44355315014768, 0.64728264624511, 0.5825071861006, -0.21206403986806 },
+ { 0.68832586073433, -0.19106885563402, -0.36416840615895,
+ -0.59756302914981 },
+ { 0.062746887857648, 0.79955877089706, 0.59681863174015,
+ -0.02400251556763 },
+ { 0.28392054221674, -0.049695747604861, -0.95198891214713,
+ 0.10313374581711 } };
+
+ public static final double[][] gradient6DLUT = {
+ { 0.31733186658157, 0.043599150809166, -0.63578104939541,
+ 0.60224147484783, -0.061995657882187, 0.35587048501823 },
+ { -0.54645425808647, -0.75981513883963, -0.035144342454363,
+ 0.13137365402959, 0.29650029456531, 0.13289887942467 },
+ { 0.72720729277573, -0.0170513084554, 0.10403853926717, 0.57016794579524,
+ 0.10006650294475, -0.35348266879289 },
+ { 0.0524867271859, 0.16599786784909, -0.49406271077513, 0.51847470894887,
+ 0.63927166664011, -0.21933445140234 },
+ { -0.57224122530978, -0.089985946187774, 0.44829955643248,
+ 0.53836681748476, -0.051299333576026, -0.41352093713992 },
+ { -0.35034584363296, -0.37367516013323, -0.52676009109159,
+ 0.12379417201967, 0.42566489477591, 0.51345191723381 },
+ { 0.40936909283115, 0.33036021753157, 0.46771483894695, 0.15073372728805,
+ 0.51541333179083, -0.46491971651678 },
+ { -0.64339751231027, -0.29341468636474, -0.50841617762291,
+ -0.080659811936781, -0.46873502824317, -0.12345817650503 },
+ { 0.46950904113222, 0.41685007896275, -0.33378791988356,
+ -0.39617029121348, 0.54659770033168, 0.19662896748851 },
+ { -0.49213884108338, 0.50450587466563, -0.0073247243900323,
+ 0.57958418990163, 0.39591449230465, 0.10272980841415 },
+ { 0.34572956497624, 0.62770109739866, 0.12165109216674, 0.35267248385686,
+ 0.34842369637704, -0.47527514024373 },
+ { 0.076282233884284, 0.56461194794873, -0.392426730607,
+ -0.20639693057567, 0.33197602170266, 0.60711436994661 },
+ { 0.46792592791359, -0.38434666353171, -0.46719345820863,
+ -0.40169520060432, -0.061343490026986, 0.49993117813162 },
+ { -0.25398819915038, -0.82255018555745, 0.40372967512401,
+ 0.21051604195389, 0.020384827146984, 0.22621006002887 },
+ { 0.23269489013955, -0.42234243708413, -0.18886779174866,
+ 0.44290933725703, -0.40895242871151, 0.60695810498111 },
+ { -0.13615585122038, 0.26142849716038, 0.68738606675966,
+ 0.42914965171764, 0.26332301994884, 0.43256061294487 },
+ { 0.06145597366231, -0.25432792035414, 0.65050463165568,
+ 0.35622065678761, -0.52670947710524, -0.32259598080167 },
+ { -0.28027055313228, 0.30275296247348, 0.39083872911587,
+ 0.17564171472763, 0.25278203996272, 0.76307625890429 },
+ { -0.62937098181034, -0.24958587788613, 0.11855057687171,
+ 0.52714220921895, 0.47759151204224, -0.14687496867489 },
+ { 0.68607574135496, 0.28465344118508, 0.57132493696771, 0.11365238375433,
+ -0.32111327299854, -0.076352560636185 },
+ { 0.42669573845021, -0.1643996530281, -0.54881376863042,
+ -0.56551221465284, 0.4027156095588, -0.087880721039792 },
+ { -0.30211042220321, -0.47278547361731, 0.050137867251391,
+ 0.46804387457884, -0.39450159355792, 0.55497099667426 },
+ { 0.31255895138908, 0.034478918459459, -0.079232996020732,
+ 0.39803160685016, 0.82281399721198, 0.24369695191021 },
+ { -0.5524321671417, 0.49350231710234, 0.52530668244467, 0.253625789825,
+ 0.26218499242504, -0.20557247282514 },
+ { 0.060763010271891, -0.023938406391206, 0.36557410300471,
+ 0.55368747615095, 0.25557899769702, -0.70014279913759 },
+ { 0.36398574324757, 0.049110464042478, -0.2428951164628,
+ -0.18733973495522, 0.020130805835303, 0.87784000694654 },
+ { -0.62385490124849, 0.020947599003133, -0.44548631925386,
+ -0.21069894502123, -0.60559127508405, 0.027809382425643 },
+ { 0.51562840479369, -0.27416131751628, -0.14365580420426,
+ -0.46525735490594, 0.16338488557607, 0.62862302132303 },
+ { 0.52085189275139, 0.51359303425374, 0.021844789421786,
+ 0.53521775458267, -0.23767218281397, -0.34858599348565 },
+ { 0.12263603513069, 0.53912951801629, 0.57550729534804,
+ -0.10335514143554, 0.57524709075397, 0.14662748040551 },
+ { 0.40942178494947, 0.17197663954561, -0.025238012475873,
+ -0.20104824969996, -0.60303014654018, 0.63094779803243 },
+ { 0.051685704973311, 0.23577798459204, -0.19154992327678,
+ -0.67743578708385, -0.51070301615526, 0.43047548181493 },
+ { 0.21373839204543, -0.44348268823586, 0.34347986958921,
+ -0.49945694096162, 0.45888698118478, -0.42382317871053 },
+ { -0.60376535923059, -0.065300874745824, 0.49448067868339,
+ 0.12358559784007, 0.58623743735263, -0.16656623971303 },
+ { 0.44140930948322, -0.41692548571374, -0.23774988226818,
+ -0.27542786466885, 0.39264397083621, 0.58717642823542 },
+ { -0.67860697457746, 0.2070991391515, -0.12832398784247,
+ -0.58381216132288, 0.24050209342748, 0.2854077401022 },
+ { -0.021324501342617, 0.0098658783730532, 0.2694901128571,
+ 0.42580554353158, -0.82903198308789, -0.24128534823695 },
+ { -0.20344882384938, 0.51719618805529, 0.24379623299129,
+ 0.11303683173372, -0.46058654895958, -0.63777957124993 },
+ { 0.15686479897897, -0.67777169905813, -0.04974608057712,
+ 0.51313211803344, 0.49928667286231, -0.030863149692696 },
+ { 0.53527130791104, -0.50102597915466, -0.60754472649714,
+ -0.25235098830686, 0.13490559284448, 0.10708155847142 },
+ { -0.20613512232544, 0.39533044356843, -0.34422306275706,
+ 0.4792145528465, -0.19178040223502, -0.64521804411898 },
+ { 0.3304779611047, 0.49148538926455, -0.30004348427342, 0.33473309391851,
+ 0.31079743137844, 0.59208027276116 },
+ { -0.52688857216953, 0.40250311061529, 0.38833191043333,
+ 0.50432308135853, -0.33327489215794, -0.21015252001231 },
+ { -0.30306420816123, -0.34460825415019, -0.26894228639121,
+ -0.58579646837355, -0.51178483212848, 0.33464319317466 },
+ { -0.20258582390514, -0.29195675136034, 0.11887973573086,
+ 0.91211540292822, 0.034118810787236, -0.16269371903027 },
+ { 0.61207678339522, -0.21883722070929, -0.23415725333464,
+ 0.0041447691596985, -0.34019274152454, 0.6378827339521 },
+ { 0.11272999861808, -0.54780877011146, -0.62497664375172,
+ -0.41373740141301, 0.33306010353229, 0.12039112788093 },
+ { 0.24918468395037, -0.068734287809286, -0.42234580029763,
+ 0.12235329631887, -0.26545138767734, 0.81815148205875 },
+ { 0.32048708659406, -0.40233908147851, 0.24633289057781,
+ -0.37087758270512, -0.55466799718133, -0.47908728788262 },
+ { -0.33748729653627, -0.45507986822699, -0.50597645316527,
+ -0.2863701644881, -0.5404199724601, -0.22120318557996 },
+ { -0.23520314824941, 0.82195093398991, -0.22661283339659,
+ 0.16382454786402, -0.41400232366734, -0.13959354720703 },
+ { -0.30495751902889, -0.47964557116121, -0.68490238495876,
+ -0.4324077675155, -0.13521732523742, -0.050887702629247 },
+ { -0.56629250538137, 0.19768903044, -0.080075220953828,
+ -0.29952637623112, 0.095974426142512, -0.73136356489112 },
+ { -0.21316607993139, 0.47585902758173, -0.49429850443227,
+ -0.24146904800157, 0.45631329089651, 0.46610972545109 },
+ { 0.12647584748018, -0.10203700758813, 0.20801341293098,
+ 0.66418891258418, -0.65219775460192, -0.2526141453282 },
+ { -0.69345279552921, 0.30149980453822, -0.46870940095961,
+ 0.20092958919922, -0.21817920622376, 0.34721422759447 },
+ { -0.69001417476102, 0.09722776919634, -0.37852252163632,
+ -0.24995374433763, 0.24829304775112, 0.4970126640943 },
+ { -0.82278510972964, 0.050748830242865, -0.3934733016285,
+ 0.00029980431140623, -0.34677214869339, -0.21301870187776 },
+ { -0.51821811089111, -0.22147302694699, 0.53524316281446,
+ 0.12892242816244, -0.5543955478928, -0.26821451961648 },
+ { -0.21006612796354, 0.26079212570498, -0.021870637510645,
+ 0.72402587064608, -0.27651658712238, 0.53544979218311 },
+ { -0.099744280251479, -0.4534212871731, 0.71954978543864,
+ -0.31082396323078, -0.26933824624449, 0.31233586755618 },
+ { -0.48121951222937, -0.43051247772929, -0.5038415181805,
+ 0.12342710418307, 0.037467829082858, -0.55909965468017 },
+ { -0.51180831908824, -0.079955485578946, -0.53046702060975,
+ 0.48748209854708, 0.16148937559829, -0.43191028009105 },
+ { -0.38131649706702, 0.46242477534251, 0.46416075424014,
+ -0.20634110277567, -0.53778490132009, 0.30582118902172 },
+ { 0.6245043069106, 0.14316692963071, -0.1436103838143, 0.27519251589203,
+ -0.60467865310212, -0.35708047307373 },
+ { 0.52425890739441, -0.20390682829262, -0.33609142609195,
+ 0.51803372559413, 0.28921536255925, 0.46756035964091 },
+ { -0.4455164148456, 0.31831805515328, 0.24217750314789, 0.49821219078654,
+ -0.47209418708575, 0.41285649844363 },
+ { -0.015857310429397, -0.45214512052441, -0.14591363373753,
+ 0.74070676188619, 0.0098874230592725, -0.47463489014478 },
+ { 0.24260837156464, 0.44639366601915, 0.31528570191456, 0.45334773303464,
+ -0.47964168123625, -0.45484996397296 },
+ { 0.47123463487178, 0.64525048646519, -0.064257637508608,
+ -0.18737730572971, -0.11735335340515, -0.55549853319118 },
+ { -0.025197229767488, -0.257963271803, 0.26277107860996,
+ -0.58236203161499, -0.41893538667715, 0.59086294196016 },
+ { -0.48940330017687, 0.33728563842186, -0.057634928591543,
+ 0.44862021996899, -0.40048256377746, 0.53080564921806 },
+ { 0.73350664260388, -0.021482988114587, 0.016568147533453,
+ 0.0021905972927896, 0.49384961731337, 0.46619710394628 },
+ { -0.25151229880228, -0.62009962583403, -0.26948657433033,
+ 0.31711936293198, -0.35081923073755, 0.50592112116981 },
+ { 0.0094298597779172, -0.35925999444899, 0.47529205807388,
+ -0.26709475088579, -0.53352146543694, 0.53754630836074 },
+ { -0.5948549517534, -0.53195924881292, -0.094383768924555,
+ -0.41704491211939, -0.41397531920841, -0.09463944474724 },
+ { -0.74917126125127, -0.24166385705367, 0.22864554725283,
+ 0.31721357549513, 0.06066292638611, -0.47303041351952 },
+ { -0.3300396030254, -0.08758658200966, -0.096726092930468,
+ -0.39607089556472, 0.55566932028997, 0.63906648027271 },
+ { -0.58933068378397, -0.38176870540341, 0.46748019640554,
+ -0.061358837959321, 0.36268480315292, -0.39127879224432 },
+ { -0.066556695042975, -0.73863083674701, -0.32153946998935,
+ 0.57454599361106, -0.090856896694743, -0.09082394033963 },
+ { -0.36335404704287, -0.41643677881158, -0.57839830999334,
+ -0.030959887755637, 0.5989792522053, -0.016582566905843 },
+ { 0.23126668855143, 0.2107790785413, -0.14272193312959,
+ -0.29232225134991, -0.48451339172564, -0.74934159314943 },
+ { 0.48188197979627, -0.040214759215399, -0.15667971883369,
+ 0.16054853668069, -0.6083975436752, -0.58796308779952 },
+ { 0.31319356064062, -0.19280657835646, 0.76136690598738,
+ -0.084506239097717, 0.4768786755523, -0.22472488900872 },
+ { 0.67504537519138, 0.36920158913876, 0.40321048682396,
+ 0.034436041975613, -0.29332731631919, 0.39774172001359 },
+ { -0.1459159803857, -0.59726183207777, -0.036384224081948,
+ -0.65093487874945, 0.39515711468056, -0.20198429937477 },
+ { 0.60092128630869, 0.18110182176699, 0.2579491954112, -0.39594768022975,
+ 0.15112959843347, 0.59995268930018 },
+ { -0.42310244265976, -0.26937197256148, 0.074700012546319,
+ 0.53119510349465, 0.41614374632783, 0.53618944036115 },
+ { 0.0071605427687482, -0.69599782505338, -0.053138604739257,
+ -0.00054500262230378, 0.69533871546989, 0.1709263483943 },
+ { 0.12447149375466, 0.33265313001972, 0.35070015349473, 0.53879932284829,
+ 0.37648083373421, 0.56463759722353 },
+ { 0.29540077719054, 0.04954124873475, -0.48345087234985,
+ 0.72758494948264, 0.070069102610626, 0.377186640377 },
+ { 0.4882414260383, 0.45135801463006, 0.48450857902353, -0.26042407965644,
+ -0.4251358047458, 0.2731053563007 },
+ { -0.49806371818291, -0.4719759672029, 0.029647087810764,
+ -0.13788472163255, -0.45346141932978, -0.5510470160674 },
+ { -0.5359511936033, -0.53585470245895, 0.1771036246335, -0.4537763243703,
+ 0.41838964069644, 0.11527149720722 },
+ { -0.36846431808379, -0.46533180802325, 0.65800816763703,
+ -0.28691297783558, 0.31521457275327, 0.18178647457201 },
+ { -0.29243126901345, -0.4352956525447, -0.58895978125929,
+ -0.49649471729812, 0.29271342931272, 0.21433587621517 },
+ { 0.056256690265475, -0.50387710054371, 0.48145041862725,
+ 0.44723671964597, -0.55771174894027, -0.0092449146014199 },
+ { -0.40973125164006, -0.73147173623276, -0.094076302480945,
+ 0.43033451471976, 0.014334271843521, -0.32066459724334 },
+ { 0.26752725373294, 0.50477344684769, 0.065069516529324,
+ 0.36001097578267, 0.59393393889869, -0.43247366096278 },
+ { 0.48945720845334, 0.6043315650632, 0.12458128550608, -0.48327805813458,
+ -0.25681943056744, 0.28316179557217 },
+ { -0.45182760404001, 0.21574002665039, -0.31462623994251,
+ 0.25279349500371, 0.44865729380505, -0.62058075048081 },
+ { 0.44017304540101, 0.43789555905674, 0.58423563606269, 0.41842994331139,
+ -0.26836655962348, 0.16143005677844 },
+ { -0.67897032028819, -0.32730885869255, -0.0243997359109,
+ 0.40649244381227, 0.47711065295824, -0.19596475712206 },
+ { 0.57441588138131, 0.09386994843744, 0.28400793066375, 0.59394229842661,
+ 0.45349906020748, 0.14881354725974 },
+ { -0.3393739967757, -0.54929055652002, 0.26209493900588, 0.0733800373509,
+ 0.56557076402003, 0.43492125584075 },
+ { 0.050007991188197, 0.74652764513134, -0.36432144611385,
+ -0.20993543754239, -0.1352041047841, 0.49508839805322 },
+ { -0.041332158875019, -0.20655741061568, 0.52511282214888,
+ 0.047248635933477, -0.6276121766011, -0.5326844609727 },
+ { -0.1889491176448, 0.05188976739355, -0.45677123586268,
+ 0.42884456750344, 0.61612085530435, -0.43526216197988 },
+ { -0.65873541163911, -0.094770059351695, 0.40844030815782,
+ 0.35536013391048, -0.16940065827957, 0.48506226422661 },
+ { -0.45779281442862, -0.46052673126242, 0.34138050378631,
+ -0.54943270263121, 0.37140594702643, -0.14826175595089 },
+ { -0.069378715405383, -0.14845488608058, -0.73991837897813,
+ 0.41519184526768, -0.11098464009855, -0.49088356499611 },
+ { 0.46422563805447, 0.46130716873201, -0.44207791495441,
+ 0.12050605352899, 0.34969556083561, -0.4893349322843 },
+ { -0.35482925073362, 0.28146983672487, -0.35356606227648,
+ -0.38774754218768, 0.35979702647173, -0.62454776976122 },
+ { -0.48343191508515, 0.41492185792886, -0.50175316406656,
+ 0.21953122931153, -0.54083165333237, 0.041040952107647 },
+ { -0.51280508048852, -0.54131124436697, -0.0099287129207481,
+ 0.23788701199175, 0.4350333223576, 0.44505087885649 },
+ { 0.2253837335044, -0.30117119745248, 0.46587685049056,
+ -0.46672901001472, -0.59182069765377, 0.27086737661249 },
+ { 0.43015756480475, -0.067851118947538, -0.26917802105288,
+ -0.57731860676632, -0.53950120703807, -0.33696522367557 },
+ { 0.20858352742161, 0.63695057987625, 0.49453142202915,
+ -0.046235371593379, -0.54436247241885, -0.088075720520231 },
+ { -0.35626464703623, 0.067539543974725, -0.18142793486226,
+ -0.49044207117167, 0.5542388249925, 0.53654796190017 },
+ { 0.52238539932434, 0.55175875223621, 0.29070268774296,
+ -0.14119026819648, -0.55841587206055, -0.080029639759127 },
+ { -0.025988002903175, 0.46612949273683, -0.56880970348453,
+ -0.44824563336003, -0.030000490931808, 0.50663523727173 },
+ { 0.047284583258099, -0.26595723160738, 0.21032033434131,
+ 0.52986834914146, -0.52245334572957, -0.5736534757312 },
+ { -0.31924244568277, -0.13888420092891, 0.30725800370737,
+ 0.49792332552544, 0.61035592292817, -0.40487771982263 },
+ { 0.038758575627018, -0.53813545398707, -0.56167256912901,
+ 0.46815373895572, -0.14142713486975, 0.39276248966752 },
+ { -0.19936871608885, 0.12488860648831, -0.62990029833727,
+ -0.29296146144627, 0.49734531468753, 0.46335923993672 },
+ { -0.078826705546604, -0.15548800857414, 0.57456768467721,
+ 0.5558854465212, -0.56893054194692, -0.082408823513622 },
+ { 0.11678856295109, 0.53358760166951, 0.49302489382249,
+ -0.53981846952046, -0.237913367643, -0.33251226509871 },
+ { 0.39126928439834, -0.39416116630681, -0.35778844984527,
+ -0.39395609960567, 0.50270356681194, -0.39448759513757 },
+ { -0.17961290695406, 0.34239532682819, -0.21870225043453,
+ -0.23322835296688, 0.75997835134209, 0.41317237364121 },
+ { 0.29699501400111, 0.17195435585404, -0.34903627841034,
+ -0.31751884057854, -0.59661546358767, 0.55102732418683 },
+ { -0.2237291316445, -0.51254305965518, -0.31277318571798,
+ 0.54270199705442, -0.34885011313806, 0.41616819064585 },
+ { 0.53534023676892, 0.45905986582643, -0.20308675275303,
+ 0.019523641323632, 0.3378580580099, 0.58898336258938 },
+ { -0.045038463119119, -0.52553334288797, -0.6098545897634,
+ 0.46226027841702, -0.36069029000651, 0.077984430434637 },
+ { -0.40129033029845, 0.39526722066586, -0.20379584931963,
+ 0.45466492237669, 0.46504795737483, -0.46712669863522 },
+ { -0.43845831945339, -0.59284534057943, 0.050241908216277,
+ -0.36494839821973, 0.32363879325018, 0.46458051299488 },
+ { -0.46057360356064, -0.34584626825548, -0.12264748451482,
+ 0.48835437094478, 0.21102526990984, 0.60843919401837 },
+ { -0.086047549693024, -0.16981605114589, -0.37222833669973,
+ 0.45158609930017, -0.55710254634126, 0.55759406480139 },
+ { 0.54697451263099, -0.45070837355303, 0.032962522247893,
+ -0.48584332140086, -0.28055687213837, 0.42642516953676 },
+ { 0.34061925303691, 0.38443007758012, 0.61614808332652,
+ -0.55774172327958, -0.075660378162998, 0.19938218730551 },
+ { 0.30626924920956, -0.057939049897675, -0.10461119704504,
+ -0.4395638756485, -0.57307193269415, 0.60849886616281 },
+ { -0.52519951444608, -0.42567534157254, -0.19896500097138,
+ 0.48819483593271, 0.12539008064447, 0.49932157157064 },
+ { -0.10173361116951, -0.07873850987854, 0.3713554090283,
+ 0.65889542748449, 0.63411890875068, 0.096414235519521 },
+ { 0.60342393773609, 0.057617370697663, 0.35558841250938,
+ 0.20766418929404, 0.030670189501999, -0.67974377143949 },
+ { -0.071971052874019, -0.44567383014704, 0.65917594080871,
+ 0.44113802003588, -0.29627117199757, 0.28160739274962 },
+ { 0.38284479693596, 0.43552320173998, -0.4282368470258,
+ -0.54809258921772, -0.27202273485667, 0.32551612927831 },
+ { -0.74755699288716, -0.20979308948438, 0.19268299390085,
+ 0.27864013929953, -0.39085278833717, 0.36001727246301 },
+ { -0.64575536737195, 0.59253747557756, 0.040885512266333,
+ -0.20167391777406, -0.43481684011627, -0.02212841779644 },
+ { 0.45874103754271, -0.0066587566394561, -0.30494054091993,
+ 0.52731059172348, -0.64443887148677, 0.056264275617853 },
+ { 0.61573773369959, -0.00074622703454316, 0.25455659350429,
+ 0.30670278147618, -0.18573195942296, 0.65383825999316 },
+ { -0.089919562456316, -0.28968403215216, -0.60618287937171,
+ 0.53370861364121, 0.37921556323246, -0.33450055738044 },
+ { -0.47481167613763, 0.3899274103573, -0.1047963185367, 0.45545456567005,
+ 0.12142073778317, 0.62397625076847 },
+ { 0.59154225785278, -0.10812441303593, -0.4685834521013,
+ -0.36007270807588, -0.1012374701199, 0.52812407295968 },
+ { -0.01292122984647, -0.23607532114711, -0.57680411110671,
+ -0.44955815301222, -0.31913443306122, -0.55448100298376 },
+ { 0.54231398466289, -0.31845386154668, -0.38636423612049,
+ 0.22187979539931, -0.6346425853783, -0.056599490898788 },
+ { -0.41950690366157, -0.4578028963184, 0.31139813874057,
+ 0.39787962066193, -0.20885901240181, 0.56172180435883 },
+ { -0.031404881097728, 0.56267475273157, -0.5556815383811,
+ 0.33075363850824, 0.39071115867626, 0.3340294973255 },
+ { -0.51485161085589, -0.34037011091125, -0.46826090820473,
+ -0.60086679836276, -0.075069409610657, 0.18202033570633 },
+ { -0.49669644859095, 0.13236483793072, 0.53440735955877, 0.4720120049858,
+ -0.05992551666341, -0.47306929861073 },
+ { -0.32796852486185, 0.65593302097807, 0.20800030327303,
+ -0.38965914824176, -0.51564565153044, -0.034636725857177 },
+ { -0.30473794783797, 0.12584230588041, 0.63911213518179,
+ 0.11269477188219, 0.62944339013855, 0.27191006392352 },
+ { -0.53642197294029, 0.50742224701512, -0.22907820767928,
+ 0.47022559371179, -0.1914125650624, 0.38019261684316 },
+ { -0.28865425091309, 0.76169672032907, -0.36166127667225,
+ -0.30555403321368, -0.12541657537884, -0.31081403770203 },
+ { 0.0025978417989835, 0.3737146483793, -0.3151511957077,
+ 0.62032810853005, 0.60524642517936, -0.09939888944988 },
+ { -0.40019833530022, 0.15931480693456, -0.61653030345628,
+ -0.49479441153976, -0.021517911098538, -0.43481713333933 },
+ { -0.26445143166732, -0.48401155081335, 0.27737058096082,
+ -0.12537486208624, -0.46956235249512, 0.61859207953377 },
+ { -0.49776294425122, 0.6509513246149, -0.20147785800704,
+ 0.26022926925791, 0.39526195830317, -0.25288299425858 },
+ { 0.20792543895216, 0.6725599557329, 0.013296712014115,
+ 0.069082404776847, -0.37233547685047, 0.60070560947898 },
+ { -0.60329265885108, 0.40708027238668, -0.17229997007444,
+ -0.52997954496878, 0.22211745651394, -0.33229784433365 },
+ { 0.61826884506104, -0.62582169643111, 0.33820439950773,
+ 0.23870919720066, -0.20670655096227, -0.10953969425599 },
+ { -0.63678168786213, -0.51101649337563, -0.19131817442969,
+ -0.49493417544846, -0.22614515287593, 0.025828539221376 },
+ { 0.7068462559507, 0.072932806612059, -0.30827034359477,
+ -0.52659704221432, -0.33954839093364, 0.086145323573817 },
+ { -0.52429050496975, 0.39091424683727, 0.52819210715237,
+ -0.16569162349745, 0.447191673089, 0.25667977984796 },
+ { 0.85033978527922, -0.37311666188152, -0.031585518143925,
+ -0.063546921071094, -0.35026506762952, 0.099923633151172 },
+ { -0.43149574251927, 0.16017753208259, -0.36624037246965,
+ 0.49372029676385, -0.60067103922455, 0.2223896202103 },
+ { -0.43599537393092, -0.360658355506, -0.42475053011196,
+ -0.52301759011739, 0.039454536357949, 0.47362064109658 },
+ { -0.35793170214797, -0.43917817788312, -0.49072242572643,
+ -0.32880277826743, -0.38509560837703, -0.42636724894184 },
+ { -0.043679644403255, 0.74697226557232, -0.40732954428872,
+ -0.48088968590275, 0.18029290312902, -0.10220931735307 },
+ { -0.058902573502295, 0.0082595236590186, 0.7136596141971,
+ -0.53043791172483, 0.22906331492979, 0.39155822265168 },
+ { 0.43459649233879, 0.18964470832196, 0.15217427204218, 0.59694624534505,
+ 0.053786588105393, 0.62671041756872 },
+ { -0.48833575031057, 0.068909881680922, 0.60168404074737,
+ -0.055455043023162, -0.62426261497771, -0.044461939113733 },
+ { -0.71822145541427, 0.054494951105527, 0.25733756171599,
+ -0.42706881935297, -0.44024663347316, 0.19687748949208 },
+ { 0.4723221071836, 0.63009683957253, 0.2166256995021, 0.31063720960745,
+ 0.079455887335627, 0.47974409023622 },
+ { -0.39506538843406, 0.42517729990346, 0.29375773990216,
+ 0.044503633424429, -0.46173213926286, 0.60139575234582 },
+ { -0.40354126620316, 0.41304136826673, -0.29533980868045,
+ -0.45300699221804, 0.23702354154238, -0.56385297528377 },
+ { -0.62315380378984, -0.42397903326965, 0.53044082394843,
+ 0.37874432092957, 0.054922713129263, 0.063952196248596 },
+ { 0.41959045692314, -0.83420441875842, -0.25505372502578,
+ 0.25012310515014, 0.010974237503127, 0.017675743681809 },
+ { -0.25231575134089, -0.17034034508503, -0.0022254428444259,
+ -0.4967771056787, 0.43184899693064, -0.68850194407078 },
+ { -0.1852812882862, -0.48330898597592, 0.13528868642679,
+ 0.15202104844417, 0.57661281495368, -0.59848767913131 },
+ { 0.64287473226568, -0.30923674494923, 0.22234318117192,
+ 0.099248962994541, 0.64370450011427, 0.13206961744112 },
+ { -0.49018899717866, 0.68654120859156, -0.27238863334662,
+ -0.085832423495263, 0.44161945604453, 0.10856057983467 },
+ { 0.48795432482822, 0.42184193883513, -0.43797315744756,
+ 0.35186997012044, -0.46483432791096, 0.22857392808385 },
+ { 0.52970834834669, -0.50684486922008, -0.39782161731912,
+ -0.3932709335414, -0.34863027587322, 0.16748196501934 },
+ { -0.46048505533, -0.3887126918161, -0.68287320410729, -0.18448530888361,
+ -0.25358256326157, 0.26870280714361 },
+ { 0.6889557358588, -0.3101022706485, -0.35882194962822, 0.30088738418801,
+ -0.039139540883101, -0.45646277242166 },
+ { -0.21954767479275, 0.40838837410593, 0.23284186868997,
+ 0.30349649888064, 0.57233263099925, 0.55778817953937 },
+ { 0.57731035290905, 0.091218309942656, 0.70670016667131,
+ 0.016358033634041, 0.3939245235472, -0.059352634867484 },
+ { 0.50055570130024, -0.021749790970703, 0.56767851040093,
+ 0.50580176326624, 0.34691320957643, 0.22478399991032 },
+ { -0.37901911159632, 0.53804099887537, -0.46780195460858,
+ 0.51497346779204, -0.27981005467588, 0.067278440906787 },
+ { 0.67241900483514, 0.074099582737, 0.43138117954806, 0.054567519697911,
+ -0.37927768894619, 0.45764946429346 },
+ { 0.14529189179172, -0.23854982910384, 0.45401647091062,
+ 0.25466539906731, 0.46182069803887, -0.66160446396375 },
+ { -0.15570980059397, -0.38476787034627, 0.37322840954917,
+ -0.43977613626294, -0.61243005550684, -0.34631643815896 },
+ { -0.19590302894013, 0.42065974653653, 0.43447548638809,
+ -0.10575548452794, 0.70439951675651, -0.29754920754254 },
+ { -0.13558865796725, 0.1427073453776, 0.49647494823192,
+ -0.65533234019218, -0.11714854214663, 0.5211321311867 },
+ { -0.6228374766114, 0.20812698103217, -0.16205154548883,
+ 0.20384566967497, -0.59321895467652, 0.38604941246779 },
+ { 0.44487837128099, -0.37224943035393, -0.22188447638327,
+ 0.48921538939858, 0.41432418029434, -0.45087099253189 },
+ { 0.66422841315008, 0.21517761068003, 0.094012579794123,
+ -0.4358159040875, 0.22245680154647, -0.51404116085847 },
+ { -0.11369362736032, 0.32284689991698, -0.38818285117689,
+ 0.49680024166881, 0.047684866166158, -0.69503480904222 },
+ { -0.5137200731924, -0.50673230867252, 0.32715252974108,
+ -0.26799714004956, -0.47616510509846, 0.27153195326233 },
+ { -0.47315177716491, -0.45711495983609, -0.31178280842352,
+ -0.51697763052226, -0.14302372043059, -0.42689944315384 },
+ { -0.050442035795027, 0.23609184251469, 0.38634880236106,
+ 0.56012774305243, 0.38963669840218, -0.57174382424149 },
+ { -0.15472134925391, -0.15333579424307, -0.14189768300467,
+ 0.032279269476252, -0.66054298438621, -0.70360180527557 },
+ { -0.10345191679557, -0.30503725808375, 0.31038263802383,
+ 0.36878846502877, -0.76824774853417, 0.2714830658427 },
+ { -0.060212868606223, -0.4172755444983, 0.39199300681258,
+ -0.44040104260082, 0.24955102139032, -0.64215903203727 },
+ { 0.25443195353315, -0.013789583113498, 0.44365000614699,
+ 0.53296203342425, -0.55057750350733, -0.38867053403178 },
+ { -0.36068564301268, -0.65616661625162, -0.48495997865466,
+ 0.24088316031012, -0.18080297655217, -0.33682435258394 },
+ { -0.53824550487673, -0.096728907851005, -0.5208619866167,
+ 0.33195321221408, -0.032263947064791, 0.56427315050798 },
+ { 0.40151657866643, -0.44825725748635, -0.54910020122855,
+ -0.095936272447708, 0.5719563905078, 0.00097783623607218 },
+ { 0.21961099467771, 0.62823723408945, -0.010045934028323,
+ -0.6610564872634, -0.17161595423903, -0.30089924032373 },
+ { 0.27961471530636, 0.054523395513076, 0.61485903249347,
+ 0.11958885677663, -0.61032561244673, -0.39241856813031 },
+ { -0.30223065341134, -0.23605925177166, -0.09697276975263,
+ -0.46458104180761, -0.37853464945647, 0.69599203908657 },
+ { 0.0023635513043496, 0.62702100484886, 0.49658954056984,
+ -0.20369645124455, -0.56457560315907, 0.00021299797811461 },
+ { -0.64198493892962, 0.59676262320476, 0.46274573284143,
+ 0.088421912306785, 0.098029994490406, -0.012953072012707 },
+ { -0.053965435026011, 0.13439533803278, -0.33103493780685,
+ 0.55991756423782, -0.58127599631056, -0.46696041830103 },
+ { -0.43965993689353, 0.07544961763381, 0.1509639518808,
+ -0.38868406689028, -0.0033436054452783, -0.79191533434483 },
+ { -0.21743914630025, -0.32019630124298, -0.56067107727615,
+ 0.027284914419519, -0.49444926389798, -0.53908992599417 },
+ { -0.36492599248168, 0.52529904803377, 0.18002253442693,
+ 0.14829474115897, 0.17212619314998, -0.71194315827942 },
+ { 0.0051876209353066, 0.50490293404098, 0.24361032552454,
+ 0.13688117617809, -0.61381291176911, -0.5386997104485 },
+ { 0.66421180843392, 0.21833854629637, -0.087909936660014,
+ 0.15624552502148, -0.68780724971724, 0.077015056461268 },
+ { 0.52710630558705, -0.42143671471468, -0.069964559463205,
+ -0.24196341534187, -0.68814841622245, 0.08695091377684 },
+ { 0.62392249806692, -0.23663281560035, -0.59058622185178,
+ 0.22685863859977, -0.36683948058558, -0.14105848121323 },
+ { 0.18069852004855, -0.083828559172887, 0.66240167877879,
+ 0.16722813432165, -0.25503640214793, -0.65462662498637 },
+ { -0.37112528006203, 0.43100319401562, -0.11342774633614,
+ 0.14418808646988, 0.5753326931164, 0.55842502411684 },
+ { 0.55378724068611, 0.21098160548047, -0.3224976646632, 0.31268307369255,
+ -0.37624695517597, -0.55269271266764 },
+ { 0.2601465870231, 0.56373458886982, -0.21638357910201, 0.41216916619413,
+ -0.25078072187299, -0.57873208070982 },
+ { 0.11217864148346, 0.54196554704815, -0.31989128683717,
+ 0.54691221598945, 0.24062434044524, 0.48409277788476 },
+ { 0.087564423746579, -0.12083081671284, 0.69931172084498,
+ 0.35220575672909, 0.28770484569954, -0.53091668762919 },
+ { 0.3395702120398, 0.042520943289575, -0.30935928261896,
+ 0.61022210846475, 0.54650816974112, 0.34079124619266 },
+ { 0.32746112891934, 0.32095220193351, -0.61142534799442,
+ 0.32197324480666, -0.38236071343678, 0.40749411210419 },
+ { 0.58741915356593, -0.30916030490652, -0.57642977381104,
+ -0.038846190358607, 0.047926713761208, -0.4725265742377 },
+ { 0.026224389898652, 0.031768907187292, -0.12510902263321,
+ 0.36102734397001, -0.72217212865059, 0.57513252722531 },
+ { -0.27510374152496, -0.5153402145828, 0.025774022629799,
+ 0.59201067073603, 0.40728366085253, -0.37645913420642 },
+ { -0.29983338495183, -0.61017291361195, -0.18551919513643,
+ 0.50515945610161, 0.18206593801497, -0.46372136367049 },
+ { -0.64290893575119, -0.34887011406157, -0.55318606770362,
+ -0.21230198963112, -0.19828983785672, 0.2730419816548 },
+ { -0.32778879906348, -0.094317293167129, 0.57811170538439,
+ 0.54346692190204, 0.17699503497579, -0.47197676839855 },
+ { -0.075738705663962, 0.53381750682665, -0.13406342524856,
+ 0.71765386263773, 0.34271060834977, 0.24259408122628 },
+ { -0.30574273227855, 0.17419449782542, -0.78861555508124,
+ 0.43305678368813, 0.064853328282818, 0.25003806266734 },
+ { 0.4397035983709, -0.51651518914239, -0.3972346186176,
+ -0.34513492086703, 0.32129829777342, -0.39965829527563 },
+ { -0.25184899643619, -0.35937572373004, 0.15273239148905,
+ -0.51640931868766, 0.4218715745627, -0.58261460582976 },
+ { -0.57396000790758, 0.1912786199605, 0.45995634753032,
+ -0.43664716984512, 0.4601630113166, 0.14146310231856 },
+ { 0.11500068018889, 0.05112652754666, -0.25672855859366,
+ -0.54715738035577, 0.67669928552409, 0.40118355777989 },
+ { -0.45252668004418, -0.40809988524453, -0.064931545867856,
+ 0.19116562077283, 0.76523014995576, 0.048337406798767 },
+ { -0.080075651760374, 0.75305314115418, 0.34797424409913,
+ 0.29104493928016, 0.0040185919664457, -0.46977598520425 },
+ { -0.3890257668276, 0.49100041230416, -0.17812126809985,
+ -0.43787557151231, -0.46923187878333, 0.40489108352503 },
+ { 0.37433236324043, -0.29441766760791, -0.066285137006724,
+ 0.33217472508825, 0.73917165688328, 0.33479099915638 },
+ { -0.02973230696179, -0.51371026289118, 0.34133522703692,
+ -0.41361792362786, -0.51561746819514, -0.4263412462482 },
+ { 0.51057171220039, -0.23740201245544, 0.26673587003088, 0.5521767379032,
+ 0.16849318602455, 0.52774964064755 } };
+
+ public static final double[] whitenoiseLUT = { -0.714286, 0.301587, 0.333333,
+ -1, 0.396825, -0.0793651, -0.968254, -0.047619, 0.301587, -0.111111,
+ 0.015873, 0.968254, -0.428571, 0.428571, 0.047619, 0.84127, -0.015873,
+ -0.746032, -0.809524, -0.619048, -0.301587, -0.68254, 0.777778, 0.365079,
+ -0.460317, 0.714286, 0.142857, 0.047619, -0.0793651, -0.492063,
+ -0.873016, -0.269841, -0.84127, -0.809524, -0.396825, -0.777778,
+ -0.396825, -0.746032, 0.301587, -0.52381, 0.650794, 0.301587, -0.015873,
+ 0.269841, 0.492063, -0.936508, -0.777778, 0.555556, 0.68254, -0.650794,
+ -0.968254, 0.619048, 0.777778, 0.68254, 0.206349, -0.555556, 0.904762,
+ 0.587302, -0.174603, -0.047619, -0.206349, -0.68254, 0.111111, -0.52381,
+ 0.174603, -0.968254, -0.111111, -0.238095, 0.396825, -0.777778,
+ -0.206349, 0.142857, 0.904762, -0.111111, -0.269841, 0.777778, -0.015873,
+ -0.047619, -0.333333, 0.68254, -0.238095, 0.904762, 0.0793651, 0.68254,
+ -0.301587, -0.333333, 0.206349, 0.52381, 0.904762, -0.015873, -0.555556,
+ 0.396825, 0.460317, -0.142857, 0.587302, 1, -0.650794, -0.333333,
+ -0.365079, 0.015873, -0.873016, -1, -0.777778, 0.174603, -0.84127,
+ -0.428571, 0.365079, -0.587302, -0.587302, 0.650794, 0.714286, 0.84127,
+ 0.936508, 0.746032, 0.047619, -0.52381, -0.714286, -0.746032, -0.206349,
+ -0.301587, -0.174603, 0.460317, 0.238095, 0.968254, 0.555556, -0.269841,
+ 0.206349, -0.0793651, 0.777778, 0.174603, 0.111111, -0.714286, -0.84127,
+ -0.68254, 0.587302, 0.746032, -0.68254, 0.587302, 0.365079, 0.492063,
+ -0.809524, 0.809524, -0.873016, -0.142857, -0.142857, -0.619048,
+ -0.873016, -0.587302, 0.0793651, -0.269841, -0.460317, -0.904762,
+ -0.174603, 0.619048, 0.936508, 0.650794, 0.238095, 0.111111, 0.873016,
+ 0.0793651, 0.460317, -0.746032, -0.460317, 0.428571, -0.714286,
+ -0.365079, -0.428571, 0.206349, 0.746032, -0.492063, 0.269841, 0.269841,
+ -0.365079, 0.492063, 0.873016, 0.142857, 0.714286, -0.936508, 1,
+ -0.142857, -0.904762, -0.301587, -0.968254, 0.619048, 0.269841,
+ -0.809524, 0.936508, 0.714286, 0.333333, 0.428571, 0.0793651, -0.650794,
+ 0.968254, 0.809524, 0.492063, 0.555556, -0.396825, -1, -0.492063,
+ -0.936508, -0.492063, -0.111111, 0.809524, 0.333333, 0.238095, 0.174603,
+ 0.333333, 0.873016, 0.809524, -0.047619, -0.619048, -0.174603, 0.84127,
+ 0.111111, 0.619048, -0.0793651, 0.52381, 1, 0.015873, 0.52381, -0.619048,
+ -0.52381, 1, 0.650794, -0.428571, 0.84127, -0.555556, 0.015873, 0.428571,
+ 0.746032, -0.238095, -0.238095, 0.936508, -0.206349, -0.936508, 0.873016,
+ -0.555556, -0.650794, -0.904762, 0.52381, 0.968254, -0.333333, -0.904762,
+ 0.396825, 0.047619, -0.84127, -0.365079, -0.587302, -1, -0.396825,
+ 0.365079, 0.555556, 0.460317, 0.142857, -0.460317, 0.238095, };
+}
diff --git a/src/com/sudoplay/joise/noise/Util.java b/src/com/sudoplay/joise/noise/Util.java
new file mode 100755
index 000000000..d81b701bb
--- /dev/null
+++ b/src/com/sudoplay/joise/noise/Util.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.joise.noise;
+
+public class Util {
+
+ public static final double TWO_PI = Math.PI * 2.0;
+
+ private static final double INV_LOG_HALF = 1.0 / Math.log(0.5);
+
+ private Util() {}
+
+ public static double clamp(double input, double min, double max) {
+ return (input < min) ? min : (input > max) ? max : input;
+ }
+
+ public static double bias(double b, double t) {
+ return Math.pow(t, Math.log(b) * INV_LOG_HALF);
+ }
+
+ public static double lerp(double t, double a, double b) {
+ return a + t * (b - a);
+ }
+
+ public static double gain(double g, double t) {
+ g = clamp(g, 0.0, 1.0);
+ if (t < 0.5) {
+ return bias(1.0 - g, 2.0 * t) * 0.5;
+ } else {
+ return 1.0 - bias(1.0 - g, 2.0 - 2.0 * t) * 0.5;
+ }
+ }
+
+ public static double quinticBlend(double t) {
+ return t * t * t * (t * (t * 6 - 15) + 10);
+ }
+
+ public static double sawtooth(double x, double p) {
+ return (2.0 * (x / p - Math.floor(0.5 + x / p))) * 0.5 + 0.5;
+ }
+
+ public static class Vector3d {
+ public double x, y, z;
+
+ public Vector3d() {
+ this(0, 0, 0);
+ }
+
+ public Vector3d(double x, double y, double z) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ }
+ }
+}
diff --git a/src/com/sudoplay/util/Assert.java b/src/com/sudoplay/util/Assert.java
new file mode 100755
index 000000000..8251d1f64
--- /dev/null
+++ b/src/com/sudoplay/util/Assert.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.util;
+
+public class Assert {
+
+ public static void notNull(Object... objects) {
+ for (Object o : objects) {
+ if (o == null) {
+ throw new NullPointerException();
+ }
+ }
+ }
+
+ public static void hasLength(Object[] objects, int length) {
+ if (objects == null && length > 0) {
+ throw new IllegalArgumentException("Expecting " + length
+ + " objects but was null");
+ } else if (objects.length != length) {
+ throw new IllegalArgumentException("Expecting " + length
+ + " objects but was " + objects.length);
+ }
+ }
+
+ public static void isClassNotNull(Class> c, Object... objects) {
+ for (Object o : objects) {
+ if (o == null) {
+ throw new NullPointerException("Expecting " + c.getName()
+ + " but was null");
+ } else if (!c.equals(o.getClass())) {
+ throw new IllegalArgumentException("Expecting " + c.getName()
+ + " but was " + o.getClass().getName());
+ }
+ }
+ }
+
+ public static void isInstanceNotNull(Class> c, Object... objects) {
+ for (Object o : objects) {
+ if (o == null) {
+ throw new NullPointerException("Expecting " + c.getName()
+ + " but was null");
+ } else if (!c.isInstance(o)) {
+ throw new IllegalArgumentException("Expecting " + c.getName()
+ + " but was " + o.getClass().getName());
+ }
+ }
+ }
+
+ public static void isClass(Class> c, Object... objects) {
+ for (Object o : objects) {
+ if (!c.equals(o.getClass())) {
+ throw new IllegalArgumentException("Expecting " + c.getName()
+ + " but was " + o.getClass().getName());
+ }
+ }
+ }
+
+ public static void isInstance(Class> c, Object... objects) {
+ for (Object o : objects) {
+ if (!c.isInstance(o)) {
+ throw new IllegalArgumentException("Expecting " + c.getName()
+ + " but was " + o.getClass().getName());
+ }
+ }
+ }
+
+ public static T isInstance(Class c, Object o) {
+ if (!c.isInstance(o)) {
+ throw new IllegalArgumentException("Expecting " + c.getName()
+ + " but was " + o.getClass().getName());
+ }
+ return c.cast(o);
+ }
+
+}
diff --git a/src/com/sudoplay/util/Checked.java b/src/com/sudoplay/util/Checked.java
new file mode 100755
index 000000000..2395a75db
--- /dev/null
+++ b/src/com/sudoplay/util/Checked.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2013 Jason Taylor.
+ * Released as open-source under the Apache License, Version 2.0.
+ *
+ * ============================================================================
+ * | Joise
+ * ============================================================================
+ *
+ * Copyright (C) 2013 Jason Taylor
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============================================================================
+ * | Accidental Noise Library
+ * | --------------------------------------------------------------------------
+ * | Joise is a derivative work based on Josua Tippetts' C++ library:
+ * | http://accidentalnoise.sourceforge.net/index.html
+ * ============================================================================
+ *
+ * Copyright (C) 2011 Joshua Tippetts
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+package com.sudoplay.util;
+
+public class Checked {
+
+ private Checked() {}
+
+ public static int safeLongToInt(long l) {
+ if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
+ throw new IllegalArgumentException(l
+ + " cannot be cast to int without changing its value.");
+ }
+ return (int) l;
+ }
+
+}
diff --git a/work_files/Tools/b24_col_to_40step_col.py b/work_files/Tools/b24_col_to_40step_col.py
index fd2a78139..a59e31815 100644
--- a/work_files/Tools/b24_col_to_40step_col.py
+++ b/work_files/Tools/b24_col_to_40step_col.py
@@ -32,5 +32,5 @@ def intFromRGB24(r24, g24, b24):
def colFromNum(raw):
return getR40(raw), getG40(raw), getB40(raw)
-print(intFromCol(12, 19, 39))
-print(colFromNum(5009))
+print(intFromRGB24(111, 0, 255))
+print(colFromNum(27239))