/* Double Modulus script for JWildfire
author="Rick Sidwell" category="generator"
info="Creates a double modulus base flame"
*/
import static org.jwildfire.base.mathlib.MathLib.M_PI;
import static org.jwildfire.base.mathlib.MathLib.sin;
import static org.jwildfire.base.mathlib.MathLib.cos;
import static org.jwildfire.base.mathlib.MathLib.sqrt;
import org.jwildfire.create.tina.base.Flame;
import org.jwildfire.create.tina.base.XForm;
import org.jwildfire.create.tina.palette.RGBPalette;
import org.jwildfire.create.tina.script.ScriptRunnerEnvironment;
import org.jwildfire.create.tina.transform.XFormTransformService;
import org.jwildfire.create.tina.base.Layer;
import org.jwildfire.create.tina.variation.Variation;
import org.jwildfire.create.tina.variation.VariationFunc;
import org.jwildfire.create.tina.variation.VariationFuncList;
import org.jwildfire.create.tina.mutagen.RandomGradientMutation;
import org.jwildfire.create.tina.base.EditPlane;
public void run(ScriptRunnerEnvironment pEnv) throws Exception {
double size, angle, sina, sin2a, cosa, cos2a;
// get size and angle from user
do
{
size = Double.parseDouble(javax.swing.JOptionPane.showInputDialog(null, "Enter Size", "Size", 1));
}
while (size <= 0);
angle = Double.parseDouble(javax.swing.JOptionPane.showInputDialog(null, "Enter angle", "Angle", 1));
sina = sin(angle*M_PI/180);
sin2a = sina * sina;
cosa = cos(angle*M_PI/180);
cos2a = cosa * cosa;
// create a new flame
Flame flame=new Flame();
flame.setCamRoll(0);
flame.setCamPitch(0);
flame.setCamYaw(0);
flame.setCamPerspective(0);
flame.setWidth(700);
flame.setHeight(700);
flame.setPixelsPerUnit(350/size);
flame.setCamZoom(1);
flame.setBGTransparency(false);
flame.setBrightness(5*size*size);
flame.setGamma(5);
// create only layer
flame.getLayers().clear();
Layer layer = new Layer();
layer.setWeight(1);
layer.setVisible(true);
flame.getLayers().add(layer);
new RandomGradientMutation().execute(layer);
// create transform 1
{
XForm xForm = new XForm();
layer.getXForms().add(xForm);
xForm.setWeight(cos2a);
xForm.setColor(0);
if (cos2a > sin2a) xForm.setColorSymmetry(sqrt(cos2a - sin2a));
xForm.setDrawMode(org.jwildfire.create.tina.base.DrawMode.HIDDEN);
xForm.setCoeff00(1); // a
xForm.setCoeff10(0); // b
xForm.setCoeff20(0); // e
xForm.setCoeff01(0); // c
xForm.setCoeff11(1); // d
xForm.setCoeff21(0); // f
xForm.setPostCoeff00(cosa);
xForm.setPostCoeff10(-sina);
xForm.setPostCoeff01(sina);
xForm.setPostCoeff11(cosa);
xForm.setPostCoeff20(0);
xForm.setPostCoeff21(0);
// change relative weights
xForm.getModifiedWeights()[0] = 0;
xForm.getModifiedWeights()[1] = 0;
xForm.getModifiedWeights()[2] = 1;
// variation 1
{
VariationFunc varFunc=VariationFuncList.getVariationFuncInstance("modulus", true);
varFunc.setParameter("x", size);
varFunc.setParameter("y", size);
xForm.addVariation(cosa, varFunc);
}
}
// create transform 2
{
XForm xForm = new XForm();
layer.getXForms().add(xForm);
xForm.setWeight(sin2a);
xForm.setColor(1);
if (sin2a > cos2a) xForm.setColorSymmetry(sqrt(sin2a - cos2a));
xForm.setDrawMode(org.jwildfire.create.tina.base.DrawMode.HIDDEN);
xForm.setCoeff00(1); // a
xForm.setCoeff10(0); // b
xForm.setCoeff20(0); // e
xForm.setCoeff01(0); // c
xForm.setCoeff11(1); // d
xForm.setCoeff21(0); // f
xForm.setPostCoeff00(cosa);
xForm.setPostCoeff10(-sina);
xForm.setPostCoeff01(sina);
xForm.setPostCoeff11(cosa);
xForm.setPostCoeff20(size);
xForm.setPostCoeff21(-size);
// change relative weights
xForm.getModifiedWeights()[0] = 0;
xForm.getModifiedWeights()[1] = 0;
xForm.getModifiedWeights()[2] = 1;
// variation 1
{
VariationFunc varFunc=VariationFuncList.getVariationFuncInstance("modulus", true);
varFunc.setParameter("x", size);
varFunc.setParameter("y", size);
xForm.addVariation(sina, varFunc);
}
}
// create transform 3
{
XForm xForm = new XForm();
layer.getXForms().add(xForm);
xForm.setWeight(1);
xForm.setColor(0);
xForm.setColorSymmetry(1);
xForm.setCoeff00(1); // a
xForm.setCoeff10(0); // b
xForm.setCoeff20(0); // e
xForm.setCoeff01(0); // c
xForm.setCoeff11(1); // d
xForm.setCoeff21(0); // f
xForm.setPostCoeff00(1);
xForm.setPostCoeff10(0);
xForm.setPostCoeff01(0);
xForm.setPostCoeff11(1);
xForm.setPostCoeff20(0);
xForm.setPostCoeff21(0);
// change relative weights
xForm.getModifiedWeights()[0] = 1;
xForm.getModifiedWeights()[1] = 1;
xForm.getModifiedWeights()[2] = 0;
// variation 1
{
VariationFunc varFunc=VariationFuncList.getVariationFuncInstance("modulus", true);
varFunc.setParameter("x", size);
varFunc.setParameter("y", size);
xForm.addVariation(1, varFunc);
}
}
// Either update the currently selected flame (to not need to create a new thumbnail
// in the thumbnail ribbon after each run of the script...
Flame selFlame = pEnv.getCurrFlame();
if(selFlame!=null) {
selFlame.assign(flame);
pEnv.refreshUI();
}
// ...or load the flame in the editor and refresh the UI
else {
pEnv.setCurrFlame(flame);
}
}
Comments