Showing posts with label scripts. Show all posts
Showing posts with label scripts. Show all posts

Sunday, 15 March 2009

Tip: ad hoc scripting #2 - rapidly change variables for a group of transforms

I have already published a set of utility scripts for working on groups of transforms (link). It's easy enough to write scripts that generalise when it comes to working with variations (one simply needs to maintain a list of currently installed plugins in alphabetical order): the old method of referencing variations by number is most useful in this context. But it doesn't allow for easy manipulation of variables. Rather than write an enormous script that covers all, I've developed a (wait for it) spreadsheet that picks up all the variables via a lookup table. But it's not necessary - just a code snippet repository or, better, a clipboard utlility (e.g. ArsClip, my review) will do the trick. As an example, we'll take the lazysusan variation - all that's required is:

Transform.lazysusan_spin := 3.14159;
Transform.lazysusan_space := 0;
Transform.lazysusan_twist := 0;
Transform.lazysusan_x := 0;
Transform.lazysusan_y := 0;

These are the default values. Also, a loop wrapper:

for i := a to b do
begin
SetActiveTransform(i);
...variables...
end

where a and b are the first and last transforms of the group (zero-based counting, that is the first transform of the flame is in fact transform #0).

Running Apophysis with the script editor window open (Ctrl-D), just click the New tool and paste in the code, amend the values as desired and click the Run tool - one click to perform what would take perhaps 30 seconds to accomplish in the Transform Editor.

Friday, 13 March 2009

Tip: ad hoc scripting #1 - batch rendering multiple .flame files

Following on from the previous tip, this becomes a very simple but powerful tool to enhance lengthy unattended rendering, ideal for setting up before a weekend away. With reference to the previous tip, [script code] represents the chosen block of script for rendering the contents of a single .flame file. The choice of method may be varied for each .flame file. The following code will render the content of three .flame files in a single run:

SetFlameFile('full path\filename1.flame');
[script code]
SetFlameFile('full path\filename2.flame');
[script code]
SetFlameFile('full path\filename3.flame');
[script code]

The snippet may be stored in a text file and then amended and copied to the clipboard (Ctrl-C). In Apophysis, open the script editor (Ctrl-D), click New and paste (Ctrl-V), then click Run. This way, you don't end up with a load of stored scripts that won't be used again.

Saturday, 7 March 2009

Tip: batch rendering

Historically, this was always accomplished using a script, whether with the internal renderer or flam3. We now have a bulit-in batch rendering command, plus I have my own custom (script) method. Which method to use depends very much on one's preferred workflow. Essentially, we can divide this into two groups:

1. All renders share the basic rendering parameters.
2. Each render has individual requirements.

Case #1 is simple: its simplest solution is to use the bulit-in method Flame, Render All Flames (Ctrl-Alt-R), offering the usual dialogue for setting parameters. Scripted, the equivalent is:

Renderer.Width := ##;
Renderer.Height := ##;
for i := 0 to FileCount - 1 do
begin
LoadFlame(i);
Flame.SampleDensity := ##;
Flame.Oversample := ##;
Flame.FilterRadius := ##;
Renderer.Filename :='path' + Flame.Name + '.ext';
SetRenderBounds;
Render;
end;
UpdateFlame := False;

where ##, path and ext should be specified as desired.

To render the contents of a .flame file other than the current one, simply precede the code with:

SetFlameFile('full path\filename.flame');

Case #2 requires a little more work, but provides more flexibility. Each parameter set would require saving with the desired dimensions, set on the Image Size tab of the Adjust dialogue (make sure to click Apply). The script code would then read:

for i := 0 to FileCount - 1 do
begin
LoadFlame(i);
Renderer.Width := Flame.Width;
Renderer.Height := Flame.Height;
Flame.SampleDensity := ##;
Flame.Oversample := ##;
Flame.FilterRadius := ##;
Renderer.Filename :='path' + Flame.Name + '.ext';
SetRenderBounds;
Render;
end;
UpdateFlame := False;

But there is no easy way to set individual values for quality, oversample and filter radius, other than editing the .flame file manually, either with a text or XML editor. To this end, I developed a spreadsheet in which values for each parameter set are entered into adjacent cells, then a button pressed that copies the code to form a consecutive set of instructions, like this:

LoadFlame(0);
Renderer.Width := 6000;
Renderer.Height := 6000;
Flame.FilterRadius := 1.2;
Flame.Oversample := 1;
Flame.SampleDensity := 1000;
Renderer.Filename := 'C:\Program Files\Apophysis 2.0\Prints\' + Flame.Name + '.jpg';
SetRenderBounds;
Render;
LoadFlame(1);
Renderer.Width := 6000;
Renderer.Height := 6000;
Flame.FilterRadius := 0.8;
Flame.Oversample := 1;
Flame.SampleDensity := 500;
Renderer.Filename := 'C:\Program Files\Apophysis 2.0\Prints\' + Flame.Name + '.jpg';
SetRenderBounds;
Render;
.
.
.
etc.

This takes very little time and provides complete flexibility for parameter choice for unattended rendering.

Thursday, 7 February 2008

Tip: animation scripts

As I've just posted my first animations, I thought I'd share my methodology. But remember, this is my way: there are many others. Some have used this script, but I much prefer the control gained by hand-crafting. Basic format:

Path := 'c:\whatever';
SetRenderBounds;
Flame.SampleDensity := 200;
Flame.Width := 640;
Flame.Height := 480;
Flame.Oversample := 4;
Flame.FilterRadius := 1;
Flame.Name := ('base0000');
SaveFlame(Path + 'myname.flame');

(initialise variables)

(for/while loop, must contain:


SetActiveTransform(i);

(increment variables)

SetActiveTransform(i+n);

(increment variables)

"
"


Flame.Name := 'base' + Format('%.4d', [j]);
SaveFlame(Path + 'myname.flame');
where j increments
end loop)


SetFlameFile(Path + 'myname.flame') ;
for i := 0 to FileCount do
begin
LoadFlame(i);
Renderer.Filename :=Path + Flame.Name + '.jpg';
Flame.SampleDensity := 200;
Renderer.Width := 640;
Renderer.Height := 480;
Flame.Oversample := 4;
Flame.FilterRadius := 1;
SetRenderBounds;
Render;
end;
UpdateFlame := False;

where:

this font denotes example only - substitute with your own text/value
this font denotes general instructions

Thursday, 24 January 2008

Tip: Functions.asc

Is there a script or fragment thereof that's re-usable elsewhere? If you have such a thing, then it's possible to call it from other scripts by naming and storing in your Functions.asc script file that comes with the program and resides in you scripts folder. Open Functions.asc: you should see:

{**********************************}
{ Functions and procedures for use }
{ by other scripts. }
{**********************************}
procedure CalculateColors;
{ Spreads the color parameters evenly }
begin
for i := 0 to Transforms - 1 do
begin
SetActiveTransform(i);
Transform.Color := i / (Transforms - 1);
end
end;

As an example, copy the following into the file and save.

procedure FineGradient;
For i := 0 to 255 do
Begin
For j := 0 to 2 do
Begin
Flame.Gradient[i][j] := trunc(31+random*191) ;
End
End;

To prove that it works, open the script editor (Ctrl-D) and click on the 'New' icon (top of right-hand panel). Type, or copy and paste, FineGradient and click on the 'Run' icon (green triangle) - your current gradient will be replaced by a 256-band brightly-coloured one.

Troubleshooting: if it doesn't work, check that Functions.asc is selected in Options, Paths, Function library