Piet
Factoid
Piet is a programming language where the source code consists of images. Program flow starts with the top-left pixel and moves around the image between pixels and pixel groups until it terminates.
For legibility, Piet programs are commonly displayed in an enlarged version. In such a case the term codel
is used to describe a group of same-coloured pixels that correspond to an individual pixel in the source image.
For this challenge, since Piet does not use characters, one codel per vote will be used for sample programs.
1 Codel
This is a valid program, it does nothing and terminates. The control flow starts in the top-left (only) pixel and has no way out, which ends the program.
The pixel can in this case be any colour for the exact same effect.
2 Codels
This will continually read characters from stdin and keep a running total of their unicode values (though nothing is done with this total and it is not displayed).
The input is the command moving left-to-right and then the add is right-to-left. On the first "add" command, nothing will happen since there is only one value on the stack, and the specification says that commands without enough values available are ignored.
This program is a loop that will never end, as most piet programs will be at extremely small sizes, since it takes at least a few codels to properly "trap" the program flow and end it.
3 Codels
This is a basic echo-type program, it will read a character at a time from stdin and print it to stdout.
Again this is an infinite loop. When travelling back left-to-right it attempts to perform subtract and add commands, but the stack is empty so these become no-ops.
4 Codels
Prints out 2 to stdout indefinitely.
Not a particularly interesting program functionally, but now that we finally have a composite number of codels we can show off slightly more advanced flow than left-to-right. The program goes around clockwise pushing 1 onto the stack twice, adding them together, then outputting the result.
5 Codels
Repeatedly reads a character at a time from stdin and tracks the sum of their unicode values.
This is essentially the same functionality as the 2-codel version, but this challenge is about showcasing the language, and one of the cool things about piet is how you can have different-looking pictures that do the same thing.
Here we see the white codel for the first time, which allows program flow to slide across it without executing instructions. The magenta and blue codels do all the work here, the 2 red ones just push the number 1 onto the stack and pop it back off.