Icon ASCII : A Love Letter


Icon My Neural Network isn't working! What should I do?


Icon Phase-Functioned Neural Networks for Character Control


Icon 17 Line Markov Chain


Icon 14 Character Random Number Generator


Icon Simple Two Joint IK


Icon Generating Icons with Pixel Sorting


Icon Neural Network Ambient Occlusion


Icon Three Short Stories about the East Coast Main Line


Icon The New Alphabet


Icon "The Color Munifni Exists"


Icon A Deep Learning Framework For Character Motion Synthesis and Editing


Icon The Halting Problem and The Moral Arbitrator


Icon The Witness


Icon Four Seasons Crisp Omelette


Icon At the Bottom of the Elevator


Icon Tracing Functions in Python


Icon Still Things and Moving Things


Icon water.cpp


Icon Making Poetry in Piet


Icon Learning Motion Manifolds with Convolutional Autoencoders


Icon Learning an Inverse Rig Mapping for Character Animation


Icon Infinity Doesn't Exist


Icon Polyconf


Icon Raleigh


Icon The Skagerrak


Icon Printing a Stack Trace with MinGW


Icon The Border Pines


Icon You could have invented Parser Combinators


Icon Ready for the Fight


Icon Earthbound


Icon Turing Drawings


Icon Lost Child Announcement


Icon Shelter


Icon Data Science, how hard can it be?


Icon Denki Furo


Icon In Defence of the Unitype


Icon Maya Velocity Node


Icon Sandy Denny


Icon What type of Machine is the C Preprocessor?


Icon Which AI is more human?


Icon Gone Home


Icon Thoughts on Japan


Icon Can Computers Think?


Icon Counting Sheep & Infinity


Icon How Nature Builds Computers


Icon Painkillers


Icon Correct Box Sphere Intersection


Icon Avoiding Shader Conditionals


Icon Writing Portable OpenGL


Icon The Only Cable Car in Ireland


Icon Is the C Preprocessor Turing Complete?


Icon The aesthetics of code


Icon Issues with SDL on iOS and Android


Icon How I learned to stop worrying and love statistics


Icon PyMark


Icon AutoC Tools


Icon Scripting xNormal with Python


Icon Six Myths About Ray Tracing


Icon The Web Giants Will Fall


Icon PyAutoC


Icon The Pirate Song


Icon Dear Esther


Icon Unsharp Anti Aliasing


Icon The First Boy


Icon Parallel programming isn't hard, optimisation is.


Icon Skyrim


Icon Recognizing a language is solving a problem


Icon Could an animal learn to program?




Icon Pure Depth SSAO


Icon Synchronized in Python


Icon 3d Printing


Icon Real Time Graphics is Virtual Reality


Icon Painting Style Renderer


Icon A very hard problem


Icon Indie Development vs Modding


Icon Corange


Icon 3ds Max PLY Exporter


Icon A Case for the Technical Artist


Icon Enums


Icon Scorpions have won evolution


Icon Dirt and Ashes


Icon Lazy Python


Icon Subdivision Modelling


Icon The Owl


Icon Mouse Traps


Icon Updated Art Reel


Icon Tech Reel


Icon Graphics Aren't the Enemy


Icon On Being A Games Artist


Icon The Bluebird


Icon Everything2


Icon Duck Engine


Icon Boarding Preview


Icon Sailing Preview


Icon Exodus Village Flyover


Icon Art Reel




Icon One Cat Just Leads To Another

Making Poetry in Piet

Created on Oct. 12, 2015, 4:28 p.m.

I'm a big fan of anything that makes programming weird and interesting so I was excited when I found Source Code Poetry, a competition that runs each year, and asks contestants to submit poetry written in compilable Java, C++ or C#. I've entered the main competition for the last couple of years, but this year there was a separate prize for the best poem that broke the rules in a way that was cool, interesting or poetic.

I started to think about this second challenge. My immediate idea was to use some kind of esoteric programming language and the first one that came to mind was Piet, a language which takes images as input. Here are some scaled up sample programs people have made in Piet. This meant my entry was going to be a picture!

piet0 piet1 piet3

The Piet interpreter works by moving a cursor (which starts in the top left) between blocks of colour. Depending on the sizes of the blocks, and the different colours of the blocks, different operations are performed.

As you probably guessed programming in Piet is not easy. I found myself repeatedly misunderstanding how it works, expecting it to be like a 2D turing machine. Instead the cursor exits the blocks of color at the topmost or bottommost corners. For complex shapes this means it can really get confusing as the cursor jumps around to some weird places.

After playing around a little and getting to know the mechanics I knew I would need to do a simple program, and probably a short program, so I decided to write a program which output a haiku I'd written. The twist was that I was going to try and make it look like an image of tree bark.

Bark Stage 0

I started crafting the program by hand but realized doing so would take years - so I came up with an approach which combined some automatic generation of the program and some custom editing by hand to get the exact look I wanted. I started by writing a Python script which generated a Piet program that output a given string. I set the string to be my haiku and the script generated a Piet program which looked like the image on the right.

Each pink block represents outputting a character of the poem. To output a particular character in Piet requires the cursor passing through a block of colour with the same number of pixels as the ascii code of the character. The white lines are the "wires" which the cursor travels along, with a little bit of Piet machinery at the corners for turning the cursor to the right direction.

Once I had this image, I already had a program that outputted the poem - so the challenge now was to adapt this program to look like a certain image without changing the functionality.

To start I found an image of what I wanted the final poem to look like - in this case an image of some bark by flikr user Syed Shuvra. I then cropped, resized, adjusted the contrast, and converted this image into the pallet of colors used by Piet. This was done in photoshop. I then put my generate Piet program in front of this background image. This filled in all the pixels not involved in the computation.

Bark Stage 1 Bark Stage 2 Bark Stage 3

But the major issue was the big pink squares completely blocking the image behind. Luckily Piet operations work by taking the difference in brightness and/or hue when moving between two colours - which means we can, to some degree, pick what colours we use for the different blocks.

So I generated a new program using the most common colour in each segment of the reference image to decide what colour to use for the different blocks of ascii characters. This looked much better but still didn't look like bark.

Then the hard work started. By hand I blended each block into the background image. To make sure I didn't change the functionality of the program I had to ensure the block kept the same number of pixels, didn't blend with any other functional blocks, and that the top right corner stayed the same. Other than that it could be almost any shape. I tried to make each block fit into the surrounding image by merging it with similar blocks.

In the end you can still see some of the "wires", and if you compare it to the reference image you can see how some of the edges of the bark are bulked out in the same colour but overall I was pleased with the results. The whole process took quite a few hours of clicking away in photoshop. On the right you can see the final product.

Bark Stage 4 Bark Stage 5 Bark

And here is a scaled up version to see the details. Be warned that this image wont work in Piet since scaling changes the meaning.

Bark Large

The "wires" are still visible - they are very hard to get rid of because they must not be black as the black areas in Piet are areas the cursor cannot move. Additionally lots of the colours are bulked out quite a lot more than in the reference image because the ascii blocks are over black areas or similar issues. Finally it was impossible for me to move the "Piet machinery" which turns the cursor to a new direction. This part was just a little fiddly and had to remain as it. But overall I think the effect is pretty convincing, and the blending worked well.

If you want to find out what the haiku I wrote it is you'll have to run the program yourself!

I hope I've inspired some more of you to write some source code poetry, and let's hope that next year's entries will be even more fun and interesting than this years. I look forward to seeing what everyone can come up with.

github twitter rss