#!/usr/bin/ruby

#
## http://rosettacode.org/wiki/Julia_set
#

var (w, h) = (80, 30)

var maxIter = 40
var c = Complex(-0.8, 0.156)

for y in ^h {
    for x in ^w {
        var i = maxIter
        var z = Complex(3 * (x - w/2) / w, 2 * (y - h/2) / h)
        while (z.abs < 2 && --i) {
            z = (z*z + c)
        }
        print (i > 0 ? ' ' : '#')
    }
    print "\n"
}
