Est. 2002 Advanced

Piet

An esoteric programming language where programs are abstract art images, named after painter Piet Mondrian.

Created by David Morgan-Mar

Paradigm Esoteric, Stack-based, Visual
Typing None (stack-based operations)
First Appeared 2002
Latest Version 1.0 (2002)

Piet is one of the most visually striking esoteric programming languages ever created. Instead of text, Piet programs are bitmap images that look like abstract art - specifically, the geometric color-block paintings of Dutch artist Piet Mondrian.

History & Origins

David Morgan-Mar, known for his collection of esoteric programming languages, created Piet in 2002. The language emerged from a simple question: what if programs could be beautiful? While most programming languages use text, Morgan-Mar decided to create a language where the source code itself is a work of art.

The name comes from Piet Mondrian (1872-1944), the Dutch painter famous for his abstract compositions of colored rectangles separated by black lines. The visual style of Piet programs naturally evokes Mondrian’s distinctive aesthetic.

A New Paradigm

Piet challenged fundamental assumptions about programming:

  • Programs as images: Source code is a PNG, GIF, or PPM image file
  • Colors as commands: Different color transitions encode different operations
  • Spatial execution: The interpreter moves through the image in 2D space
  • Art meets code: Programs can be aesthetically designed while remaining functional

How Piet Works

Piet uses 20 colors organized into cycles. The execution model is based on how the “Direction Pointer” moves through colored regions:

The Color System

Eighteen colors are arranged in two cycles:

  • Hue cycle: Red → Yellow → Green → Cyan → Blue → Magenta → Red
  • Lightness cycle: Light → Normal → Dark → Light

Plus two special colors:

  • White: Allows free movement with no operation
  • Black: Acts as a wall, blocking movement

Operations

Commands are determined by the change in hue and lightness when moving from one color block to another:

Lightness ChangeHue +0Hue +1Hue +2Hue +3Hue +4Hue +5
+0-pushpop---
+1addsubtractmultiplydividemodnot
+2greaterpointerswitchduplicaterollin(num)

Additional operations:

  • in(char): Read character input
  • out(num): Output number
  • out(char): Output character

The Stack

Like Forth and Brainfuck, Piet is stack-based. Numbers are pushed by counting the pixels (codels) in a color block. For example, a block of 5 red pixels pushes the value 5 onto the stack.

Direction Pointer (DP)

The interpreter maintains a Direction Pointer that can point right, down, left, or up. It moves through the image, transitioning between color blocks. The pointer command rotates the DP clockwise.

Codel Chooser (CC)

When a color block has multiple edge codels, the Codel Chooser determines which one to exit from. The switch command toggles the CC between left and right.

Creating Piet Programs

Writing Piet is unlike any other programming:

Conceptual Approach

  1. Design the algorithm: Break down what you need (push values, add, output)
  2. Calculate color transitions: Determine which colors produce which operations
  3. Plan the path: Design how the DP will flow through the image
  4. Create the image: Draw colored blocks in the correct arrangement
  5. Test and refine: Run through interpreters, adjust as needed

Tools

Several tools help create and debug Piet programs:

  • npiet: The most popular interpreter, with tracing capabilities
  • PietDev: A visual IDE for creating Piet programs
  • Online IDEs: Browser-based editors for quick experimentation

Artistic Considerations

Many Piet programmers deliberately create visually appealing programs:

  • Symmetry: Arranging code blocks in symmetric patterns
  • Color harmony: Choosing color sequences that look pleasant
  • Mondrian-style: Using black borders between blocks
  • Spiral patterns: Creating execution paths that spiral inward

Implementations

npiet

The de facto standard interpreter, written by Erik Schoenfelder. Features include:

  • PNG, GIF, and PPM image support
  • Execution tracing for debugging
  • Configurable codel size
  • Available in most Linux package managers

Other Interpreters

  • PietJS: JavaScript interpreter for browser execution
  • rpiet: Rust implementation
  • Various online interpreters: Run Piet in your browser

Why Piet Matters

Programming as Art

Piet demonstrates that programming languages don’t have to be textual. It opens questions about what “code” really is and whether programs can have aesthetic value beyond their function.

Educational Value

Piet teaches stack-based programming and forces programmers to think differently about execution flow. The visual nature makes the abstract concepts of a stack tangible.

Turing Completeness

Despite its unusual nature, Piet is Turing complete. Complex programs including interpreters for other languages have been written, proving its computational power.

Community Creativity

The Piet community has created programs ranging from simple Hello Worlds to complex interactive games, all while maintaining visual appeal.

File Format

Piet programs are image files:

  • .png - Most common, supports all colors needed
  • .gif - Also supported
  • .ppm - Portable Pixmap format

The “codel size” determines how many pixels represent one code unit. A codel size of 1 means each pixel is a codel; larger sizes make images more visible but larger in file size.

Continue to the Hello World tutorial to see a Piet program in action.

Timeline

2002
David Morgan-Mar creates Piet, inspired by Piet Mondrian's artwork
2002
Language specification and first interpreter released
2004
Erik Schoenfelder releases npiet, a feature-rich interpreter with tracing and editing capabilities
2006
Thomas Schoch creates artistic Hello World programs demonstrating Piet's aesthetic potential
2008
Matthias Ernst implements a Brainfuck interpreter entirely in Piet
Present
Active community creates complex programs and artistic code

Notable Uses & Legacy

Artistic Programming

Programs intentionally designed as visually appealing abstract art.

Brainfuck Interpreter

Matthias Ernst implemented a complete Brainfuck interpreter in Piet, demonstrating Turing completeness.

Text Adventure Game

One of the most complex Piet programs - a complete text adventure game.

Esoteric Language Education

Used to demonstrate that programs need not be text-based.

Language Influence

Influenced By

Forth Brainfuck Abstract art

Running Today

Run examples using the official Docker image:

docker pull esolang/piet

Example usage:

docker run --rm -v $(pwd):/code esolang/piet /bin/piet /code/hello.png

Topics Covered

Last updated: