LibGDX, here I am.

This commit is contained in:
minjaesong
2017-06-22 02:31:07 +09:00
parent 1ecbc57f83
commit ad481853bb
356 changed files with 3125 additions and 21138 deletions

View File

@@ -1,178 +0,0 @@
/*
* 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.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import com.sudoplay.joise.module.Module;
import com.sudoplay.joise.module.SeedableModule;
import com.sudoplay.util.Assert;
public class Joise {
private Module module;
private ModuleMap moduleMap;
private HashMap<String, ArrayList<SeedableModule>> seedMap = new HashMap<String, ArrayList<SeedableModule>>();
/**
* Creates a new instance of Joise with the supplied module chain.
* <p>
* 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.
* <p>
* 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}.
* <p>
* 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.
* <p>
* 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<Entry<String, ModulePropertyMap>> it = map.mapIterator();
Module module = null;
while (it.hasNext()) {
Entry<String, ModulePropertyMap> 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<SeedableModule> list = seedMap.get(seedName);
if (list == null) {
list = new ArrayList<SeedableModule>();
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<SeedableModule> 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);
}
}

View File

@@ -1,66 +0,0 @@
/*
* 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);
}
}

View File

@@ -1,107 +0,0 @@
/*
* 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<String, Module> {
@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<Entry<String, Module>> iterator() {
return super.entrySet().iterator();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("[");
Iterator<Entry<String, Module>> it = iterator();
while (it.hasNext()) {
Entry<String, Module> e = it.next();
sb.append("[");
sb.append(e.getKey());
sb.append("|");
sb.append(e.getValue());
sb.append("]");
}
sb.append("]");
return sb.toString();
}
}

View File

@@ -1,103 +0,0 @@
/*
* 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<String, ModulePropertyMap> {
@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<Entry<String, ModulePropertyMap>> mapIterator() {
return super.entrySet().iterator();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("[");
Iterator<Entry<String, ModulePropertyMap>> it = mapIterator();
while (it.hasNext()) {
Entry<String, ModulePropertyMap> e = it.next();
sb.append("[");
sb.append(e.getKey());
sb.append("|");
sb.append(e.getValue());
sb.append("]");
}
sb.append("]");
return sb.toString();
}
}

View File

@@ -1,154 +0,0 @@
/*
* 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<String, Object> {
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<Entry<String, Object>> iterator() {
return super.entrySet().iterator();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Iterator<Entry<String, Object>> it = iterator();
while (it.hasNext()) {
Entry<String, Object> e = it.next();
sb.append("[");
sb.append(e.getKey());
sb.append("|");
sb.append(e.getValue());
sb.append("]");
}
return sb.toString();
}
}

Binary file not shown.

View File

@@ -1,81 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,31 +0,0 @@
package com.sudoplay.joise.generator
/**
* Created by SKYHi14 on 2017-02-20.
*/
class Xorshift128plus : BasePRNG() {
private var s0: Long = 0
private var s1: Long = 0
init {
setSeed(10000L)
}
override fun get(): Int {
var x = s0
val y = s1
s0 = y
x = x xor (x shl 23)
s1 = x xor y xor (x ushr 17) xor (y ushr 26)
return (s1 + y).toInt()
}
override fun setSeed(seed: Long) {
if (seed == 0L)
throw IllegalArgumentException("Invalid seed: cannot be zero")
s0 = (6364136223846793005L * seed + 1442695040888963407L)
s1 = (6364136223846793005L * s0 + 1442695040888963407L)
}
}

View File

@@ -1,96 +0,0 @@
/*
* 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];
}
}

View File

@@ -1,72 +0,0 @@
/*
* 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);
}
}

View File

@@ -1,100 +0,0 @@
/*
* 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];
}
}

View File

@@ -1,72 +0,0 @@
/*
* 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);
}
}

View File

@@ -1,753 +0,0 @@
/*
* 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();
}
}
}

View File

@@ -1,62 +0,0 @@
/*
* 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
}
};
}

View File

@@ -1,62 +0,0 @@
/*
* 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
}
};
}

View File

@@ -1,53 +0,0 @@
/*
* 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
}

View File

@@ -1,60 +0,0 @@
/*
* 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();
}

View File

@@ -1,62 +0,0 @@
/*
* 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
}
};
}

View File

@@ -1,371 +0,0 @@
/*
* 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 <T extends Enum<T>> void readEnum(String name, String methodName,
Class<T> 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));
}
}

View File

@@ -1,97 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,305 +0,0 @@
/*
* 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.Xorshift128plus;
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;
Xorshift128plus lcg = new Xorshift128plus();
// 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;
}
}

View File

@@ -1,334 +0,0 @@
/*
* 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.Xorshift128plus;
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);
Xorshift128plus lcg = new Xorshift128plus();
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;
}
}

View File

@@ -1,125 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,144 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,163 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,140 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,176 +0,0 @@
/*
* 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();
}
}

View File

@@ -1,161 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,127 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,489 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,97 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,97 +0,0 @@
/*
* 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;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,206 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,120 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,204 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,97 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,177 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,137 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,111 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,227 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,113 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,171 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,122 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,245 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,97 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,206 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,173 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,169 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,176 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,114 +0,0 @@
/*
* 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);
}
}
}

View File

@@ -1,94 +0,0 @@
/*
* 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);
}
}

View File

@@ -1,79 +0,0 @@
/*
* 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);
}
}

View File

@@ -1,83 +0,0 @@
/*
* 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);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,101 +0,0 @@
/*
* 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;
}
}
}

View File

@@ -1,121 +0,0 @@
/*
* 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> T isInstance(Class<T> c, Object o) {
if (!c.isInstance(o)) {
throw new IllegalArgumentException("Expecting " + c.getName()
+ " but was " + o.getClass().getName());
}
return c.cast(o);
}
}

View File

@@ -1,63 +0,0 @@
/*
* 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;
}
}