
Task
Generate and draw a Julia set.




Related tasks
   Mandelbrot Set


require('Imager')
 
var (w, h) = (640, 480)
var img = %s'Imager'.new(xsize => w, ysize => h, channels => 3)
 
var maxIter = 50
var c = Complex(-0.388, 0.613)
 
var color = %s'Imager::Color'.new('#000000')
 
for x,y in (^w ~X ^h) {
    var i = maxIter
    var z = Complex((x - w/2) / w * 3, (y - h/2) / h * 2)
    while (z.abs < 2 && --i) {
        z = (z*z + c)
    }
    color.set(hsv => [i / maxIter * 360, 1, i])
    img.setpixel(x => x, y => y, color => color)
}
 
img.write(file => "JuliaSet_sidef.png")