Code Circles

Long story short: I wrote a program that turns other programs into cool looking circles. Every image on this page is actually a piece of Lisp code. I call them “Magic” Code Circles because they were originally inspired by the magic rune circles that show up in a lot of fantasy games.

My technique is pretty straightforward. I use colors to represent ascii symbols and use nested circles to represent code structure. The program itself is written in C# using the .NET image library. I chose to focus on turning Lisp code into circles because Lisp has a very simple syntax that makes it relatively easy to parse.

To be fair the program isn’t quite perfect yet. It can’t handle any of Lisp’s special built-in functions, doesn’t properly show the difference between a symbol and a function call and there is no way to tell how many character segments are inside of a monochrome circle. I plan to fix these flaws by adding some meta-symbols to each circle at some future date.

Here is the current code if you want to make your own code circles. Be warned that it’s still a little fragile so don’t be surprised if it can’t handle every input string you pass.

Sample Code Circles

Exit Circle

exit

Here we have just about the simplest Lisp program possible. A single function call to exit the code interpreter

(exit)

Notice that it is just a single circle with four colored segments. Each color represents a different letter and together they spell out “exit”.

Hello Circle

helloworld

Here we have the second simplest Lisp program, the traditional “Hello World”. A function call with a single argument

(print "Hello World")

Notice that the outer cirlce, which spells out “print”, now has a smaller circle inside it that spells out “Hello World” The outer circle represents the function call, the inner cirlce reperesents its arguments

Simple Addition Circle

+19

Let’s add another argument and do some math

(+ 1 9)

Now we have a big outer circle whose color translates to “+” and two inner cirlces that spell out “1” and “9”. The top circle is the first argument and the lower circle is the second.

Triple Multiplication Circle

mult258

Let’s crank it up to 3 arguments and switch to multiplication

(* 2 5 8)

Just like before we have a big circle meaning “*” and then three inner circles representing the arguments of 2, 5 and 8. The top circle is still the first argument and you then move clockwise to find the second and third.

Big List Circle

list

And just for fun let’s have 8 arguments. We’ll use the “list” function which just creates a big list of all its arguments

(list A 1 b 2 C 3 d 4)

I’m sure you can see how it works by now. Big circle spells out the function name “list” and the smaller circles spell out the arguments, starting at the top and then proceeding clockwise.

Nested Math Circle

multadd

Like all good languages, Lisp allows you to nest function calls inside of function calls. So here we have a function where first we add together 1 and 5 and then multiply by 3

(* (+ 1 5) 3)

As you can see this nested function call adds a new layer of circles to the code circles. We still have a big outer circle that represents “*”. The first inner circle is no longer just a simple circle, but instead represents “+” and has two inner circles representing 1 and 5.

Very Nested Math Circle

nestedmath

And of course you can nest more functions inside of the nested functions, like so

(+ (* 2 (/ 6 3)) (- 5 2) 9)

Factorial Circle

smallfactorial

This one is a complete Lisp function: a recursive factorial.

(defun factorial (num)
    (if (eq 1 num)
      1
      (* num (factorial (- num 1)))))

This is a pretty short, simple function but the circle is already getting complicated enough that it’s difficult to see the smaller circles or make out the colors that went into them. For really complicated circles a high resolution image is required in order to see all the details.