The Scripted Animator
About Animator
Animator is a program that allows you to draw simple animated 2D vector graphics without having to know the intricate APIs of more sophisticated vector libs. You don't have to link with anything: animator reads drawing commands from its STDIN.
Optionally, Animator can describe mouse and keyboard events on its STDOUT, so interactive graphics may be made.
Animator is written in C and depends only on SDL.
Command Line
Animator takes no file arguments, input is always read from STDIN.
The following command line arguments are accepted:
- -h - display help
- -x N - set horizontal resolution (default 640)
- -y N - set vertical resolution (default 480)
- -k - disable keepalive, exit on EOF on STDIN (keepalive is enabled by default)
- -e - enable event reporting (disabled by default)
- -a - do not enforce aspect ratio (enforced by default)
Input Syntax
Input is freeform, tokens are separated by whitespace.
Text starting with the ! character is ignored until EOL.
String constants can be given without quotes if they don't collide with keywords (and they're a single word); otherwise, they should be surrounded with double quotes ". Double quotes and backslashes can be escaped with backslash. Special characters \n \t \r \b \f are supported.
General Commands
- quit - shutdown program
- keepalive on|off - control whether to keep processing events after EOF on STDIN. Enabled by default
- events on|off - control event reporting. Disabled by default. When enabled, the current transformation matrix is saved as the event transformation matrix. Subsequent event coordinates will be reported in this coordinate system.
- resize width height - resize drawing window to a specific resolution
- echo string - write the string (plus a newline) to STDOUT
Frame Management
- frame - use this at the beginning of a frame. Current drawing color is set to white, but nothing else is changed (in particular, current transformations/matrices are preserved).
- flush - use this at the end of a frame. Draws current frame in the window. Can be invoked any time to refresh the window, even in the middle of frames.
- sleep N - sleep N seconds (even event handling stops for this period...)
- aspect on|off - enable/disable enforcing aspect radio (enabled by default)
- bg color - set background color - the color is given in the same form as with the color command
Transformations
Initial coordinate system is left edge to right edge -1 .. 1, bottom edge to top edge -1 .. 1. Transformation matrices are kept on a stack; the top matrix of the stack is the active one.
- rotate angle - apply rotation, angle degrees counter-clockwise
- scale x y - scale current matrix, by x factor horizontally and y factor vertically
- shift x y - apply a translation, by x horizontally and y vertically
- mult 9xN - multiply current matrix with an arbitrary matrix - 9 numbers given in row-major order
- push - create a copy of the current transformation matrix and push it on the stack.
- pop - pop off the topmost element of the stack
Drawing
- color color - set current drawing color; color can be the name of a color, or given in #rrggbb hexadecimal form
- dot x y - draw a single pixel
- line x1 y1 x2 y2 - draw a line
- arrow x1 y1 x2 y2 - draw a line, with an arrowhead at x2,y2
- rect x y width height - draw a rectangle of size width * height, centered at x,y
- text [left|center|right bottom|center|top] x y text - draw text, at x,y; alignment is optional, default is center center
- lines x1 y1 x2 y2 [x3 y3]... - draw a line of multiple connected segments
- poly x1 y1 x2 y2 x3 y3 [x4 y4]... - draw a filled polygon
Macros
- macro name - start recording macro
- endmacro - end recording macro
- invoke name - execute macro
- invoke X Y name - equivalent to: push; shift by X,Y; execute macro; pop
- forget - forget all macros
Not all commands are allowed inside macro bodies; basically only drawing and matrix commands are allowed. This is the full list:
color dot line arrow rect text lines poly push pop mult rotate scale shift invoke
Empty macro bodies are not allowed.
Executing a macro is equivalent to executing the instructions in it.
Event Output
When event reporting is turned on, a description of each event is written to STDOUT, one per line. Coordinates in events are written in the current coordinate system seen at the time of the last events on command.
Reported Event Types
- PRESS button_number X Y
Mouse button pressed.
- RELEASE button_number X Y
Mouse button released.
- MOTION button_mask X Y
Mouse moved.
- KEYDOWN mod_mask unicode keyname
Key pressed.
- KEYUP mod_mask keyname
Key released.
mod_mask is a bitmask integer, describing which modifier keys are currently pressed. Here's the value table:
NONE = 0x0000,
LSHIFT= 0x0001,
RSHIFT= 0x0002,
LCTRL = 0x0040,
RCTRL = 0x0080,
LALT = 0x0100,
RALT = 0x0200,
LMETA = 0x0400,
RMETA = 0x0800,
NUM = 0x1000,
CAPS = 0x2000,
MODE = 0x4000
unicode is an integer: the unicode character the current keypress represents (might be 0 if no character can be associated)
keyname is the name of the pressed key, as reported by SDL_GetKeyName. A list may be seen here (the Common name column). Note that the names may contain spaces.
Author
Copyright (C) 2009 Máté Nagy <mnagy AT port70.net>
Animator is licensed under the GNU General Public License Version 2 (available in the file COPYING) or any later version.
Home page: http://repo.hu/projects/animator