Advanced

Hello World in Piet

Your first Piet program - the classic Hello World example with Docker setup

Writing “Hello World” in Piet is unlike any other programming language - because your “code” is a colorful image that looks like abstract art. There’s no text to type; instead, you create (or download) an image that the interpreter executes.

The Program

Unlike text-based languages, Piet programs are images. Here’s a classic Hello World program:

Piet Hello World Program

This tiny image - just 11x11 pixels of colored blocks - outputs “Hello world!” when run through a Piet interpreter. Each colored pixel is a “codel” (code element), and the color transitions between regions encode the operations.

Create a file named hello.png:

Download the image above, or use this direct link to save the Hello World program:

# Piet programs are images, not text!
# Download hello.png from the link above
# The image encodes: push ASCII values, output characters

How This Program Works

Understanding a Piet program requires tracing the interpreter’s path through the image:

The Execution Flow

  1. Start: The interpreter begins at the top-left corner
  2. Direction: It initially moves right (default Direction Pointer)
  3. Color transitions: Each time the path crosses from one color region to another, an operation is performed
  4. Character output: The program pushes ASCII values onto the stack and outputs them as characters
  5. End: The program terminates when the interpreter gets trapped (surrounded by black/edges)

The Characters

The program outputs “Hello world!” by:

  1. Pushing the ASCII value for ‘H’ (72) using color block sizes and arithmetic
  2. Outputting it as a character
  3. Repeating for ’e’ (101), ’l’ (108), ’l’ (108), ‘o’ (111), ’ ’ (32), ‘w’ (119), ‘o’ (111), ‘r’ (114), ’l’ (108), ’d’ (100), ‘!’ (33)

Why It’s Compact

This Hello World uses clever arithmetic. Rather than creating a 72-pixel region to push ‘H’, it uses smaller regions with multiplication and addition. For example:

  • Push 8, push 9, multiply = 72 (‘H’)
  • This is more space-efficient than a 72-pixel block!

Running with Docker

The easiest way to run Piet without installing an interpreter locally:

1
2
3
4
5
# Pull the Piet interpreter image
docker pull esolang/piet

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

Expected Output

Hello world!

Note: This classic Hello World outputs “Hello world!” (with lowercase ‘w’ and no comma). Different Piet Hello World programs may produce slight variations like “Hello, World!” depending on the author.

Understanding the Colors

Piet uses 20 colors. Here’s how they map to the execution model:

The 18 Chromatic Colors

Arranged in a 6x3 grid by hue and lightness:

RedYellowGreenCyanBlueMagenta
Light#FFC0C0#FFFFC0#C0FFC0#C0FFFF#C0C0FF#FFC0FF
Normal#FF0000#FFFF00#00FF00#00FFFF#0000FF#FF00FF
Dark#C00000#C0C000#00C000#00C0C0#0000C0#C000C0

Special Colors

  • White (#FFFFFF): No operation, allows free movement
  • Black (#000000): Blocks movement, acts as walls

Operations by Color Change

Moving from one color to another performs an operation based on:

  • Hue steps: How many positions around the hue cycle (0-5)
  • Lightness steps: How many positions down the lightness cycle (0-2)

For example:

  • Light Red → Normal Red (0 hue, 1 light) = Add
  • Normal Red → Normal Yellow (1 hue, 0 light) = Push

Creating Your Own Piet Hello World

While you can download existing programs, creating your own is rewarding:

Tools You’ll Need

  1. Image editor: Any editor that can work at pixel level (GIMP, Paint.net, even MS Paint)
  2. Piet color palette: Use exact RGB values for the 20 Piet colors
  3. Planning paper: Map out your algorithm and color transitions
  4. Interpreter: Test frequently with npiet or the Docker image

Design Tips

  1. Start simple: Begin with pushing small numbers
  2. Use arithmetic: Multiply small numbers instead of counting huge blocks
  3. Plan your path: Sketch the Direction Pointer’s route
  4. Test often: Run your image after each major change
  5. Add aesthetics later: Get it working first, beautify after

Variations and Artistic Versions

The Piet community has created many Hello World programs, each with different aesthetics:

Mondrian-Style

Programs designed to look like Piet Mondrian paintings, with black borders and primary colors.

Spiral Programs

Execution paths that spiral inward, ending in a black “cage” at the center.

Minimal Programs

The smallest possible Hello World - optimized for codel count.

Maximum Aesthetic

Programs prioritizing beauty over efficiency, with symmetry and color harmony.

Common Challenges

Wrong Output

  • Cause: Color transitions don’t match intended operations
  • Fix: Trace through manually using the color operation table

Infinite Loop

  • Cause: The Direction Pointer gets stuck bouncing between regions
  • Fix: Add black barriers to guide the path correctly

Unexpected Termination

  • Cause: The interpreter got trapped before finishing
  • Fix: Ensure the path reaches all output operations before hitting walls

Image Format Issues

  • Cause: JPEG compression corrupts colors
  • Fix: Always use PNG or GIF (lossless formats)

Technical Note

The esolang/piet Docker image uses the /bin/piet interpreter, which is based on npiet. It supports:

  • PNG images
  • Configurable codel sizes (defaults to auto-detect)
  • Multiple output modes

Next Steps

Now that you’ve run your first Piet program, explore:

  • Creating your own images: Start with simple number outputs before attempting strings
  • The npiet debugger: Use trace mode to see execution step-by-step
  • Artistic challenges: Create a visually appealing version of Hello World
  • Complex programs: The Piet community has implemented games and interpreters!

The beauty of Piet is that every program is literally a work of art. Happy painting!

Running Today

All examples can be run using Docker:

docker pull esolang/piet
Last updated: