The code was golfed down to 140 bytes during JSConf EU 2011, inspired by a slide from Jed Schmidt's talk:
Credits go to @sylvinus who came up with the idea and the original code as well as @p01 and Jacob Seidelin who pioneered tweet-sized ASCII art fractals back in 2008.
Instead of drawing onto a canvas, the gist uses █ characters (U+2588) with a font-size of 1px. In order to make this work, the target DIV must have the following styles:
font-size:1px;
line-height:1px;
width:300px;
word-wrap:break-word;
To support Firefox on OSX, we also have to set a font in which the FULL BLOCK character is exactly 1em wide. Helvetica works well here. All other browsers, including Firefox on Windows and even IE6 don't care about the font. But be warned, it takes a while in old IEs to render the 90000 font tags.
Besides the use of String.prototype.fontcolor()
this gist features some other nifty tricks, like using bitmasks and exploiting the
parsing rules for
legacy color values which are all documented in the annotated version.
If you want to learn more about the Mandelbrot set itself, check out the this comprehensive tutorial.
And here is a jsFiddle to play with.
@p01 About saving the five bytes: I actually added this feature to pack as much functionality as possible into the available space. But I'd happily sacrifice it for a cooler feature if we could fill up the whole 140 bytes!
BTW, adding a
>
sign to the end of your 111b version would restore FF support. And by replacing the literal 0x1F linebreak with\n
it would work in even more browsers. Two bytes extra for cross-browser support doesn't sound like a bad deal.