SWOG language syntax

The picture is described in text file commands, one on each line. Each command's end has the same syntax:
/alt/ :name <link> [param1:value1] .. [paramN:valueN]
*You can see argument descriptions when moving mouse pointer on arguments
All above arguments are not usually mandatory (this is shown by color )

new 100,100

fcircle 60,60 30 red /a simple link title/ <> 

frect 10,10 30 20 [map_title:javascript region] [map_onclick:alert('You clicked on a rect!')]

Few words about coordinates format. When command syntax is like
line coordinate dimension ,
then it means that coordinate has to be replaced by one of following:
  • coordinates in form x,y
  • point on object in form (object_name.point) , where point name depends on referenced object. For example for rectangle legal values are p1, p2, p3, p4 and center All objects named points
  • object name in form (object_name), then values for x and y are taken from object object_name x and y.
And dimension may be given as coordinate in same format as coordinate or as figure's width-height in format width height.
new 220,220
line 10,10 100 50 blue :joon
#line was drawn from 10,10 to 110,60

line (joon) 200,200 red
#line was drawn from 10,10 to 200,200

Commands by function

Set output format
export new
Set coordinates system
coordsys mirror newCoordsys newCoordsysPoints origin rotate scale
(f)arc (f)circle connect (f)ellipse fill fillToBorder image line (f)poly (f)rect string
Create complex shapes
dots drawAxis frects lineGraph object tree
Define helper objects
axis color defObject font gradient point pointAdd
Set drawing environment
setColor setFont setLineThickness undo
Change objects on picture
alter moveAfter moveBefore newSECorner
Using other drawing programs
gnuplot graphviz mimetex
Output image
outputRawGif outputRawGifAnim outputRawHtml outputRawPng outputRawSVG toGif toGifAnim toHtml toPng toSVG

Commands in alphabethical order

alter new value property object
(Command is not useable in fast mode)

Changes object property, usually are legal values for property color or font. However this changing does not change size for SWOG engine: When a font size is changed then text is drawn with new font, but for example click detection uses old size.
new 100,50

string 10,10 black {tere} :jutt

#muudame jutu värvi punaseks:
alter red color jutt

(f) arc coordinate x_radius y_radius start_deg end_deg color object points

Draws an arc, angle on ellipse increases from right side in clock-wise direction.
See also: ellipse

axis arrowStyle coverage ticked labeled-ticks label_position label_font

Defines axis style, by default is useable the axis defAxis, which is defined by command
axis arrow auto ticks all above medium :defAxis
See also: lineGraph

(f) circle coordinate radius color object points

Draws a circle.

color red green blue alpha :name

color_name alpha :name
Defines color by setting it's red, green, blue and transparency factors.
new 100,60
color 5 54 324 :minu_varv
color red 100 :punane_kuma

frect 0,0 50 60 blue
frect 40,10 50 60 punane_kuma

connect p1 p2 color

Connects the given circles or ellipses by lines this way that lines are drawn from arc to arc. There may be point coordinate in each argument, then the line is drawn to given point.
new 400,280
defObject mull
fellipse 50,50 50 25 greenyellow
ellipse 50,50 50 25 :r
string center center 50,50 {%this}

object 10,10 mull :a <>
object 10,160 mull :b <>
object 120,70 mull :c <>
object 240,90 mull :d <>

connect a.r c.r
connect a.r b.r
connect c.r d.r
connect b.r d.r

coordsys origin-and-direction

Sets coordinates system. By default rules coordsys west north right down (that is zero-point is in upper left corner and axes point to right and down).

defObject class-name


Defines a new object class which can ne used for drawing. row1..N may contain all SWOG commands (except defObject) also you can use parameters in format %1, %2 ... and variable %this, which is replaced by drawn object name.
new 190,100

defObject ruut
        frect 10,10 20 20 %1

defObject nelik
	frect 0,0 80 80 %1
        object 0,0 ruut red
        object 40,0 ruut black
        object 0,40 ruut black
        object 40,40 ruut red

object 10,10 nelik yellow
object 95,10 nelik pink

dots coordinate1 .. coordinateN color

Outputs the given points.
new 100,100

dots 10,10 12,12 14,14 16,16 18,18 $
30,31 32,34 36,37 38,40 red

dots 50,50 50,60 50,70 black

drawAxis coordinate length axis start end {values} color

Draws coordinates axis.
new 140,40

drawAxis 20,30 100 defAxis -10 250 {0;100;200}    

(f) ellipse coordinate x_radius y_radius color object points

Draws an ellipse.

export clean-screen duration

Animation frame is output on export commands, therefore this command should be the last command in case of animations. If it wasn't the last command then last frame would not be drawn. Command export is ignored when output format is not gif animation.
new 330,180 white

point 140,80 :kesk
ellipse (kesk) 100 50 :ellips

export 200

arc (kesk) 100 50 10 80 :kaar
line (kaar.p1) (kaar.p2)
export 200

arc (kesk) 100 50 80 150 :kaar1
line (kaar1.p1) (kaar1.p2)
export 200

arc (kesk) 100 50 150 220 :kaar2
line (kaar2.p1) (kaar2.p2)
export 200

line (kaar.p1) (kaar2.p2)

export clean 200
fpoly (kaar.p1) (kaar.p2) (kaar2.p1) (kaar2.p2) purple

export 1000

fill coordinate color

Fills picture from the given point using the given color. It is filled until it meets a color which has other than the one in starting point.
See also: fillToBorder

fillToBorder coordinate borderColor fillColor

Fills picture from the given point with the fillColor . Painting is made until it meets the borderColor.
See also: fill

font {filename} angle size

Command is for using TrueType (.ttf) font. When one doesn't want to use ttf font files there are GD fonts called tiny, small, medium, large and giant for using.
With program distribution there are ARIAL.TTF and Manga Temple.ttf fonts in catalog fonts/. The fonts come from and are claimed to be for free use. While outputting SVG fonts link descriptive text is also used. Format for /alt/ is: property1|value1|... For example when alt= family|Serif|weight|bold, then to SVG it is added as font-family="Serif" font-weight="bold"
new 30,20

font {Arial.ttf} 8 :arial8
string 10,10 black arial8 {tere!}

frects coordinate rectWidth rectHeight gradient col1level .. col2level object points

Draws filled rectangles next to each other. Rectangles are always in shape of rects, coordinatesystem transformation is applied only to start point. It is also possible to use alternate form in which colors are not given as gradient levels but by usual color codes (but this format is slower to parse)
new 200,100

frects 10,10 15 10 #000000 #880000 #ff0000 #008800 #00ff00 #000088 

gradient red green 50 :gradient

frects 10,40 20 20 gradient 0 10 20 30 40 50

See also: gradient

gnuplot coordinate width height


Draws picture by using gnuplot. Rows row1..N contain gnuplot drawing commands.
new 400,200

gnuplot 10,0 300 200 :plot
	set title "Sin from gnuplot"
	plot sin(x)

#and draw a rect around the gnuplot output
rect (plot.p1) (plot.p3)

gradient startColor endColor startValue endValue :gradientName

Defines gradient, which changes from color startColor to endColor on the given scale. You can use gradient as regular color in format gradientName#level, where level is in slice [startValue,endValue].
new 110,60

gradient red blue 100 :grad

frect 5,0 20 20 grad#1
frect 25,0 20 20 grad#25
frect 45,0 20 20 grad#50
frect 65,0 20 20 grad#75
frect 85,0 20 20 grad#100

gradient #ff00007F red  1 :alpha
frect 5,30 20 20 alpha#0
frect 25,30 20 20 alpha#0.1
frect 45,30 20 20 alpha#0.2
frect 65,30 20 20 alpha#0.5

graphviz layout-program coordinate

   objectName1 /alt/ <link>
   objectNameL /alt/ <link>

Draws a graph by using Graphviz. Part
   objectName1 /alt/ <link>
   objectNameL /alt/ <link>
, which may also be repeated is optional, here are defined graph nodes which will be used as SWOG objects. It is needed to output HTML clickmaps or use the nodes in SWOG code.

Rows row1..N contain Graphviz input file.
SWOG uses Graphviz binaries from directory bin/thirdparty/graphviz/bin.
NB! Currently click-detection is not complete, you can only detect nodes and only ellises and rects are used. But the command might be improved, when there is a need for it.
new 10,10

graphviz  0,0 :graph 

#define which graph nodes are used in SWOG
	  LR_0 /0/ <>
	  LR_1 /1/ <>  
#and graph in dot format for graphviz
	digraph finite_state_machine {
	        #set size in inches
		node [shape = circle];
		LR_0 -> LR_2 [ label = "SS(B)" ];
		LR_0 -> LR_1 [ label = "SS(S)" ];
		LR_1 -> LR_3 [ label = "S($end)" ];
		LR_2 -> LR_6 [ label = "SS(b)" ];
		LR_2 -> LR_5 [ label = "SS(a)" ];

#make picture as big as graph
newSECorner (graph.p3)

image coordinate width height {filename} imageStartPoint imWidth imHeight

Command to add a picture file. Supported types are png, gif and jpeg.
new 250,70

#joonistame pildi orginaalmõõdus
image 10,10 {salmon.png}

#joonistame pildi ruutu 100 50
image 60,10 100 50 {salmon.png}

#joonistame pildi punktist 10,10
image 170,10 {salmon.png} 10,10

#joonistame pildi ruudust 10,10 10 10
image 210,10 {salmon.png} 10,10 10 10

line coordinate dimension color object points

Draws a line.
See also: setLineThickness

lineGraph axisStyle colWidth lineWidth align coordinates dimension (lines1) :line1Group line1Color ...

linesN are in format lineCoords /alt/ :name <link> and separated by semicolons.
Places the lines to graph this way that they don't intersect and are visible.
When also an axis is drawn then you can access it's point by referrence (graph_name.axis.val_VALUE), where VALUE is the value on scale.
new 500,120

font {Arial.ttf} 12 :arial

axis auto ticks all below arial :telg

#punased ja sinised pannakse samadele ridadele,
#aga rohelised eraldi..
#siin see $ rea lõpus on rea murdja...

lineGraph telg 10 5 up 60,10 400 200  $
(230 35) green  $
(123,209 94,159 345,422 345,416 359,412 288,368 ) :a red  $
(86,136 124,204 ) :a blue  

See also: axis

mimetex tex coordinate dimension

Outputs image drawn by mimetex script. NB! Currently output to SVG format is not supported. It uses program bin/thirdparty/mimetex/mimetex.cgi to create output image.
new 300,100

mimetex \Large f=b_o+\frac{a_1}{b_1+\frac{a_2}   $
	{b_2+\frac{a_3}{b_3+a_4}}} 10,10


Performs coordinate system mirroring.
new 100,100

origin 50,50

line 10,30 -50,-3 red


line 10,30 -50,-3 blue

moveAfter object1_name object2_name
(Command is not useable in fast mode)

Changes objects drawing order.

moveBefore object1_name object2_name
(Command is not useable in fast mode)

Changes objects drawing order.
new 100,50 pink

string 10,10 white giant {tere} :s

#joonistame tekstile sinise tausta:
fpoly (s.p1) (s.p2) (s.p3) (s.p4) blue :taust

#praegu on taust aga teksti peal, liigutame selle tekstist tahapoole
moveBefore taust s

new x,y background color

Sets picture dimensions and background color. This should be the first command in the input file.

newCoordsys coordinate rotateX rotateY scaleX scaleY

Defines 0-coordinate location and axis directions and scales.
new 100,100

#default coordsys would be defined like this:
newCoordsys 0,0 0 -90 

#but lets change zero point to 100,100 and set x-axis to left and y-axis to up
newCoordsys 100,100 180 90  :setting
line 0,0 50 20 red

undo setting

#same zero point
#but x is scaled by 2 and y by 0.5
newCoordsys 100,100 180 90 2 0.5 
line 0,0 50 20 blue

newCoordsysPoints coordinate p1,0 p0,1

Defines coordinatesystem by three points - 0,0 1,0 and 0,1.
new 100,100

#set center to 50,50 and scales equal to 1:

#short version
newCoordsysPoints 50,50 1 1 :setter

#same would be:
#newCoordsysPoints 50,50 51,50 50,51 :setter

line 0,0 40 30 red

undo setter

#but is is also possible to mess up coordsys totally:
newCoordsysPoints 50,50 30,12 17,43

line 0,0 1,0 blue
line 0,0 0,1 green

newSECorner coordinate
(Command is not useable in fast mode)

Changes picture's dimensions. New bottom-right corner will be the given point.
See also: pointAdd

object coordinate object class name arguments

Is meant to use a predefined object. In objects %1 %2 ... are replaced by the arguments.
new 500,400

#algeline kaalumaatriksi tegemise näide

#joonistab T
#antud: laius %1
#       kõrgus %2
#       värv %3 
defObject T
  scale %1,%2
  fpoly 0,0 100,0 100,40 70,40 70,100 30,100 30,40 0,40 %3
#alumine vasak punkt
  point 0,100 :botleft
#ülemine parem punkt
  point 100,0 :topright

#joonistab A
#antud: laius %1
#       kõrgus %2
#       värv %3 
defObject A
  scale %1,%2
  fpoly 50,0 100,100 80,100 65,75 35,75 20,100 0,100 %3
#alumine vasak punkt
  point 0,100 :botleft
#ülemine parem punkt
  point 100,0 :topright

line 10,30 300 0 blue :joon

string south (joon) {2,1}

object (joon) T 1 2 red :T1 <T1>
object (T1.botleft) A 1 1 green :A1 <A1>

pointAdd (T1.topright) 10 0 :rida2
string south (rida2) {0.5,2.5}
scale 0.5,1
object (rida2) T 1 0.5 pink :T2 <T2>
object (T2.botleft) A 1 2.5 violet :A2 <A2>

See also: defObject

origin coordinate

Defines new coordinates system zero point. The new point coordinates are given in current coordinates system.
new 60,50

origin 10,10
#0-punkt on 10,10

line 0,0 10 10 :line1
#tõmbasime joone (10,10)-st (20,20)-sse

origin 10,10
#0-punkt on nüüd 20,20

origin (line1)
#0-punkt on nüüd joone alguspunkt ehk 10,10


Asks interpreter to output GIF image to std output.

outputRawGifAnim temp-dir

Asks interpreter to output GIF animation to std. output.


Asks interpreter to output HTML clickmap to std. output.


Asks interpreter to output PNG image to std. output.


Asks interpreter to output SVG image to std. output.

point coordinate :name

Defines point coordinates.

pointAdd coordinate width height

Defines new point by adding dimensions to the given point coordinates.
new 400,400 yellow2

string 10,10 {tekst} :tekst

pointAdd (tekst.p2) 4 4 :p2

#teeme pildi täpselt nii suureks, et 
#tekstist pildi servani jääks 5 punkti:
pointAdd (p2) 5 5 :aar

newSECorner (aar)

See also: newSECorner

(f) poly coordinate coordinate coordinate other coordinate color object points

Draws a polygon.
new 300,150

fpoly 10,10 270,5 250,100 30,120 red

poly 50,50 150,150 60,34 blue

(f) rect coordinate dimension color object points

Draws a rectangle.

rotate coordinate degrees

Rotates the following objects by the given point the given degrees in counter-clock wise. However, rotation is not implemeneted for all objects. For example circles are only draw as ellipses, they won't be stalled. Also text outputting is not correcty implemented - it is not possible tho output mirror texts.

scale x,y

Changes coordinates system and multiplies following coordinates by the given values. When there are many scale commands, then multiplation is repeated that is commands scale 2,2 and scale 3,3, are same as command scale 6,6.

setColor color_name

Sets color used to draw following figures when color parameter is not given, by default is the used color black.

setFont fontName

Sets defautl font, by default is used medium.

setLineThickness thickness

Changes next lines width, default width is 1 pixel. When the widht is wider then line is drawn as filled polygon. Command helps to create clickable region around lines.
new 270,80

setLineThickness 16
line 50,20 150 30 blue <>

setLineThickness 8
line 50,20 150 30 yellow

#set to default (a simple line):
setLineThickness 1
line 50,20 150 30 red

See also: line

string orientation coordinate color font {text} object points

Outputs text.
See also: setFont

toGif {filename}

Asks interpeter to output picture in GIF format.

toGifAnim {temp-dir} {filename}

Asks interpretator to output gif animation.

toHtml {filename}

Asks interpreter to output HTML clickmap to a file.

toPng {filename}

Asks interpreter to output picture in PNG format.

toSVG {filename}

Asks interpretator to output picture as .svg image.

tree halign coordinate dimension color (rootNode(childNode1(..);childNode2(..);..))

Draws to the rectangle teh given tree. Each nodeInfo has syntax similar to command string syntax: color font {node_name} /alt/ :name <link>
new 295,248

font {Arial.ttf} 12 :arial

setFont arial

tree 0,0 295 248 ({root} /juur/ <> ({child1}; {child2}; {child3}({child3_1}; {child3_2})))

#root peal saab nüüd klikkida...

undo command1_name command2_name command3_name ...

Restores environment settings which were changed by the given commands. Restoring is performed from right to left.
new 170,200

origin 70,50

#teeme ühe vildaka ristküliku:
rotate 0,0 -45 :keera    
rect 0,0 50 80 blue

#lähme tagasi süsteemi, mis oli enne keeramist
undo keera

rect 0,0 50 50 red