1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
{ Simple program that uses CastleScript to create an image
[http://castle-engine.sourceforge.net/caste_script.php].
CastleScript allows you to load an existing image, or start from scratch,
and perform basic image processing. After the script executed,
we will save image to file.
Run with two parameters: script URL (usually just a filename),
and output image URL (usualy just a filename).
For example
image_make_by_script mkimage_gradient.castlescript new_image.png
Within the script, you have variables:
- result, helper_img (type image),
- i, j, k, l are ints,
- x, y, z, are floats,
- v2, v3, v3 are single-precision vectors of 2,3,4 elements.
You should make a function named "main" in the script, this will be executed.
See example scripts mkimage_*.castlescript in this directory.
}
uses SysUtils, CastleUtils, CastleFilesUtils, CastleStringUtils, CastleImages,
CastleClassUtils, CastleParameters, CastleURIUtils,
CastleScript, CastleScriptParser, CastleScriptVectors, CastleScriptImages,
CastleLog, CastleApplicationProperties;
var
Vars: TCasScriptValueList;
Prog: TCasScriptProgram;
begin
Parameters.CheckHigh(2);
ApplicationProperties.OnWarning.Add(@ApplicationProperties.WriteWarningOnConsole);
Vars := TCasScriptValueList.Create(true);
try
Vars.Add(TCasScriptImage.Create(true));
Vars.Last.Name := 'result';
Vars.Add(TCasScriptImage.Create(true));
Vars.Last.Name := 'helper_img';
Vars.Add(TCasScriptInteger.Create(true));
Vars.Last.Name := 'i';
Vars.Add(TCasScriptInteger.Create(true));
Vars.Last.Name := 'j';
Vars.Add(TCasScriptInteger.Create(true));
Vars.Last.Name := 'k';
Vars.Add(TCasScriptInteger.Create(true));
Vars.Last.Name := 'l';
Vars.Add(TCasScriptFloat.Create(true));
Vars.Last.Name := 'x';
Vars.Add(TCasScriptFloat.Create(true));
Vars.Last.Name := 'y';
Vars.Add(TCasScriptFloat.Create(true));
Vars.Last.Name := 'z';
Vars.Add(TCasScriptVec2f.Create(true));
Vars.Last.Name := 'v2';
Vars.Add(TCasScriptVec3f.Create(true));
Vars.Last.Name := 'v3';
Vars.Add(TCasScriptVec4f.Create(true));
Vars.Last.Name := 'v4';
Prog := ParseProgram(FileToString(Parameters[1]), Vars);
try
Prog.Environment.BaseUrl := URICurrentPath;
Prog.ExecuteFunction('main', []);
SaveImage(TCasScriptImage(Vars[0]).Value, Parameters[2]);
finally FreeAndNil(Prog) end;
finally FreeAndNil(Vars) end;
end.
|