Vector Graphics in Lil
This technical deep-dive showcases the elegant power of Lil, Decker's APL-inspired scripting language, for manipulating vector graphics. It meticulously explains how complex transformations like scaling, shearing, and rotation are achieved through concise, 'conforming' arithmetic operations on nested data structures. The article appeals to developers fascinated by expressive, array-oriented programming paradigms applied to fundamental graphics problems.
The Lowdown
The article 'Vector Graphics in Lil' delves into the implementation and manipulation of 2D vector graphics within Lil, the APL-influenced scripting language of the Decker ecosystem. It starts by introducing the foundational concepts inspired by Dr. Allen Vincent Hershey's pioneering digital typefaces from his 1967 report, 'Calligraphy for Computers', and how they are handled by Decker's hershey module.
- Foundational Structures: It defines
pointsas(x,y)pairs,strokesas lists of points forming polylines, andpathsas lists of strokes, representing complex shapes or text. Lil represents these as nested lists of numbers. - Text Rendering: The
hershey.textpath[]function is demonstrated for assembling complex paths from text strings using font glyphs, which are then drawn to a canvas using collective operations likec.line @ p. - Conforming Arithmetic: A core theme is Lil's unique 'conforming' arithmetic, where operators implicitly 'spread' across nested list structures. This allows uniform scaling of points, strokes, or paths with simple multiplication, e.g.,
path * 2. - Path-Mangling Techniques: The article explains how to achieve non-uniform scaling, mirroring, and translation using specific 'enclosing' idioms (e.g.,
p * list list scalex,scaley) to guide the conforming behavior. It also details horizontal and vertical shearing by extracting and manipulating x or y coordinates ('peels') from paths. - Rotation and Complex Effects: It introduces
mag,heading, andunitprimitives for decomposing paths into polar coordinates, enabling concise rotation around the origin. Finally, it demonstrates creating complex, dynamic effects like perspective distortion, 'line-boil' (wiggly lines), and 'flapping' animations by combining affine transformations with time-based functions.
In essence, the article provides a detailed look at how Lil's powerful and concise data manipulation capabilities lend themselves to expressive and efficient vector graphics programming, allowing for complex visual effects with minimal code.