User:Kkorb/sandbox

Piet is one of many esoteric programming languages invented by David Morgan-Mar and is named after the Dutch abstract painter Piet Mondrian, as Mondrian had already been taken.

Piet was designed to have its source code appear as abstract art, where pixels are interpreted instead of code. Piet recognizes a total of 20 colors to implement its instruction set.

Colors
Of the 20 colors recognized by Piet 6 are hues that are kept in a strict order. Each of these 6 hues have a lighter and darker variant making a total of 18 colors. The last two being white and black. Most commonly interpreters will treat any color aside from these 20 as white.

Since Piet interprets an image pixel by pixel, example source code is often enlarged so the developer can easily pick out mistakes. Blocks of adjacent pixels with the same colors are called Codels, which are interpreted together. Codels are often used to represent numbers or ASCII codes.

Program Execution
Piet uses a Direction Pointer and Codel Chooser in order to determine the flow of execution when traversing the image. The Direction Pointer by default points to the right, but can be changed to any of the four directions: up, down, left or right. The Direction Pointer dictates the direction in which the code is executed, while the Codel Chooser chooses the codel to interpret. The Codel Chooser by default points left from the point of view of the Direction Pointer and can be either left or right.

By default, program execution begins in the top left corner and travels to the right, picking the uppermost codel, as from the Direction Pointer's point of view, left is up. Once the codel is picked the color is evaluated.

Piet uses a stack to store variables which are restricted as signed integers. All commands are either performed on the stack, deal with input/output or affect the Direction Pointer/Codel Chooser rules.

Codel Color Evaluation
Black is used to mark the edges of the program, so when encountered the Codel Chooser is flipped. If the current codel is still black, then the Direction Pointer is turned clockwise. These two steps are alternated till a non-black codel is found, if none are found in 8 steps the program is terminated.

Any of the 18 recognized colors by themselves do not mean much, whereas the difference between the lightness and the steps between the hues determines the command.

White is ignored as the program passes through it when finding the next codel. Any other colors are most commonly interpreted as white, while sometimes treated as black depending on the interpreter.

Commands
In total there are 15 unique commands that are determined by comparing the differences between 2 codels. The first difference being the change in brightness, with 3 levels of brightness and always going from light to dark, there are 3 possibilities. The first case being no change, the second, that it is one level darker and the last, two levels darker.

Lightness Cycle: light -> normal -> dark -> light again

The second difference taken into account is the change in hue. With the strict sequence of the 6 hues, the change in hues or steps between them is the other part in determining the command. For example going from blue to green would result in 4 steps.

Hue Cycle: red -> yellow -> green -> cyan -> blue -> magenta -> red again

Integrated Development Environment and Interpreters
There are many Piet IDE's and Interpreters, but because the language is quite small and simple, the most popular combination of these are web-based. Two of the popular web-based IDE's are Rapapaing's IDE and Zobier's IDE. These are both are very similar, with grids to write the program and debugging controls. The most popular and well known Piet IDE is npiet, which has three main downloadable utilities: an IDE, an Interpreter, and a translator from foogol (a very small ALGOL) to Piet.