Experiments in variable fps animation to simulate drawing / handwriting.
Drawing instructions are encoded and stored as a string in the lua code. Two different encodings ISIDORE and ROXANA were implemented, each with corresponding function used to decode and execute the drawing instructions.
TIP: toggle performance monitor using Ctrl+P to view fps
Motivation
When using animation to simulate something being hand-drawn or handwritten, ability to vary the speed of the "pen stroke" can help make the animation look more realistic and convincing, e.g. faster for straight lines, and slower for tight turns and loops.
How?
With this undocumented function:
_set_fps(rate) |
The wiki seems to suggest that 15, 30, or 60 are the only acceptable values, but with a bit of experimentation I found that arbitrary values do work.
There are a few caveats:
- custom main loop required
- seems limited to maximum of 60 fps or thereabouts
- tailoring the fps to whatever is being animated = generally only animating one thing at a time
- undocumented feature, so no official support or guarantee it will continue to work
Preliminaries
Before doing anything fancy, it is important to note that on a raster display, animating a line or curve as it is extended pixel-by-pixel will cause the perceived speed of drawing to vary depending on direction. We will need to compensate for this when setting the speed at which a "pen stroke" is animated.
(If you understand why, feel free to skip ahead. Otherwise, open hidden block for explanation.)
Encoding schemes
ISIDORE
The basic idea is to specify the predominant axis of motion and increment along it at 1px intervals, then provide the offset (along the other axis) where the pen/brush should be placed.
There are two variants:
- Metavlitos: this was the original version which specified the brush size to use at every increment
- Konstantinos: added later for more efficient encoding when brush size does not change often (=in most cases)
Details inside spoiler block:
ROXANA
The basic idea is to specify the coordinates of a starting point, and subsequently move the pen/brush by small increments, each given as x- and y- offsets from the preceding position.
Like Isidore, Roxana has two variants:
- Metavlitos: brush size specified at every increment
- Konstantinos: changes in brush size requires control code
Details inside spoiler block:
changelog
2021-04-09 - Roxana v1.0 initial version
2021-04-05 - Isidore v1.0 initial version
[Please log in to post a comment]