Piet (programming language)
Piet is an esoteric programming language designed by David Morgan-Mar, whose programs are bitmaps that look like abstract art. Piet was named after the Dutch painter Piet Mondrian.
Computational class
If the stack is allowed to hold any arbitrarily long number then it's very likely Turing-complete. There's no formal proof though.
Sketch of a proof for TC: The rotate operation makes every stack position directly accessible, thus making the stack usable as a register bank. It's enough for TC to have two unlimited-size registers and be able to do certain simple operations with them, as stated in the Minsky machine article. Writing Piet programs is straightforward enough as to make it possible to program the finite-state automaton needed to simulate an universal Turing machine.
Colours
Piet uses 20 distinct colours, as shown in the table at right. The 18 colours in the first 3 rows of the table are related cyclically in the following two ways:
* Hue Cycle: red -> yellow -> green -> cyan -> blue -> magenta -> red * Lightness Cycle: light -> normal -> dark -> light
Note that "light" is considered to be one step "darker" than "dark", and vice versa. White and black do not fall into either cycle.
Additional colours (such as orange, brown) may be used, though their effect is implementation-dependent. In the simplest case, non-standard colours are treated by the language interpreter as the same as white, so may be used freely wherever white is used. (Another possibility is that they are treated the same as black.)
Codels
Piet code takes the form of graphics made up of the recognised colours. Individual pixels of colour are significant in the language, so it is common for programs to be enlarged for viewing so that the details are easily visible. In such enlarged programs, the term "codel" is used to mean a block of colour equivalent to a single pixel of code, to avoid confusion with the actual pixels of the enlarged graphic, of which many may make up one codel. Colour Blocks The basic unit of Piet code is the colour block. A colour block is a contiguous block of any number of codels of one colour, bounded by blocks of other colours or by the edge of the program graphic. Blocks of colour adjacent only diagonally are not considered contiguous. A colour block may be any shape and may have "holes" of other colours inside it, which are not considered part of the block.
Stack
Piet uses a stack for storage of all data values. Data values exist only as integers, though they may be read in or printed as Unicode character values with appropriate commands.
Execution
The Piet language interpreter begins executing a program in the colour block which includes the upper left codel of the program. The interpreter maintains a Direction Pointer (DP), initially pointing to the right. The DP may point either right, left, down or up. The interpreter also maintains a Codel Chooser (CC), initially pointing left. The CC may point either left or right. The directions of the DP and CC will often change during program execution.
As it executes the program, the interpreter traverses the colour blocks of the program under the following rules:
1. The interpreter finds the edge of the current colour block which is furthest in the direction of the DP. (This edge may be disjoint if the block is of a complex shape.) 2. The interpreter finds the codel of the current colour block on that edge which is furthest to the CC's direction of the DP's direction of travel. (Visualise this as standing on the program and walking in the direction of the DP) 3. The interpreter travels from that codel into the colour block containing the codel immediately in the direction of the DP.
The interpreter continues doing this until the program terminates.
External links
- Piet programming language
- Piet on the esolangs wiki
- A Piet program with detailed explanation
- A Piet program that looks like a painting of Piet Mondrian
- Piet::Interpreter - An interpreter for Piet written in Perl
- npiet - An interpreter and editor for Piet
- PietDev - An online Piet editor and debugger
- 99 bottles of beer on the wall