use of org.jwildfire.create.tina.variation.VariationFunc in project JWildfire by thargor6.
the class GnarlRandomFlameGenerator method prepareFlame.
@Override
public Flame prepareFlame(RandomFlameGeneratorState pState) {
// Bases loosely on the W2R Batch Script by parrotdolphin.deviantart.com */
Flame flame = new Flame();
Layer layer = flame.getFirstLayer();
flame.setCentreX(0.0);
flame.setCentreY(0.0);
flame.setPixelsPerUnit(200);
layer.getFinalXForms().clear();
layer.getXForms().clear();
// init
double scaleX = Math.random() * 0.04 + 0.04;
if (Math.random() > 0.75) {
scaleX = 0 - scaleX;
}
double scaleY = Math.random() * 0.04 + 0.04;
if (Math.random() > 0.75) {
scaleY = 0 - scaleY;
} else if (Math.random() < 0.25) {
scaleY = scaleX;
}
double freqX, freqY;
if (Math.random() < 0.5) {
freqX = Math.random() * 2.0 + 2.0;
if (Math.random() > 0.5) {
freqY = freqX;
} else {
freqY = Math.random() * 2.0 + 2.0;
}
} else {
freqX = -Math.random() * 2.0 + 2.0;
if (Math.random() > 0.5) {
freqY = freqX;
} else {
freqY = -Math.random() * 2.0 + 16.0;
}
}
double blurAmount = 0.0025 * Math.random();
if (Math.random() < 0.33) {
blurAmount = 0.0 - blurAmount;
}
double wavesWeight = Math.random() * 15 + 135;
double _2ndWeight = 0.5;
double _3rdWeight = 0.5;
double symmetry = 0.7 + Math.random() * 0.3;
int sides = (int) (Math.random() * 8.0 + 3.0);
// 1st XForm
{
XForm xForm = new XForm();
layer.getXForms().add(xForm);
xForm.setWeight(wavesWeight);
VariationFunc w2 = Math.random() > 0.89 ? createWaves2Variation(scaleX, scaleY, freqX, freqY) : createWaves2BVariation(scaleX, scaleY, freqX, freqY);
xForm.addVariation(1 + Math.random() * 0.001, w2);
String[] varLst = { "blur", "cos", "exp", "exponential", "lazysusan", "ngon", "sech", "sinh", "epispiral_wf", "tanh", "twintrian", "epispiral" };
String varName = Math.random() > 0.25 ? varLst[(int) (Math.random() * varLst.length)] : VariationFuncList.getRandomVariationname();
xForm.addVariation(blurAmount, VariationFuncList.getVariationFuncInstance(varName, true));
xForm.setColorSymmetry(symmetry);
xForm.setColor(0.9);
if (Math.random() > 0.5) {
XFormTransformService.scale(xForm, 0.995, true, true);
}
double angle, tx, ty;
switch(sides) {
case 3:
angle = -120;
tx = Math.random() * 8 - 4;
ty = Math.random() * 8 - 4;
break;
case 4:
angle = -90;
tx = Math.random() * 8 - 4;
ty = Math.random() * 8 - 4;
break;
case 5:
angle = -72;
tx = Math.random() * 7 - 3.5;
ty = Math.random() * 7 - 3.5;
break;
case 6:
angle = -60;
tx = Math.random() * 7 - 3.5;
ty = Math.random() * 7 - 3.5;
break;
case 7:
angle = -51.42857;
tx = Math.random() * 6 - 3;
ty = Math.random() * 6 - 3;
break;
case 8:
angle = -135;
tx = Math.random() * 6 - 3;
ty = Math.random() * 6 - 3;
break;
case 9:
angle = -40;
tx = Math.random() * 5 - 2.5;
ty = Math.random() * 5 - 2.5;
break;
case 10:
angle = -36;
tx = Math.random() * 4 - 2;
ty = Math.random() * 4 - 2;
break;
default:
throw new IllegalStateException();
}
XFormTransformService.rotate(xForm, angle);
XFormTransformService.localTranslate(xForm, tx * 1.5, ty * 1.5);
}
// 2nd XForm
{
XForm xForm = new XForm();
layer.getXForms().add(xForm);
xForm.setWeight(_2ndWeight);
int f = Tools.randomInt(3);
switch(f) {
case 0:
xForm.addVariation(Math.random() * 0.37 + 0.1, VariationFuncList.getVariationFuncInstance("radial_blur", true));
break;
case 1:
xForm.addVariation(Math.random() * 0.37 + 0.3, VariationFuncList.getVariationFuncInstance("bubble", true));
xForm.addVariation(Math.random() * 0.37 + 0.1, VariationFuncList.getVariationFuncInstance("radial_blur", true));
break;
case 2:
xForm.addVariation(Math.random() * 0.1, VariationFuncList.getVariationFuncInstance("radial_blur", true));
JuliaNFunc juliaN = (JuliaNFunc) VariationFuncList.getVariationFuncInstance("julian", true);
juliaN.setParameter("power", 50 - Math.random() * 100);
juliaN.setParameter("dist", Math.random() * 10 - 2);
xForm.addVariation(Math.random() * 0.06 + 0.1, juliaN);
break;
default:
// nothing to do
break;
}
xForm.setColorSymmetry(-1);
}
// 3rd XForm
if (Math.random() > 0.75) {
XForm xForm = new XForm();
layer.getXForms().add(xForm);
xForm.setWeight(_3rdWeight);
xForm.addVariation(1.0, VariationFuncList.getVariationFuncInstance("linear3D", true));
XFormTransformService.rotate(xForm, 180 - Math.random() * 360.0);
XFormTransformService.localTranslate(xForm, 1.0 - 2.0 * Math.random(), 1.0 - 2.0 * Math.random());
xForm.setColorSymmetry(-1);
}
return flame;
}
use of org.jwildfire.create.tina.variation.VariationFunc in project JWildfire by thargor6.
the class GnarlRandomFlameGenerator method createWaves2Variation.
public static VariationFunc createWaves2Variation(double scaleX, double scaleY, double freqX, double freqY) {
VariationFunc w2;
w2 = VariationFuncList.getVariationFuncInstance("waves2", true);
w2.setParameter("freqx", freqX);
w2.setParameter("scalex", scaleX);
w2.setParameter("freqy", freqY);
w2.setParameter("scaley", scaleY);
return w2;
}
use of org.jwildfire.create.tina.variation.VariationFunc in project JWildfire by thargor6.
the class JuliansRandomFlameGenerator method prepareFlame.
@Override
public Flame prepareFlame(RandomFlameGeneratorState pState) {
Flame flame = new Flame();
flame.setCentreX(0.0);
flame.setCentreY(0.0);
flame.setPixelsPerUnit(200);
flame.setCamZoom(1.0);
Layer layer = flame.getFirstLayer();
layer.getFinalXForms().clear();
layer.getXForms().clear();
String primary = Math.random() < 0.666 ? "julian" : "juliascope";
// 1st xForm
{
XForm xForm = new XForm();
layer.getXForms().add(xForm);
xForm.setWeight(0.00001 + Math.random() * 20.0);
xForm.setColor(Math.random());
if (Math.random() < 0.5) {
xForm.addVariation(-1.0 + Math.random() * 2.0, VariationFuncList.getVariationFuncInstance(VariationFuncList.getRandomVariationname(), true));
}
VariationFunc varFunc = VariationFuncList.getVariationFuncInstance(primary, true);
varFunc.setParameter("power", randInRange(1, 7));
varFunc.setParameter("dist", -2.0 + 4.0 * Math.random());
xForm.addVariation(-2.0 + Math.random() * 4.0, varFunc);
randomAffine(xForm);
}
// 2nd xForm
{
XForm xForm = new XForm();
layer.getXForms().add(xForm);
xForm.setWeight(0.00001 + Math.random() * 6.0);
xForm.setColor(Math.random());
VariationFunc varFunc = VariationFuncList.getVariationFuncInstance(primary, true);
varFunc.setParameter("power", randInRange(1, 7));
varFunc.setParameter("dist", -2.0 + 4.0 * Math.random());
xForm.addVariation(-2.0 + Math.random() * 4.0, varFunc);
if (Math.random() < 0.8) {
xForm.addVariation(-1.0 + Math.random() * 2.0, VariationFuncList.getVariationFuncInstance("linear", true));
xForm.addVariation(-1.0 + Math.random() * 2.0, VariationFuncList.getVariationFuncInstance(VariationFuncList.getRandomVariationname(), true));
}
xForm.getModifiedWeights()[1] = Math.random() < 0.5 ? 0.0 : Math.random();
XFormTransformService.scale(xForm, 0.5 + Math.random() * 0.5, Math.random() < 0.5, Math.random() < 0.5);
randomAffine(xForm);
}
// 3rd xForm
{
XForm xForm = new XForm();
layer.getXForms().add(xForm);
xForm.setWeight(0.00001 + Math.random() * 2.0);
xForm.setColor(Math.random());
VariationFunc varFunc = VariationFuncList.getVariationFuncInstance(primary, true);
varFunc.setParameter("power", randInRange(1, 5));
varFunc.setParameter("dist", -2.0 + 4.0 * Math.random());
xForm.addVariation(-2.0 + Math.random() * 4.0, varFunc);
randomAffine(xForm);
randomPostAffine(xForm);
}
return flame;
}
use of org.jwildfire.create.tina.variation.VariationFunc in project JWildfire by thargor6.
the class RandomParamMutation method setRandomFlameProperty.
public void setRandomFlameProperty(Layer pLayer, double pAmount) {
List<VariationFunc> variations = new ArrayList<VariationFunc>();
for (XForm xForm : pLayer.getXForms()) {
addVariations(variations, xForm);
}
for (XForm xForm : pLayer.getFinalXForms()) {
addVariations(variations, xForm);
}
filterVariations(variations);
if (variations.size() > 0) {
int idx = (int) (Math.random() * variations.size());
VariationFunc var = variations.get(idx);
int pIdx = (int) (Math.random() * var.getParameterNames().length);
Object oldVal = var.getParameterValues()[pIdx];
if (oldVal instanceof Integer) {
int o = (Integer) oldVal;
int da = Tools.FTOI(pAmount);
if (da < 1) {
da = 1;
}
if (o >= 0) {
o += da;
} else {
o -= da;
}
var.setParameter(var.getParameterNames()[pIdx], o);
} else if (oldVal instanceof Double) {
double o = (Double) oldVal;
if (o < EPSILON || Math.random() < 0.3) {
if (o >= 0) {
o += 0.1 * pAmount;
} else {
o -= 0.1 * pAmount;
}
} else {
if (o >= 0) {
o += o / 100.0 * pAmount;
} else {
o -= o / 100.0 * pAmount;
}
}
var.setParameter(var.getParameterNames()[pIdx], o);
}
}
}
use of org.jwildfire.create.tina.variation.VariationFunc in project JWildfire by thargor6.
the class AnimationService method _disableMotionCurves.
private static void _disableMotionCurves(Object pObject) throws IllegalAccessException {
Class<?> cls = pObject.getClass();
for (Field field : cls.getDeclaredFields()) {
field.setAccessible(true);
if (field.getType() == MotionCurve.class && field.getName().endsWith(Tools.CURVE_POSTFIX)) {
MotionCurve curve = (MotionCurve) field.get(pObject);
if (curve.isEnabled()) {
curve.setEnabled(false);
}
} else if (field.getType().isAssignableFrom(ArrayList.class)) {
List<?> childs = (List<?>) field.get(pObject);
for (Object child : childs) {
_disableMotionCurves(child);
}
} else if (field.getType().isAssignableFrom(RGBPalette.class)) {
RGBPalette gradient = (RGBPalette) field.get(pObject);
_disableMotionCurves(gradient);
}
}
if (pObject instanceof Variation) {
Variation var = (Variation) pObject;
VariationFunc func = var.getFunc();
for (String name : func.getParameterNames()) {
MotionCurve curve = var.getMotionCurve(name);
if (curve != null && curve.isEnabled()) {
curve.setEnabled(false);
}
}
}
}
Aggregations