Special offer: Maintainable Software Worksheet and free 30-minute consultation! Download

Explore Mandelbrot fractals in your terminal

by Leon Miller-Out

Last night I wrote this fun code to see if I could display a Mandelbrot fractal in my terminal. It was easier than I thought, thanks to some pseudo-code on the Mandelbrot Set Wikipedia page, although tracking down the proper UTF-8 code for the Full Block character did take some time.

Tonight I added keyboard navigation so you can move and zoom through the fractal. This is written in Ruby 1.9 using only core features (no gems or even stdlib)! If you're going to play with it, make sure you turn on the "Use bright colors for bold text" option in your Terminal preferences for full 16-color glory :-)

Here's the initial view in my standard-sized terminal:

Screen Shot 2012 06 19 At 9.32.17 Pm

And here's a nice zoomed-in view:

Screen Shot 2012 06 19 At 9.33.49 Pm

The code will detect the size of your terminal window, so you can use a big window with a really small font to get a pretty high resolution fractal:

Screen Shot 2012 06 19 At 9.38.28 Pm

Here's the code: