ASCII Sprites with Golang

August 29, 2016

I’ve been trying to think of a way to spruce up the Docker container which we print on all of the t-shirts for Dockercon.  At Dockercon 16 in Seattle we told everyone to run this command:

docker run -it --rm hello-seattle

That displays some data about how containers work from a really superficial level.  Somewhat useful for novices, I guess, but it doesn’t exactly have a ton of pizzazz.

When I first started working at Docker a year and half ago, I converted some of my ancient Pyweek video games which I’ve written to run from Docker containers.  These tend to be a lot more interesting, but getting them running from the command line can be a huge pain in the neck.  You have to pass in the X11 socket, give it access to the sound card and do all sorts of nastiness which I wouldn’t want to print on the back of a t-shirt. This would be fine if the docker engine had support for showing graphical style applications, but for now, I’ve ruled it out for a quick and dirty demo.

Instead, I’ve been thinking about the limitations of ASCII and have been wondering if there were a way to use it with typical gaming primitives like sprites.  I wanted to keep the size of the container image really small, so that ruled out writing anything in python where I’d have to package up the interpreter.  Instead I went with a statically compiled golang application which meant it could live by itself inside of a container.

I’m not actually finished yet, but I managed to cobble together a bit of a demo.  It just bounces around a bunch of ASCII Docker whales, but even that is a step up from the old container.  Here’s a screenshot:

You can give it a try with this command:

docker run -it --rm pdevine/whale-test

Use ‘a’ to add more whales, and ‘z’ to take them away.  ‘q’ will quit out of the program.  Oh yeah, and I guess it goes without saying that you need Docker to run it.  I would imagine it works just fine with Docker for Mac and Docker for Windows, but I haven’t tried them out.

Anyway, it’s a start.  I did run in to some interesting problems writing it which maybe I’ll write up in a future post.