Piet Interpreter

Table of Contents
  1. Piet Language
  2. Using the Editor
  3. Using the Interpreter

Click here to go to the Piet interpreter/editor.


During high school, I discovered the wonders of esoteric programming languages (esolangs), and I loved how strange and creative they were. One of the most interesting languages that I found later on was a two-dimensional, stack-based, graphical programming language called Piet, named after Piet Mondrian. Piet's gimmick is that the programs are images that can be made in forms of abstract art.

I had originally played with Piet by making programs by hand in an image editor and using an online interpreter to run them. After much time of writing programs manually, I decided to write an editor and interpreter for Piet, and used it to make this program.

The interpreter was written in about three weeks, with small improvements made later on. You can tell what I found more interesting considering I wrote the interpreter during my final exams.

Hello world

Hello world program by Thomas Schoch.

Piet Language

The basic premise of Piet is that each change in color of each blocks of color results in a different instruction being executed. Each colored blocks are given a value equal to the number of codels (blocks of color representing a single pixel), and these values are used for the instructions executed.

The interpreter will travel between blocks of color from their edges in a specific direction. White spaces are considered empty, and the interpreter will pass through them, whereas the black blocks will stop the interpreter.

Piet is a stack-based programming language, where data is stored only as integers on the stack.

You can read the official description and specification of Piet here.

Using the Editor

Color Tables

The main feature of the editor is the two color tables at the top, which are for quickly writing Piet programs.

The first table is for selecting a Piet color to draw, with the first 18 colors are for commands, and the white and black colors are special.

The second color table is for quickly choosing the next color based on the next instruction desired. The table automatically calculates what colors are next, and you can click on the operation to select the next color. Clicking on the current color box lets you pick any color, including invalid Piet colors. Invalid Piet colors are treated as white according to the specification.

The second color table makes coding Piet programs much faster and efficiently since it's very easy to see what colors need to be used next for the instruction desired.

Edit mode


The editor toolbox is located on the left side of the drawing grid. It has the basic tools: brush, fill, select, move, color picker, undo, and redo. Brush is for drawing, fill changes the adjacent common color codels to the one selected, select draws rectangular bounds, move lets the cursor pan the canvas, color picker picks the codel color, and undo/redo undo/reload the canvas state. Some of the tools have settings that are changeable at the bottom of the editor.

If you need to do any editing outside the basic editor, there is an import/export feature, but you should keep in mind that the block sizes do affect how the program is interpreted. Make sure everything is the correct size by setting the codel sizes when importing/exporting.

Using the Interpreter

When it's time to run the program, just click the switch to change into interpreter mode.

Interpreter mode running the above hello world program with the tracer shown.

Interpreter mode with the tracer shown.

The interpreter lets you run or step through the program and shows the pointer (border-highlighted in blue around the current codel), commands, and stack during runtime. With the Draw Tracer mode enabled, the interpreter will also draw lines of the path it takes along the blocks of codels.

When using input, the interpreter will look in the input box first for characters. If there are no characters when the input command is run, then it will give an input prompt. If the input prompt is cancelled, or the input box reaches the end and EOF at end of input is checked, then the next input character will be a null character (0x00).