User:Kkorb/sandbox
Paradigm | Esoteric, Imperative, Scalar, Value-level, Stack-oriented |
---|---|
Designed by | David Morgan-Mar |
Typing discipline | Untyped |
Filename extensions | .png, .gif, .ppm |
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.
white #FFFFFF | black #000000 | ||||
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 |
Colors
[edit]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
[edit]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.[1]
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.[2]
Codel Color Evaluation
[edit]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.
darkness change | |||
---|---|---|---|
Hue change | None | 1 Darker | 2 Darker |
None | push | pop | |
1 Step | add | subtract | multiply |
2 Steps | divide | mod | not |
3 Steps | greater | pointer | switch |
4 Steps | duplicate | roll | in(number) |
5 Steps | in(char) | out(number) | out(char) |
Commands
[edit]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
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)[3] to Piet.
Example Programs
[edit]This very simple linear Hello World Program uses only two commands, push, and out (char). The varying height codels represent each of the character ASCII codes in "Hello, World!". The first codel consists of 72 pixels, which is the ASCII code for 'H'. The next codel is the same color, but 1 lightness step different, this results in the signed integer 72 being pushed to the stack. The next codel is cyan and 2 lightness steps different, resulting in the first value on the stack to be output as a character, printing out 'H'. This continues till the Direction Pointer reaches the black codel at the top right. Here it alternates changing its Direction Pointer and Codel Chooser 8 times which all result on a black codel, to terminate the program. | |
This is an example of a much more complex Hello World Program that focuses on making its code small, symmetric, and no color appearing twice. It heavily uses the stack to add and multiply its way to each of the ASCII values. This is done by circling around like a spiral. The execution begins going right along the top, then down the right edge, left across the bottom, and up the left side before repeating. Each time getting closer to the middle where it ends in the black circle. At each of the corners it uses a push and pointer command, which pushes the previous codel block size onto the stack (always 1) and rotates the Direction Pointer that many times clockwise. |
References
[edit]This is a user sandbox of Kkorb. You can use it for testing or practicing edits. This is not the sandbox where you should draft your assigned article for a dashboard.wikiedu.org course. To find the right sandbox for your assignment, visit your Dashboard course page and follow the Sandbox Draft link for your assigned article in the My Articles section. |
- ^ "DM's Esoteric Programming Languages - Piet". www.dangermouse.net. Retrieved 2017-03-18.
- ^ LLC, Revolvy,. ""Piet (programming language)" on Revolvy.com". www.revolvy.com. Retrieved 2017-03-18.
{{cite web}}
: CS1 maint: extra punctuation (link) CS1 maint: multiple names: authors list (link) - ^ "foogol / cfoogol". www.bertnase.de. Retrieved 2017-03-24.
- ^ http://progopedia.com/user/Nickolas/. "Programming language Piet". progopedia.com. Retrieved 2017-03-21.
{{cite web}}
:|last=
has generic name (help); External link in
(help)|last=
- ^ Schoch, Thomas. ""Hello, world!" in Piet". www.retas.de. Retrieved 2017-03-21.