Advertisement
rsidwell

Double Modulus RS

Jan 25th, 2018
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.46 KB | None | 0 0
  1. /* Double Modulus script for JWildfire  
  2. author="Rick Sidwell" category="generator"
  3. info="Creates a double modulus base flame"
  4. */
  5. import static org.jwildfire.base.mathlib.MathLib.M_PI;
  6. import static org.jwildfire.base.mathlib.MathLib.sin;
  7. import static org.jwildfire.base.mathlib.MathLib.cos;
  8. import static org.jwildfire.base.mathlib.MathLib.sqrt;
  9. import org.jwildfire.create.tina.base.Flame;
  10. import org.jwildfire.create.tina.base.XForm;
  11. import org.jwildfire.create.tina.palette.RGBPalette;
  12. import org.jwildfire.create.tina.script.ScriptRunnerEnvironment;
  13. import org.jwildfire.create.tina.transform.XFormTransformService;
  14. import org.jwildfire.create.tina.base.Layer;
  15. import org.jwildfire.create.tina.variation.Variation;
  16. import org.jwildfire.create.tina.variation.VariationFunc;
  17. import org.jwildfire.create.tina.variation.VariationFuncList;
  18. import org.jwildfire.create.tina.mutagen.RandomGradientMutation;
  19. import org.jwildfire.create.tina.base.EditPlane;
  20.  
  21. public void run(ScriptRunnerEnvironment pEnv) throws Exception {
  22.   double size, angle, sina, sin2a, cosa, cos2a;
  23.  
  24.   // get size and angle from user
  25.   do
  26.     {
  27.     size = Double.parseDouble(javax.swing.JOptionPane.showInputDialog(null, "Enter Size", "Size", 1));
  28.     }
  29.   while (size <= 0);
  30.   angle = Double.parseDouble(javax.swing.JOptionPane.showInputDialog(null, "Enter angle", "Angle", 1));
  31.   sina = sin(angle*M_PI/180);
  32.   sin2a = sina * sina;
  33.   cosa = cos(angle*M_PI/180);
  34.   cos2a = cosa * cosa;
  35.  
  36.   // create a new flame
  37.   Flame flame=new Flame();
  38.   flame.setCamRoll(0);
  39.   flame.setCamPitch(0);
  40.   flame.setCamYaw(0);
  41.   flame.setCamPerspective(0);
  42.   flame.setWidth(700);
  43.   flame.setHeight(700);
  44.   flame.setPixelsPerUnit(350/size);
  45.   flame.setCamZoom(1);
  46.   flame.setBGTransparency(false);
  47.   flame.setBrightness(5*size*size);
  48.   flame.setGamma(5);
  49.  
  50.   // create only layer
  51.   flame.getLayers().clear();
  52.   Layer layer = new Layer();
  53.   layer.setWeight(1);
  54.   layer.setVisible(true);
  55.   flame.getLayers().add(layer);
  56.   new RandomGradientMutation().execute(layer);
  57.      
  58.   // create transform 1
  59.   {
  60.     XForm xForm = new XForm();
  61.     layer.getXForms().add(xForm);
  62.     xForm.setWeight(cos2a);
  63.     xForm.setColor(0);
  64.     if (cos2a > sin2a) xForm.setColorSymmetry(sqrt(cos2a - sin2a));
  65.     xForm.setDrawMode(org.jwildfire.create.tina.base.DrawMode.HIDDEN);
  66.  
  67.     xForm.setCoeff00(1); // a
  68.     xForm.setCoeff10(0); // b
  69.     xForm.setCoeff20(0); // e
  70.     xForm.setCoeff01(0); // c
  71.     xForm.setCoeff11(1); // d
  72.     xForm.setCoeff21(0); // f
  73.  
  74.     xForm.setPostCoeff00(cosa);
  75.     xForm.setPostCoeff10(-sina);
  76.     xForm.setPostCoeff01(sina);
  77.     xForm.setPostCoeff11(cosa);
  78.     xForm.setPostCoeff20(0);
  79.     xForm.setPostCoeff21(0);
  80.  
  81.     // change relative weights
  82.     xForm.getModifiedWeights()[0] = 0;
  83.     xForm.getModifiedWeights()[1] = 0;
  84.     xForm.getModifiedWeights()[2] = 1;
  85.  
  86.     // variation 1
  87.     {
  88.       VariationFunc varFunc=VariationFuncList.getVariationFuncInstance("modulus", true);
  89.       varFunc.setParameter("x", size);
  90.       varFunc.setParameter("y", size);
  91.       xForm.addVariation(cosa, varFunc);
  92.     }
  93.   }
  94.  
  95.   // create transform 2
  96.   {
  97.     XForm xForm = new XForm();
  98.     layer.getXForms().add(xForm);
  99.     xForm.setWeight(sin2a);
  100.     xForm.setColor(1);
  101.     if (sin2a > cos2a) xForm.setColorSymmetry(sqrt(sin2a - cos2a));
  102.     xForm.setDrawMode(org.jwildfire.create.tina.base.DrawMode.HIDDEN);
  103.  
  104.     xForm.setCoeff00(1); // a
  105.     xForm.setCoeff10(0); // b
  106.     xForm.setCoeff20(0); // e
  107.     xForm.setCoeff01(0); // c
  108.     xForm.setCoeff11(1); // d
  109.     xForm.setCoeff21(0); // f
  110.  
  111.     xForm.setPostCoeff00(cosa);
  112.     xForm.setPostCoeff10(-sina);
  113.     xForm.setPostCoeff01(sina);
  114.     xForm.setPostCoeff11(cosa);
  115.     xForm.setPostCoeff20(size);
  116.     xForm.setPostCoeff21(-size);
  117.  
  118.     // change relative weights
  119.     xForm.getModifiedWeights()[0] = 0;
  120.     xForm.getModifiedWeights()[1] = 0;
  121.     xForm.getModifiedWeights()[2] = 1;
  122.  
  123.     // variation 1
  124.     {
  125.       VariationFunc varFunc=VariationFuncList.getVariationFuncInstance("modulus", true);
  126.       varFunc.setParameter("x", size);
  127.       varFunc.setParameter("y", size);
  128.       xForm.addVariation(sina, varFunc);
  129.     }
  130.   }
  131.  
  132.   // create transform 3
  133.   {
  134.     XForm xForm = new XForm();
  135.     layer.getXForms().add(xForm);
  136.     xForm.setWeight(1);
  137.     xForm.setColor(0);
  138.     xForm.setColorSymmetry(1);
  139.  
  140.     xForm.setCoeff00(1); // a
  141.     xForm.setCoeff10(0); // b
  142.     xForm.setCoeff20(0); // e
  143.     xForm.setCoeff01(0); // c
  144.     xForm.setCoeff11(1); // d
  145.     xForm.setCoeff21(0); // f
  146.  
  147.     xForm.setPostCoeff00(1);
  148.     xForm.setPostCoeff10(0);
  149.     xForm.setPostCoeff01(0);
  150.     xForm.setPostCoeff11(1);
  151.     xForm.setPostCoeff20(0);
  152.     xForm.setPostCoeff21(0);
  153.  
  154.     // change relative weights
  155.     xForm.getModifiedWeights()[0] = 1;
  156.     xForm.getModifiedWeights()[1] = 1;
  157.     xForm.getModifiedWeights()[2] = 0;
  158.  
  159.     // variation 1
  160.     {
  161.       VariationFunc varFunc=VariationFuncList.getVariationFuncInstance("modulus", true);
  162.       varFunc.setParameter("x", size);
  163.       varFunc.setParameter("y", size);
  164.       xForm.addVariation(1, varFunc);
  165.     }
  166.   }
  167.  
  168.   // Either update the currently selected flame (to not need to create a new thumbnail
  169.   // in the thumbnail ribbon after each run of the script...
  170.   Flame selFlame = pEnv.getCurrFlame();
  171.   if(selFlame!=null) {
  172.     selFlame.assign(flame);
  173.     pEnv.refreshUI();
  174.   }
  175.   // ...or load the flame in the editor and refresh the UI
  176.   else {
  177.     pEnv.setCurrFlame(flame);
  178.   }
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement