Inspiration

We as a team are driven almost exclusively by curiosity, and so naturally we found ourselves drawn to Piet. Piet is considered an 'esoteric' programming language by way of it's unusual design: it is written exclusively as png files. The language operates by starting at the top left pixel of the image and then begins walking a path defined by the pixels directly adjacent to the program's current position, executing instructions along the way.

Our goal was to write a human-readable language from scratch that compiles into png files that can be executed by Piet---because why not!

What it does

PietC stands for "Piet Compiler" and it's job is to take a high-level script written by the user and compile that script as a png file that is compliant with the Piet interpreter. As a result, we are able to allow our users to convert the logic of their programs into modern art rather than have it the other way around.

How we built it

As we mentioned above, we wrote all of this from scratch (excluding the Piet interpreter of course). We used Python as our language of choice given it's robust execution, it's broad available modules, and the efficiency of it's syntax to ensure our development time could be made as short as possible.

In particular, we used the module PLY (by David M. Beazley) to parse the user's source file using our own defined grammar and syntax, and we used PIL to manipulate the output png file. From here, we have written hooks for each form of statement available to the PietC programmer that directly correspond to small snippets of pixels that perform our desired functionality. Using these snippets we build the resulting png file bit by bit.

Challenges we ran into

It turns out that there is an unreasonable amount of logistics involved in making sure that snippets can properly communicate without the risk of having our program overwrite any of the busing that is required to have the program appropriately jump to different segments of code.

Furthermore, defining a language is itself a tough matter of organization. A language, in order to be unambiguous, flexible, and functional, requires layers of recursion which can be tedious to write and difficult to debug.

Lastly, as a team we had to ensure that each side of the project, the pixel generation and the language parsing, met up at a middle point that guarantees each statement of our language can be reliably converted to the unusual structures used by Piet.

Accomplishments that we're proud of

We actually have something that works! The photo you see above is our proof.

What we learned

This project was definitely a challenge by it's design, and our coordination was an enjoyable process to undergo. As a result of our time this weekend, we have learned to write a compiler from the ground up and process data in a way that is far removed from anything we have experienced in our courses.

What's next for PietC

Piet programs aren't unique! There are many different ways to write the same programs in Piet, and one idea that we have shared among ourselves is the possibility of providing a way for a user to go back and "push" the pixels that we generate around so that they can design a more aesthetically pleasing Piet program without any loss to it's functionality.

Built With

Share this project:

Updates