How to Create Scripts Part 5

Fixed Gradients

Because scripts are created with a random gradient instruction, each time you run them, it will randomly change colours. But what if you have a favourite gradient set you want to use? Well, read on and we’ll get to how to make sure the scripts only run the gradient set you want.

Time Needed : 30 minutes

Fixed gradients, how to set them up inside a script.

  1. Grab your gradient

    You’ll want to first make sure you have access to your gradient file. If you know where this is, great. You’ll need to copy the gradient file to the folder that your script is in. It will be a UGR file or a MAP file. So go ahead and copy it into the folder now. If you can just see it in JWildfire and want to save it you can go to the gradient area and click save. Save it to your script folderStep 1 Save Gradient

  2. Saving UGR files

    More often than not, you’ll want to save the UGR file (which is a collection of gradients, rather than a MAP file which is a single gradient only. To do this you’ll need to know where your gradients are saved. Go to the settings area of JWildfire to find the path to them. Step 2 Find Gradient Path

  3. Look for your gradient in the folders

    Your gradient will be a UGR file typically, but if it’s a single map file that’s fine also. So copy it to your script folderStep 3 Find Gradient FIle

  4. Getting your script to read your gradient file only.

    Look at the code for your script, at the top you’ll see a bunch of lines that start “import.org” etc You’ll need to add the following lines underneath all the lines that start import.org so copy these three lines and paste them underneath the last line of the import.org section in your script, as seen in the picture.import java.util.List;import org.jwildfire.create.tina.palette.RGBPalette;import org.jwildfire.create.tina.io.UniversalPaletteReader;Step 4 insert org commands

  5. Adding the gradient selector

    Once you’ve pasted the 3 lines above, you need to scroll down your script code. You’re looking for the line that creates the random gradient. See example underneath.// create a random gradient new RandomGradientMutation().execute(layer);Now, this has to be replaced with the code that’s found at the bottom of these steps. So, copy all the code underneath these steps (underneath the title “Code to add for fixed gradient”) click the copy button, then switch back to your script. Highlight the random gradient lines, and paste the new code over the top of it.Step 6 replacement code

  6. Change the line of code to point to your gradient.

    String custom_code_file = script_dir + file_separator + “carr.ugr”;When you’ve pasted the code from the bottom of this page over the random gradient instruction, look for the above line in your new code. What you’re wanting to do is change the carr.ugr filename, to the filename of your gradient. So it might look like… This tells the new code to look for your gradient file and not the carr.ugr. In the screenshot above I’ve changed it to leafy.ugr which is a leaf coloured gradient file I copied into my script folder.String custom_code_file = script_dir + file_separator + “yourfilename.ugr”;

  7. Save the script

    So, once you’ve done all of this.. make sure to save your script, I usually save it as scriptname-copy.jwfscript so that I don’t overwrite the original script. Then go to the script area of JWildfire, hit the scan button and run your new script. As long as the gradient file is in the same folder as your script, and you changed the name. You’ll now see your script running, but only using that gradient.

Tools
  • Notepad ++
Materials
  • JWildfire

Code to add for fixed gradient

// This CODE Will Read a Gradients File (*.map , *.ugr , *.xml) just from the directory where the script is installed
// Put your *.ugr file in the same directory as your script is located,
// you can distribute the *.ugr file in your zip file with the script file *.jwfscript

  UniversalPaletteReader gradientReader=new UniversalPaletteReader();
  String script_path = this.getScriptPath();
  String file_separator = System.getProperty("file.separator");
  String script_dir = script_path.substring(0, script_path.lastIndexOf(file_separator));
  String custom_code_file = script_dir + file_separator + "carr.ugr";
// Provide the path to your gradient here --- ANY GRADIENT FILE of *.map , *.ugr , *.xml may be used
   List gradients= gradientReader.readPalettes(custom_code_file );   // <------ For Universality, create folder C:/Gradients, and put the gradient file in it
// Choose a random gradient from the gradient file
   double gradSize = gradients.size();
   RGBPalette palete=(RGBPalette)gradients.get((int)(Math.random()* gradSize));
   flame.setPalette(palete);  

Related Posts

You may be interested in ...

1 thought on “How to Create Scripts Part 5”

  1. Hi,thank you for the tutorial,It’s really helpful
    I seem to have a problem here
    After I pasted the code ,it says:
    System error
    Line 63, Column 26: Cannot determine simple type name “UniversalPaletteReader”

    Here is my script
    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.base.DrawMode;
    import org.jwildfire.create.tina.base.ColorType;
    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.transform.XFormTransformService;
    import org.jwildfire.create.tina.base.EditPlane;

    //Add a random number
    public int range(int min, int max)
    {
    return min +(int)(Math.random()*(max-min + 1));
    }
    public double range(double min,double max)
    {
    return min +Math.random()*(max-min);

    }

    public void run(ScriptRunnerEnvironment pEnv) throws Exception {
    // create a new flame
    Flame flame=new Flame();
    flame.getLayers().clear(); // get rid of the default layer because we create all layers by ourselves
    // set the flame main attributes
    flame.setCamRoll(0);
    flame.setCentreX(0.00140505);
    flame.setCentreY(0.00061178);
    flame.setCamPitch(0);
    flame.setCamYaw(0);
    flame.setCamBank(0);
    flame.setCamPerspective(0);
    flame.setWidth(848);
    flame.setHeight(636);
    flame.setPixelsPerUnit(403.277);
    flame.setCamZoom(1);
    flame.setBGTransparency(false);
    // Uncomment setBrightness or setGamma if essential for the flame
    // flame.setBrightness(3.52173913043478);
    // flame.setGamma(2.8);
    flame.setPreserveZ(false);
    // create layer 1
    {
    Layer layer = new Layer();
    flame.getLayers().add(layer);
    layer.setWeight(1);
    layer.setDensity(1);
    layer.setVisible(true);
    // create a random gradient
    new RandomGradientMutation().execute(layer);
    // This CODE Will Read a Gradients File (*.map , *.ugr , *.xml) just from the directory where the script is installed
    // Put your *.ugr file in the same directory as your script is located,
    // you can distribute the *.ugr file in your zip file with the script file *.jwfscript

    UniversalPaletteReader gradientReader=new UniversalPaletteReader();
    String script_path = this.getScriptPath();
    String file_separator = System.getProperty(“file.separator”);
    String script_dir = script_path.substring(0, script_path.lastIndexOf(file_separator));
    String custom_code_file = script_dir + file_separator + “carr.ugr”;
    // Provide the path to your gradient here — ANY GRADIENT FILE of *.map , *.ugr , *.xml may be used
    List gradients= gradientReader.readPalettes(custom_code_file ); // <—— For Universality, create folder C:/Gradients, and put the gradient file in it
    // Choose a random gradient from the gradient file
    double gradSize = gradients.size();
    RGBPalette palete=(RGBPalette)gradients.get((int)(Math.random()* gradSize));
    flame.setPalette(palete);
    // create transform 1
    {
    XForm xForm = new XForm();
    layer.getXForms().add(xForm);
    xForm.setWeight(0.5);
    xForm.setColor(1);
    xForm.setColorSymmetry(0.984);
    xForm.setDrawMode(DrawMode.NORMAL);
    xForm.setMaterial(0);
    xForm.setMaterialSpeed(0);

    xForm.setCoeff00(0.304401); // a
    xForm.setCoeff10(-0.871167); // b
    xForm.setCoeff20(0); // e
    xForm.setCoeff01(-0.871167); // c
    xForm.setCoeff11(-0.304401); // 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] = 10;

    // variation 1
    {
    VariationFunc varFunc=VariationFuncList.getVariationFuncInstance("splits", true);
    varFunc.setParameter("x", -0.618);
    varFunc.setParameter("y", -0.618);
    varFunc.setParameter("lshear", 0);
    varFunc.setParameter("rshear", 0);
    varFunc.setParameter("ushear", 0);
    varFunc.setParameter("dshear", 0);
    xForm.addVariation(1, varFunc);
    }
    // set default edit plane
    flame.setEditPlane(EditPlane.XY);
    // random affine transforms (uncomment to play around)
    // XFormTransformService.scale(xForm, 1.25-Math.random()*0.5, true, true, false);
    // XFormTransformService.rotate(xForm, 360.0*Math.random(), false);
    // XFormTransformService.localTranslate(xForm, 1.0-2.0*Math.random(), 1.0-2.0*Math.random(), false);
    // random affine post transforms (uncomment to play around)
    // XFormTransformService.scale(xForm, 1.25-Math.random()*0.5, true, true, true);
    // XFormTransformService.rotate(xForm, 360.0*Math.random(), true);
    // XFormTransformService.localTranslate(xForm, 1.0-2.0*Math.random(), 1.0-2.0*Math.random(), true);
    }
    // create transform 2
    {
    XForm xForm = new XForm();
    layer.getXForms().add(xForm);
    xForm.setWeight(0.5);
    xForm.setColor(0.454);
    xForm.setColorSymmetry(0.19);
    xForm.setDrawMode(DrawMode.OPAQUE);
    xForm.setOpacity(0.47);
    xForm.setMaterial(0);
    xForm.setMaterialSpeed(0);

    xForm.setCoeff00(-0.104173); // a
    xForm.setCoeff10(-0.294474); // b
    xForm.setCoeff20(0); // e
    xForm.setCoeff01(-0.294474); // c
    xForm.setCoeff11(0.104173); // d
    xForm.setCoeff21(0); // f

    xForm.setPostCoeff00(0.32986);
    xForm.setPostCoeff10(-0.94403);
    xForm.setPostCoeff01(-0.94403);
    xForm.setPostCoeff11(-0.32986);
    xForm.setPostCoeff20(0);
    xForm.setPostCoeff21(0);

    // change relative weights
    xForm.getModifiedWeights()[0] = 5;
    xForm.getModifiedWeights()[1] = 0.618;

    // variation 1
    xForm.addVariation(0.195, VariationFuncList.getVariationFuncInstance("sinusoidal", true));
    // variation 2
    xForm.addVariation(1.618, VariationFuncList.getVariationFuncInstance("pre_blur", true));
    // set default edit plane
    flame.setEditPlane(EditPlane.XY);
    // random affine transforms (uncomment to play around)
    // XFormTransformService.scale(xForm, 1.25-Math.random()*0.5, true, true, false);
    // XFormTransformService.rotate(xForm, 360.0*Math.random(), false);
    // XFormTransformService.localTranslate(xForm, 1.0-2.0*Math.random(), 1.0-2.0*Math.random(), false);
    // random affine post transforms (uncomment to play around)
    // XFormTransformService.scale(xForm, 1.25-Math.random()*0.5, true, true, true);
    // XFormTransformService.rotate(xForm, 360.0*Math.random(), true);
    // XFormTransformService.localTranslate(xForm, 1.0-2.0*Math.random(), 1.0-2.0*Math.random(), true);
    }
    }
    // 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);
    }
    }

Leave a Comment