> For the complete documentation index, see [llms.txt](https://cajac.gitbook.io/ctf-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cajac.gitbook.io/ctf-notes/prog/other-languages/piet.md).

# Piet

Piet is a language designed by [David Morgan-Mar](https://en.wikipedia.org/wiki/David_Morgan-Mar), whose programs are [bitmaps](https://en.wikipedia.org/wiki/Bitmap) that look like [abstract art](https://en.wikipedia.org/wiki/Abstract_art). The execution is guided by a "pointer" that moves around the image, from one continuous coloured region to the next. Procedures are carried out when the pointer exits a region.

There are 20 colours for which behaviour is specified: 18 "colourful" colours, which are ordered by a 6-step hue cycle and a 3-step brightness cycle; and black and white, which are not ordered. When exiting a "colourful" colour and entering another one, the performed procedure is determined by the number of steps of change in hue and brightness. Black cannot be entered; when the pointer tries to enter a black region, the rules of choosing the next block are changed instead. If all possible rules are tried, the program terminates. Regions outside the borders of the image are also treated as black. White does not perform operations, but allows the pointer to "pass through". The behaviour of colours other than the 20 specified is left to the compiler or interpreter.

## Example Code

<figure><img src="https://1587471879-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQXR5fXxk8kNo5GmU617i%2Fuploads%2FfPtH4ubf15LjIiQ5PKTw%2FPiet_Program.gif?alt=media&amp;token=2b228ec1-92a1-412d-a54e-d86381226ec0" alt=""><figcaption><p>Piet program that prints 'Piet'</p></figcaption></figure>

<figure><img src="https://1587471879-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQXR5fXxk8kNo5GmU617i%2Fuploads%2FjchnXTDRqiB5oLwAjeTt%2FPiet_Program_Hello_World.gif?alt=media&amp;token=b5a27a37-94b0-4f17-bba6-46bbf5890b9f" alt=""><figcaption><p>A "Hello World" program in Piet</p></figcaption></figure>

## Online Services

You can use one of these online services to decode/execute Piet code:

bertnase.de: <https://www.bertnase.de/npiet/npiet-execute.php>

bubbler.one: <https://piet.bubbler.one/>

## Resources

Piet - Esolang: <https://esolangs.org/wiki/Piet>

Piet - Wikipedia: <https://en.wikipedia.org/wiki/Esoteric_programming_language#Piet>
