Version 0 of ASCII Mandelbrot

Updated 2004-08-12 17:04:12

Inspired by the some very short lisp code (http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&c2coff=1&selm=ceef5p%24cch%241%40newsreader2.netcologne.de ) which itself is based on some Java code, I gave a 10 minute try to implement the mandelbrot set in the shortest amount of Tcl (one cheat: use tcllib):

 package require math::complexnumbers

 proc norm {c} { return [expr {pow([math::complexnumbers::real $c],2) + pow([math::complexnumbers::imag $c],2)}] }
 proc abs {c} { return [expr {sqrt([norm $c])}] }
 proc mandel {} {
    for {set y -1} {$y < 1.1} {set y [expr {$y + 0.1}]} {
        for {set x -2} {$x < 1.0} {set x [expr {$x + 0.04}]} {
            set c 126
            set z [math::complexnumbers::complex $x $y]
            set a $z
            while {([abs [set z [math::complexnumbers::+ [math::complexnumbers::* $z $z] $a]]] < 2) && ([incr c -1] > 32)} {}
            puts -nonewline [format %c $c]
        }
        puts ""
    }
 }
 mandel

This can be greatly improved on, so please do so! -- Todd Coram

See Mandelbrot for background on this fractal.