Julia set: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl 6}}: use complex numbers: performance improvement of ~4x)
(Added Julia)
Line 86: Line 86:
}
}
}</lang>
}</lang>

=={{header|Julia}}==
[[File:JuliaSet_julia.png|250px|thumb|right]]
<lang julia>using Images

w, h = 800, 600
img = Array(UInt8, h, w, 3)

maxIter = 50
c = -0.8+0.156im

function hsv2rgb(h, s, v)
c = v * s
x = c * (1 - abs(((h/60) % 2) - 1))
m = v - c

r,g,b =
if h < 60
(c, x, 0)
elseif h < 120
(x, c, 0)
elseif h < 180
(0, c, x)
elseif h < 240
(0, x, c)
elseif h < 300
(x, 0, c)
else
(c, 0, x)
end

r = round(UInt8, (r + m) * 255)
g = round(UInt8, (g + m) * 255)
b = round(UInt8, (b + m) * 255)

b,g,r
end

for x in 1:w
for y in 1:h
i = maxIter
z = Complex((x - w/2) / w * 3, (y - h/2) / h * 2)
while abs(z) < 2 && (i -= 1) > 0
z = z*z + c
end
r,g,b = hsv2rgb(i / maxIter * 360, 1, i > 1 ? 1 : 0)
img[y,x,1] = r
img[y,x,2] = g
img[y,x,3] = b
end
end

save("JuliaSet.png", colorim(img, "RGB"))</lang>


=={{header|Perl}}==
=={{header|Perl}}==