A 0-byte sprite sheet: pixel art drawn entirely with code
I stumbled upon a great guide on how to create pixel art without an artist and without a single image file. The author was building a sandbox for social experiments with turtles (involving memory, inherited traits, and the prisoner’s dilemma), and created all the graphics using code on a standard 2D canvas.
The ideas that struck me as most useful:
・A sprite is an array of strings, where each character represents a pixel. The letter doesn’t denote a color, but a role: S — shell, s — dark edge, h — highlight, B — belly. A single stencil works for all turtles.
・The rendering function is about ten lines long; it loops through the rows and calls `fillRect`.
・The pattern on the shell isn’t a drawing, but a rule like (x + y) % 3 === 0.
・The color is taken from the hue gene: the hue is quantized to 36 values in 10° increments, and the rest of the palette is built using HSL. In older turtles, the saturation drops; in sick ones, the face turns green.
・Rendered sprites are cached in an invisible canvas, which is precisely why there are exactly 36 shades—otherwise, the cache would grow indefinitely.
A bonus I hadn’t thought of before: text sprites are stored in Git with a readable diff, and you can write regular unit tests for them. Does anyone else generate sprites procedurally?
Source: Habr
The ideas that struck me as most useful:
・A sprite is an array of strings, where each character represents a pixel. The letter doesn’t denote a color, but a role: S — shell, s — dark edge, h — highlight, B — belly. A single stencil works for all turtles.
・The rendering function is about ten lines long; it loops through the rows and calls `fillRect`.
・The pattern on the shell isn’t a drawing, but a rule like (x + y) % 3 === 0.
・The color is taken from the hue gene: the hue is quantized to 36 values in 10° increments, and the rest of the palette is built using HSL. In older turtles, the saturation drops; in sick ones, the face turns green.
・Rendered sprites are cached in an invisible canvas, which is precisely why there are exactly 36 shades—otherwise, the cache would grow indefinitely.
A bonus I hadn’t thought of before: text sprites are stored in Git with a readable diff, and you can write regular unit tests for them. Does anyone else generate sprites procedurally?
Source: Habr
Comments 0
Leave the first comment, in any language.
Log in to comment