Julia set: Difference between revisions

Content added Content deleted
(Kotlin entry)
m (→‎{{header|Julia}}: code simplifications)
Line 602: Line 602:
<lang julia>using Images
<lang julia>using Images


w, h = 800, 600
const w, h = 800, 600
img = Array(UInt8, h, w, 3)
const img = Array(RGB{Float64}, h, w)


maxIter = 50
const maxIter = 50
c = -0.8+0.156im
const c = -0.8+0.156im


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


r,g,b =
const r,g,b =
if h < 60
if h < 60
(c, x, 0)
(c, x, 0)
Line 628: Line 628:
end
end


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

b,g,r
end
end


Line 643: Line 639:
end
end
r,g,b = hsv2rgb(i / maxIter * 360, 1, i > 1 ? 1 : 0)
r,g,b = hsv2rgb(i / maxIter * 360, 1, i > 1 ? 1 : 0)
img[y,x,1] = r
img[y,x] = RGB{Float64}(r, g, b)
img[y,x,2] = g
img[y,x,3] = b
end
end
end
end


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


=={{header|Kotlin}}==
=={{header|Kotlin}}==