2013/05/22

The Labs.Com PicArt PicArt: Script
Last update 2001/07/16

The Labs - Design & Functionality For The Net

The Reference Manual of PicArt-Script

  1. Introduction
  2. Philosophy
  3. Types
  4. Reference
  5. Reference
  6. Stack vs. Functions
  7. Assignments
  8. Online Help
  9. Resources
PicArt: Script
1. Introduction
PicArtScript is the core of the PicArt-Package. It's a very simple stack oriented language like PostScript.

In example, to add two numbers: 2 5 add, executed you will have 7 on the stack:

Stack:2 5
2
add
5
2
7
Token:25add

PicArt: Script
2. Philosophy

Philosophy of PicArtScript is that images are objects which you can apply effect(s) on (all programs listed).

PicArt: Script
3. Types

There are only five types of operands:
  • numbers: 1.545 13434
  • strings: "Hello" "After all"
  • images: a.jpg /tmp/mylocal.ppm
  • literals: /name /test
  • ordinary token: show xyz paste
If an ordinary token is an executable token then it will be, otherwise considered as operand. Numbers, strings and images are all stored as string internally, only the commands then decide how things are handled.

PicArt: Script
4. Reference
Stack Oriented

<font>text.font
<points>text.size
<x> <y>text.scale
<r> <g> <b>text.rgb
<text>text <imgout>
Hint: All its sub-command handle the text-rendering
% echo 'Times-Bold text.font 24 text.size 0 0 0 text.rgb "This is a sample string" text xv' | pascript -

<path>setfontpath
<font>setfont
<points>setfontsize
<x> <y>setfontscale
<r> <g> <b>setrgb
<text>show <imgout>
Hint: The same as text (just for compatibility reason)
% echo 'Times-Bold setfont 24 setfontsize 0 0 0 setrgb "This is a sample string" show xv' | pascript -

<w> <h> <r> <g> <b> <a>make <imgout>
% echo '80 50 128 200 255 0 make xv' | pascript -

<img>sizeof <w> <h>
<imgbase> <w> <h>scale <imgout>
Hint: <w> & <h> can be absolute values ie 160, when one size is defined then either <w> or <h> can be 'constrain'. <w> or <h> also can be also 1.5x or .5x
% echo 'Images/albuquerque-small.jpg 100 200 scale xv' | pascript -

<imgbase> <rot>rotate <imgout>
% echo 'Images/albuquerque-small.jpg 25 rotate xv' | pascript -

<imgbase> <h> <s> <l>hsl <imgout>
Hint: <h> is hue, offset -1 .. 1, 0 is neutral; <s> is saturation, 1 is neutral; <l> is lightness, 1 is neutral
% echo 'Images/albuquerque-small.jpg .1 1. 1. hsl xv' | pascript -

% echo 'Images/albuquerque-small.jpg 0 1.5 1. hsl xv' | pascript -

% echo 'Images/albuquerque-small.jpg 0 1. 1.5 hsl xv' | pascript -

<imgbase> <contrast>contrast <imgout>
% echo 'Images/albuquerque-small.jpg 5. contrast xv' | pascript -

% echo 'Images/albuquerque-small.jpg .2 contrast xv' | pascript -

<imgbase> <x> <y> <imgpaste>paste <imgout>
Hint: <x> or <y> can be absolute values, 50- are right aligned, 'center' is centered (vertical or horizontal), the same .5x
% echo 'Images/albuquerque-small.jpg 20 20 Helvetica text.font 24 text.size 255 255 255 text.rgb "This is a scenery" text paste xv' | pascript -

<imgbase> <imgalpha>alpha <imgout>
% echo 'Images/bw.gif dup alpha xv' | pascript -

<imgbase> <r> <g> <b>alpha <imgout>
<imgbase> <which>extract <imgred> <imggreen> <imgblue> <imgalpha>
<imgbase> <w> <h>tile <imgout>
% echo 'Images/albuquerque-small.jpg 50 40 scale 300 150 tile xv' | pascript -

<imgbase> <shadeimg>shade <imgout>
% echo 'Images/albuquerque-small.jpg Images/sea.ppm shade xv' | pascript -

<img> <shear>shear <imgout>
% echo 'Images/albuquerque-small.jpg .1 shear xv' | pascript -

<img> <spread>spread <imgout>
% echo 'Images/albuquerque-small.jpg 5 spread xv' | pascript -

<img> <depth> <rot>smear <imgout>
% echo 'Images/albuquerque-small.jpg 10 45 smear xv' | pascript -

<imgbase>smooth <imgout>
% echo 'Images/albuquerque-small.jpg smooth xv' | pascript -

<imgbase> <depth>smooth <imgout>
<xs> <ys>wavy.noise
<rot>wavy.linear
<xr> <yr>wavy.circular
<imgbase> <scale> <heavyness>wavy <imgout>
% echo 'Images/albuquerque-small.jpg 5 10 wavy xv' | pascript -

% echo '2. .5 wavy.noise Images/albuquerque-small.jpg 5 10 wavy xv' | pascript -

% echo '.7 .3 wavy.circular Images/albuquerque-small.jpg 10 10 wavy xv' | pascript -

% echo '45 wavy.linear Images/albuquerque-small.jpg 10 10 wavy xv' | pascript -

<imgbase> <a> <b> <c> <x> <y>whirl <imgout>
% echo 'Images/albuquerque-small.jpg 2 10 40 .5 .5 whirl xv' | pascript -

<imgbase> <scale> <heavyness> <r> <g> <b> <a>noise <imgout>
% echo 'Images/albuquerque-small.jpg 10 2 1 1 1 1 noise xv' | pascript -

<imgbase> <scale> <heavyness> <octave> <r> <g> <b> <a>turbulence <imgout>
<imgbase> <scale> <heavyness>bumpy <imgout>
% echo 'Images/albuquerque-small.jpg 10 1. bumpy xv' | pascript -

<imgbase> <factor>blowup <imgout>
% echo 'Images/albuquerque-small.jpg 2. blowup xv' | pascript -

<img> <brush> <dir>stroke <imgout>
% echo 'Images/albuquerque-small.jpg Images/brush-2.jpg Images/stroke-radial.jpg stroke xv' | pascript -

<img1> <img2> <fade>fade <imgout>
% echo 'Images/albuquerque-small.jpg Images/waterfall-small.jpg .5 fade xv' | pascript -

<img> <r> <g> <b> <a>gamma <imgout>
% echo 'Images/albuquerque-small.jpg 2. .5 1. 1. gamma xv' | pascript -

<imgbase> <x> <y> <w> <h>cut <imgout>
% echo 'Images/albuquerque-small.jpg 20 40 150 80 cut xv' | pascript -

<imgbase> <x> <y> <w> <h>pick <r> <g> <b> <a>
<imgbase>flipv <imgout>
% echo 'Images/albuquerque-small.jpg flipv xv' | pascript -

<imgbase>fliph <imgout>
% echo 'Images/albuquerque-small.jpg fliph xv' | pascript -

<imgbase>flipcw <imgout>
% echo 'Images/albuquerque-small.jpg flipcw xv' | pascript -

<img1> <img2>catv <imgout>
% echo 'Images/albuquerque-small.jpg 120 80 scale Images/waterfall-small.jpg 120 80 scale catv xv' | pascript -

<img1> <img2>cath <imgout>
% echo 'Images/albuquerque-small.jpg 120 80 scale Images/waterfall-small.jpg 120 80 scale cath xv' | pascript -

<img>invert <imgout>
% echo 'Images/albuquerque-small.jpg invert xv' | pascript -

<imgbase> <w> <h>border <imgout>
% echo 'Images/albuquerque-small.jpg 40 20 0 0 0 0 border xv' | pascript -

<img> <w> <h> <r> <g> <b> <a>border <imgout>
<w> <h> <border> <r> <g> <b>button <imgout>
% echo '220 90 4 190 160 50 button xv' | pascript -

<imgbase> <imgmask>mask <imgout>
% echo '220 90 4 190 160 50 button Images/sea.ppm 220 90 scale mask xv' | pascript -

<imgbase> <r> <g> <b> <a>map <imgout>
% echo 'Times-Bold text.font 60 text.size "Test1" text 255 0 0 0 map xv' | pascript -

% echo 'Times-Bold text.font 60 text.size "Test2" text Images/sea.ppm map xv' | pascript -

<imgbase> <imgmask>map <imgout>
<img> <freq> <bright>stars <imgout>
% echo '300 100 0 0 0 0 make 2 1.5 stars .8 .3 50 20 1. 2.5 255 200 150 supernova xv' | pascript -

<base> <x> <y> <r> <spks> <sharp> <bright> <r> <g> <b>supernova <imgout>
% echo 'Images/albuquerque-small.jpg .1 .6 20 20 1. 1.8 255 200 150 supernova xv' | pascript -

% echo '150 150 0 0 0 0 button .2 .8 50 5 5. 1.5 255 100 100 supernova .5 .2 50 5 5. 1.8 100 255 100 supernova .8 .8 50 5 5. 1.8 100 100 255 supernova xv' | pascript -

<x> <y> <z> <r> <g> <b> <intens>light.point
<x> <y> <z> <r> <g> <b> <intens>light.direction
<ambient>light.ambient
<spec> <specwidth>light.specular
<imgbase> <imgheight>light <imgout>
% echo 'Images/bw.gif dup alpha dup 0 0 1 1 linear 250 250 0 0 250 20 20 0 blend map dup a extract invert smooth smooth smooth -1 -1 1 1 1 1 1 light.direction 1 3 light.specular light xv' | pascript -

% echo 'Times-Bold text.font 50 text.size 50 20 150 text.rgb Hello text 2 2 border dup a extract invert smooth smooth -1 -.5 1 1 1 1 .8 light.point 1 1 1 0 1 0 .7 light.direction -1 1 1 1 .6 0 1. light.direction 0 light.ambient 1.5 4 light.specular light xv' | pascript -

<imgbase> <xr0> <yr0> <xr1> <yr1> <type> <r> <g> <b> <a> <r1> <g1> <b1> <a1>blend <imgout>
% echo 'Images/albuquerque-small.jpg 0 0 0 1 linear 0 0 200 0 0 0 50 255 blend xv' | pascript -

% echo 'Images/albuquerque-small.jpg .1 .6 .4 .8 radial 250 200 0 0 100 80 0 255 blend xv' | pascript -

% echo 'Times-Bold text.font 50 text.size Hello text dup 0 .3 0 1 linear 255 0 0 0 255 255 0 0 blend map xv' | pascript -

% echo 'Times-Bold text.font 50 text.size Hello text dup 0 .3 0 1 linear 3 1 255 255 255 0 make 255 0 0 0 draw.rgba 1 0 draw.point 255 255 0 0 draw.rgba 2 0 draw.point draw blend map xv' | pascript -

<imgbase> <xr0> <yr0> <xr1> <yr1> <type> <imgpalette>blend <imgout>
<img> <r> <g> <b> <a> <x> <y> <tolerance>fill <imgout>
% echo 'Images/albuquerque-small.jpg 255 255 0 0 5 5 .2 fill xv' | pascript -

<x> <y> <x1> <y1>draw.line
<r> <g> <b> <a>draw.rgba
<x> <y>draw.point
<x> <y> <x1> <y1>draw.rect
<x> <y> <x1> <y1>draw.fillrect
<x> <y> <rx> <ry>draw.ellipse
<x> <y> <rx> <ry>draw.fillellipse
<x> <y> <x2> <y2> .. <xN> <yN> <n>draw.poly
<x> <y> <x2> <y2> .. <xN> <yN> <n>draw.fillpoly
<imgbase>draw <imgout>
Hint: All draw.* commands are executed once you call draw itself, try to call draw as rarely as required to speed up drawing instead to call draw after each draw.* occurance.
% echo 'Images/albuquerque-small.jpg 255 0 0 0 draw.rgba 20 10 40 80 draw.line 0 0 255 128 draw.rgba 80 80 40 20 draw.fillellipse draw xv' | pascript -

<img> <cols> <name>togif
<img> <r> <g> <b> <cols> <name>togif
<img> <quality> <name>tojpeg
<img> <name>toppm
<img>xv
<fname>fstat <mtime> <length>
<any>print
<any1> <any2>lt <boolean>
<any1> <any2>< <boolean>
<any1> <any2>gt <boolean>
<any1> <any2>> <boolean>
<any1> <any2>eq <boolean>
<any1> <any2>== <boolean>
<any1> <any2>add <sum>
<any1> <any2>+ <sum>
<any1> <any2>sub <sub>
<any1> <any2>- <sub>
<any1> <any2>div <div>
<any1> <any2>/ <div>
<any1> <any2>mul <sum>
<any1> <any2>* <sum>
<any1>int <int>
<any1>sin <sin>
<any1>asin <asin>
<any1>cos <cos>
<any1>acos <acos>
<any1>tan <tan>
<any1>atan <atan>
<any1>abs <abs>
<any1> <any2>exch <any2> <any1>
<any>pop
<any>dup <any> <any>
/<name> <any>def
<any> <token>find <ntimes>
<any> <token>split <...>
<anyN> .. <any1> <n>ncat <outstr>
<filename>exec
<sequence>execstack
<bool> <{...}>if
<bool> <{true...}> <{false...}>ifelse
<start> <end> <step> <{loop...}>for

PicArt: Script
5. Reference
Function Call

text.font(<font>)
text.size(<points>)
text.scale(<x>, <y>)
text.rgb(<r>, <g>, <b>)
text(<text>) <imgout>
setfontpath(<path>)
setfont(<font>)
setfontsize(<points>)
setfontscale(<x>, <y>)
setrgb(<r>, <g>, <b>)
show(<text>) <imgout>
make(<w>, <h>, <r>, <g>, <b>, <a>) <imgout>
sizeof(<img>) <w> <h>
scale(<imgbase>, <w>, <h>) <imgout>
rotate(<imgbase>, <rot>) <imgout>
hsl(<imgbase>, <h>, <s>, <l>) <imgout>
contrast(<imgbase>, <contrast>) <imgout>
paste(<imgbase>, <x>, <y>, <imgpaste>) <imgout>
alpha(<imgbase>, <imgalpha>) <imgout>
alpha(<imgbase>, <r>, <g>, <b>) <imgout>
extract(<imgbase>, <which>) <imgred> <imggreen> <imgblue> <imgalpha>
tile(<imgbase>, <w>, <h>) <imgout>
shade(<imgbase>, <shadeimg>) <imgout>
shear(<img>, <shear>) <imgout>
spread(<img>, <spread>) <imgout>
smear(<img>, <depth>, <rot>) <imgout>
smooth(<imgbase>) <imgout>
smooth(<imgbase>, <depth>) <imgout>
wavy.noise(<xs>, <ys>)
wavy.linear(<rot>)
wavy.circular(<xr>, <yr>)
wavy(<imgbase>, <scale>, <heavyness>) <imgout>
whirl(<imgbase>, <a>, <b>, <c>, <x>, <y>) <imgout>
noise(<imgbase>, <scale>, <heavyness>, <r>, <g>, <b>, <a>) <imgout>
turbulence(<imgbase>, <scale>, <heavyness>, <octave>, <r>, <g>, <b>, <a>) <imgout>
bumpy(<imgbase>, <scale>, <heavyness>) <imgout>
blowup(<imgbase>, <factor>) <imgout>
stroke(<img>, <brush>, <dir>) <imgout>
fade(<img1>, <img2>, <fade>) <imgout>
gamma(<img>, <r>, <g>, <b>, <a>) <imgout>
cut(<imgbase>, <x>, <y>, <w>, <h>) <imgout>
pick(<imgbase>, <x>, <y>, <w>, <h>) <r> <g> <b> <a>
flipv(<imgbase>) <imgout>
fliph(<imgbase>) <imgout>
flipcw(<imgbase>) <imgout>
catv(<img1>, <img2>) <imgout>
cath(<img1>, <img2>) <imgout>
invert(<img>) <imgout>
border(<imgbase>, <w>, <h>) <imgout>
border(<img>, <w>, <h>, <r>, <g>, <b>, <a>) <imgout>
button(<w>, <h>, <border>, <r>, <g>, <b>) <imgout>
mask(<imgbase>, <imgmask>) <imgout>
map(<imgbase>, <r>, <g>, <b>, <a>) <imgout>
map(<imgbase>, <imgmask>) <imgout>
stars(<img>, <freq>, <bright>) <imgout>
supernova(<base>, <x>, <y>, <r>, <spks>, <sharp>, <bright>, <r>, <g>, <b>) <imgout>
light.point(<x>, <y>, <z>, <r>, <g>, <b>, <intens>)
light.direction(<x>, <y>, <z>, <r>, <g>, <b>, <intens>)
light.ambient(<ambient>)
light.specular(<spec>, <specwidth>)
light(<imgbase>, <imgheight>) <imgout>
blend(<imgbase>, <xr0>, <yr0>, <xr1>, <yr1>, <type>, <r>, <g>, <b>, <a>, <r1>, <g1>, <b1>, <a1>) <imgout>
blend(<imgbase>, <xr0>, <yr0>, <xr1>, <yr1>, <type>, <imgpalette>) <imgout>
fill(<img>, <r>, <g>, <b>, <a>, <x>, <y>, <tolerance>) <imgout>
draw.line(<x>, <y>, <x1>, <y1>)
draw.rgba(<r>, <g>, <b>, <a>)
draw.point(<x>, <y>)
draw.rect(<x>, <y>, <x1>, <y1>)
draw.fillrect(<x>, <y>, <x1>, <y1>)
draw.ellipse(<x>, <y>, <rx>, <ry>)
draw.fillellipse(<x>, <y>, <rx>, <ry>)
draw.poly(<x>, <y>, <x2>, <y2>, .., <xN>, <yN>, <n>)
draw.fillpoly(<x>, <y>, <x2>, <y2>, .., <xN>, <yN>, <n>)
draw(<imgbase>) <imgout>
togif(<img>, <cols>, <name>)
togif(<img>, <r>, <g>, <b>, <cols>, <name>)
tojpeg(<img>, <quality>, <name>)
toppm(<img>, <name>)
xv(<img>)
fstat(<fname>) <mtime> <length>
print(<any>)
lt(<any1>, <any2>) <boolean>
<(<any1>, <any2>) <boolean>
gt(<any1>, <any2>) <boolean>
>(<any1>, <any2>) <boolean>
eq(<any1>, <any2>) <boolean>
==(<any1>, <any2>) <boolean>
add(<any1>, <any2>) <sum>
+(<any1>, <any2>) <sum>
sub(<any1>, <any2>) <sub>
-(<any1>, <any2>) <sub>
div(<any1>, <any2>) <div>
/(<any1>, <any2>) <div>
mul(<any1>, <any2>) <sum>
*(<any1>, <any2>) <sum>
int(<any1>) <int>
sin(<any1>) <sin>
asin(<any1>) <asin>
cos(<any1>) <cos>
acos(<any1>) <acos>
tan(<any1>) <tan>
atan(<any1>) <atan>
abs(<any1>) <abs>
exch(<any1>, <any2>) <any2> <any1>
pop(<any>)
dup(<any>) <any> <any>
def(/<name>, <any>)
find(<any>, <token>) <ntimes>
split(<any>, <token>) <...>
ncat(<anyN>, .., <any1>, <n>) <outstr>
exec(<filename>)
execstack(<sequence>)
if(<bool>, <{...}>)
ifelse(<bool>, <{true...}>, <{false...}>)
for(<start>, <end>, <step>, <{loop...}>)

PicArt: Script
6. Stack vs. Functions

You can mix stack-oriented or function-oriented calls:

 "Hello" show 2 2 255 255 0 0 border xv 

is the same as

 show("Hello") border(2,2,255,255,0,0) xv 

border requires as first argument the image, that is obmitted and taken from the stack, which was given by output of show already. In this way, whatever you are more familiar, use function-oriented or stack-oriented calls.

Important Note: Be aware that always arguments are put on stack, even when it's a function-oriented call!

PicArt: Script
7. Assignments

Since PicArtScript was designed as stack oriented language, addtionally the function-call style is available as mentioned above, there are also several ways to make assignments:

Assignment is done with def or =:

 /posx 10 def 
 10 /posx exch def 
 posx = 10; 

also valid

 /posx 10 5 add def 
 10 5 add /posx exch def 
 posx = 10 5 add; 

The character ";" is used to terminate an "="-assignment, otherwise it's ignored, so you can write also:

 /a = "test file"; show(a); xv(); 

which is the same as

 /a "test file" def a show xv 

or very compact

 "test file" show xv 

So whatever you are comfortable with, your choice.

PicArt: Script
8. Online Help

Online help you get by calling pascript -help or pascript -man search.

 % pascript -man blend 

PicArt: Script
9. Resources

PicArt Cookbook
Further information of how to write stand-alone scripts and tricks
PicArt Script Collection
Collection of stand-alone & shaders

                                                                                                                                   

PicArt: Programs PicArtPicArt Cookbook

Hipocrisy of the finest:

"I agree that no single company can create all the hardware and software. Openness is central because it's the foundation of choice."
-- Steve Balmer (Microsoft) blaming Apple regarding iPhone, February 18, 2009

"Things work better when hardware and software are considered together, [..]. We control it all, we design it all, and we manufacture it all ourselves."
-- Steve Balmer announcing Windows 8 Tablet, June 19, 2012

Last update 2001/07/16

All Rights Reserved - (C) 1997 - 2012 by The Labs.Com

Top of Page

The Labs.Com