Piet - Esolang (original) (raw)

“Hello World” in Piet.

Piet is a stack-based esoteric programming language in which programs look like abstract paintings. It uses 20 colors, of which 18 are related cyclically through a lightness cycle and a hue cycle. A single stack is used for data storage, together with some unusual operations.

Piet was invented by David Morgan-Mar and is named after geometric abstract art pioneer Piet Mondrian.

Computational class

If the interpreter for Piet allows for an arbitrarily large stack with each item holding an arbitrarily large number, then Piet is Turing-complete. In addition, a brainfuck interpreter has been created in Piet, and since brainfuck is Turing-complete, Piet is also Turing-complete.

Execution

Codels

A codel in Piet is like an image's pixel. Some Piet programs are upscaled, meaning that a codel might not always be equivalent to 1 pixel, but a codel is always a substitute for pixels.

Color blocks

A color block is any group of codels of the same color that are adjacent to each other. Note that codels only touching each other diagonally are not considered part of the same color block; they must be touching in one if the 4 cardinal directions to be part of the same color block.

Direction pointer

The direction pointer (DP) is what moves along the program to make it run. It can be in any one of the 4 cardinal directions. The direction pointer always starts at the color block containing the upper-left-most codel, and always starts facing right. After it has executed the proper command, it will move on to the next color block that is both:

  1. adjacent to the current color block, and
  2. is the farthest in the direction of the DP.

This continues until the program terminates (see below).

Codel chooser

The codel chooser (CC) is used when multiple color blocks meet the above two criteria for the next block to be executed. Its direction is always relative to the DP's direction, and starts out facing left. When there are more than one possible color blocks to be executed, the one farthest in the direction of the codel chooser (again, relative to the DP) is the one chosen. The codel chooser can only point left or right.

Colors

Piet uses 20 colors in its programs. Each of these colors (with the exceptions of white and black) have two properties, those being hue and lightness. All colors and their properties are shown in the table below.

Colorful

Light red (#FFC0C0) Light yellow (#FFFFC0) Light green (#C0FFC0) Light cyan (#C0FFFF) Light blue (#C0C0FF) Light magenta (#FFC0FF)
Red (#FF0000) Yellow (#FFFF00) Green (#00FF00) Cyan (#00FFFF) Blue (#0000FF) Magenta (#FF00FF)
Dark red (#C00000) Dark yellow (#C0C000) Dark green (#00C000) Dark cyan (#00C0C0) Dark blue (#0000C0) Dark magenta (#C000C0)

Hue is shown going to the left and lightness is shown going down. Note that these properties are cycles, meaning that, in terms of hue, red comes after magenta. Hue always goes to the left, and lightness always goes down, meaning that going from yellow to red is 5 changes in hue, and vice versa.

White

White (#FFFFFF) is one of the two colors in Piet that doesn't fit into either cycle. White color blocks act like blank spaces. When the DP encounters a white block, it will simply go through it and move on to the next color block. No commands are executed when the DP goes through a white block.

Black

Black (#000000) is like the opposite of white in the sense that the DP cannot pass through it. If the DP tries to go to the next color block but fails because of a black block, it will switch the CC to its other state and try again. If it still can't get to the next color block, then the DP will be rotated one step clockwise. If the DP has gone through all possible states but it still can't get to the next color block, it will conclude there is no way out and the program will terminate. This is the only way to terminate a Piet program.

Commands

Piet commands aren't executed based on the color the DP is on, but instead based on the change in lightness and hue. Below is a table with all 17 commands in Piet and how they're executed.

Hue change Lightness change
No change 1 darker 2 darker
No change N/A Push Pop
1 step Add Subtract Multiply
2 steps Divide Modulo Not
3 steps Greater Pointer Switch
4 steps Duplicate Roll Input num
5 steps Input char Output num Output char

Examples

Examples are currently not available.

Notes

In 2022, a museum found out that it had a draft of a painting of Piet Mondrian hanging upside down. Unlike his finished artworks, the draft was not an oil painting, but made of colored strips of paper glued to a white canvas, so that Mondrian can experiment by moving them. Since the draft is mechanically fragile, the museum didn't reorient the piece.

The situation above is quite identical to the Piet language since it is almost invaried in case of turning programs upside down: the only time that the language notices is when it initializes the program counter. If a Piet program were found to somehow have turned upside down, you would not need to adjust its orientation. You'd just add a painted frame that initializes the program correctly, entering the bottom left codel through a white block with the direction set to left and the codel chooser set to left.

See also

External resources