Piet
Piet
Piet is a programming language whose source code is not text but a picture — specifically, an abstract image of colored blocks that looks, by design, like a Piet Mondrian canvas. David Morgan-Mar created it and named it after the Dutch geometric abstractionist, producing the only language in this catalogue whose "Hello, World!" you could plausibly hang in a gallery.[1]
A Piet program is an image made of codels — the language's equivalent of pixels, which may be scaled to arbitrary size for display. Contiguous same-colored codels form color blocks, and execution proceeds when a direction pointer (DP) walks from block to block across the canvas. The command executed at each step is determined not by the color entered but by the change in hue and lightness between the block left and the block entered — the program is encoded in the transitions, which is why a Piet image has no discernible syntax at all: only relationships.[2]
A palette with a program inside
Piet defines exactly 20 colors: six hues (red, yellow, green, cyan, blue, magenta) at three lightness levels — 18 cyclically-ordered colors — plus white, which the pointer passes straight through like blank space, and black, which is impassable. Commands come from the two cycles:
- Hue change (0–5 steps forward around the six-hue ring) selects the row of the command table.
- Lightness change (none, one, or two steps along the light→dark cycle) selects the column.
- Crossing from magenta to red increases hue by one step — the cycle wraps — while going the other way is a five-step move.
The result is a 17-command machine: the no-hue-change row pushes and pops; the one-step row adds, subtracts, multiplies; two steps divide, modulo, NOT; three steps compare, steer the pointer, switch the codel chooser; four steps duplicate, roll, input numbers; five steps do character I/O. Push has a beautiful quirk — it pushes the size of the color block just left, so the physical area of a region of paint is a numeric literal.[3]
Flow control for painters
The direction pointer starts at the upper-left codel moving right, accompanied by a codel chooser (CC) that breaks ties when several blocks qualify as "next." When the DP hits a black wall it cannot cross, the chooser flips, then the pointer rotates clockwise — and if every orientation is walled in, the program ends. The only way to terminate a Piet program is to trap the pointer in black paint. Loops are paths around the canvas; branches are corridors; the pointer and switch commands let data steer execution mid-flight. The whole thing is a maze that computes.[4]
And it is not a toy in the formal sense: Piet is Turing-complete when the stack is unbounded — a result demonstrated concretely by the existence of a Brainfuck interpreter written in Piet, an abstract painting that executes another language's code. Brainfuck, the language designed to be as small as possible, was implemented in the language designed to be as pretty as possible.[5]
Where it sits in the wing
The esolang canon broke one assumption each: INTERCAL broke seriousness, Brainfuck size, Malbolge the programmer, Whitespace visibility, Befunge dimensionality, Unlambda variables, LOLCODE vocabulary, and Shakespeare the identity of code as code. Piet broke the last assumption standing — that a program is text. Its answer is a proof by painting: everything a Turing machine needs can be expressed in areas of flat color, and the result is, genuinely, the only source code in this wiki that improves a room.
Check your understanding
- What determines which command a Piet color block executes — its color, or something else?
- What do black and white blocks do to the direction pointer?
- What does
pushactually push onto the stack? - How does a Piet program terminate?
Show answers
1 — not its color — the transition in hue and lightness between the previous block and the entered block selects the command. 2 — white is pass-through (the pointer slides across, executing nothing); black is impassable and forces pointer/chooser retries. 3 — the number of codels in the block just left — the literal is the paint's physical area. 4 — only when the pointer is completely trapped by black in every direction and chooser state — there is no halt instruction.
Footnotes
- ↑ Piet, esoteric-languages wiki — Morgan-Mar, the Mondrian namesake, and the color-block execution model
- ↑ Piet execution model — codels, color blocks, the direction pointer, and the codel chooser
- ↑ Piet command table — the full 17-command hue/lightness matrix and the block-size push
- ↑ Piet execution model — DP/CC steering, black-wall blocking, and the only termination path
- ↑ Piet computational class — the unbounded-stack caveat and the Piet-hosted Brainfuck interpreter