Draw your program with Piet

Marina Kolesnichenko
3 min readMar 26, 2021

Piet is an esoteric visual programming language. Programs on Piet look like beautiful examples of abstract art. The language is named after Piet Mondrian, who pioneered the field of geometric abstract art.

Tower of Hanoi

The interesting this about Piet programs is — the same program could be written in different ways. Example of two ‘Hello world’ programs.

Hello, world!

Looks interesting, right? But how to write your own program? I’ll tell you the shortest and easiest way how to do this.

What we usually open when start programming? Right, our IDE’s. Pretty common is JetBrains, VS Code, Visual Studio and a lot of other great IDE’s. But here will be something new for you. We’ll use the Paint, yeah default program Paint on Windows. Or any other program for drawing what do you prefer. Did you even write a program in Adobe Photoshop? :)

So, let’s start with our colours pallet. Piet programs contain only these colours (6 hues * 3 lightness levels, black and white colours).

Colours pallet

As the Piet interpreter moves around the image, each relative transition between colours produces the command.

There are so many ways to produce the same command. Two Piet programs can be functionally-equivalent but look very different.
Do you remember two examples of ‘Hello world’? They are doing the same thing but looks different. Let’s make our own example, but by using a minimum colour pallet. I like the red colour, so will use it.

First the all, what means ‘H’ in ‘Hello world’? Piet is a low-level programming language. So, we need the ASCII table to take the right value for it.

ASCII table

Our ‘H’ means 72, that's the number of pixels that we need to draw. The layer params are:

This means the value pushed is the number of pixels in the block — 72. By this push, we added the ‘H’ letter. But how to see the output? We need to use a magenta colour. Our phrase contains the next letters:

H — 72, e — 101, l — 108, o — 111, space — 32, w — 119, r — 114, d-100, ! — 33

What we will have after putting these lines of pixels.

Our Hello world!

The black colour here like the barrier to not allow Piet to take another colour or go to a different flow.

How to run it? I can suggest a good online interpreter for Piet: here Or you can download any Python interpreter.

Looking forward to seeing more Piet examples. Hope you’ll like Piet! 😉