Mandelbrot set: Difference between revisions

→‎{{header|Julia}}: Translation from Python: Normalized Iteration Count, Distance Estimation and Mercator Maps
(→‎{{header|Julia}}: Translation from Python: Normalized Iteration Count, Distance Estimation and Mercator Maps)
Line 5,179:
img = mandelbrot()
save("mandelbrot.png", img)</lang>
 
===Normalized Iteration Count, Distance Estimation and Mercator Maps===
This is just a translation of the corresponding Python section.
<lang julia>using GR
 
d, h = 800, 600 # pixel density (= image width) and image height
n, r = 200, 500 # number of iterations and escape radius (r > 2)
 
x = range(0, 2, length=d+1)
y = range(0, 2 * h / d, length=h+1)
 
A, B = (x .- 1)' .* ones(h + 1), ones(d + 1)' .* (y .- h / d)
C = 2.0 * (A + B * im) .- 0.5
 
Z, dZ = zero(C), zero(C)
T, D = zeros(size(C)), zeros(size(C))
 
for k = 1:n
M = abs.(Z) .< r
Z[M], dZ[M] = Z[M] .^ 2 + C[M], 2 * Z[M] .* dZ[M] .+ 1
T[M] = T[M] .+ 1
end
 
imshow(T .^ 0.1, colormap=21)
savefig("Mandelbrot_set_1.png", colormap=21)
 
N = abs.(Z) .> r # normalized iteration count
T[N] = T[N] - log2.(log.(abs.(Z[N])) / log(r))
 
imshow(T .^ 0.1, colormap=21)
savefig("Mandelbrot_set_2.png", colormap=21)
 
N = abs.(Z) .> 2 # exterior distance estimation
D[N] = 0.5 * log.(abs.(Z[N])) .* abs.(Z[N]) ./ abs.(dZ[N])
 
imshow(D .^ 0.1, colormap=21)
savefig("Mandelbrot_set_3.png", colormap=21)</lang>
 
A small change in the above code allows Mercator maps of the Mandelbrot set.
<lang julia>using GR
 
d, h = 400, 2200 # pixel density (= image width) and image height
n, r = 800, 1000 # number of iterations and escape radius (r > 2)
 
x = range(0, 2, length=d+1)
y = range(0, 2 * h / d, length=h+1)
 
A, B = (x * pi)' .* ones(h + 1), ones(d + 1)' .* (y * pi)
C = 2.0 * exp.((A + B * im) * im) .- 0.74366367740001 .+ 0.131863214401 * im
 
Z, dZ = zero(C), zero(C)
T, D = zeros(size(C)), zeros(size(C))
 
for k = 1:n
M = abs.(Z) .< r
Z[M], dZ[M] = Z[M] .^ 2 + C[M], 2 * Z[M] .* dZ[M] .+ 1
T[M] = T[M] .+ 1
end
 
imshow(-T' .^ 0.1, colormap=23)
savefig("Mercator_map_1.png", colormap=23)
 
N = abs.(Z) .> r # normalized iteration count
T[N] = T[N] - log2.(log.(abs.(Z[N])) / log(r))
 
imshow(-T' .^ 0.1, colormap=23)
savefig("Mercator_map_2.png", colormap=23)
 
N = abs.(Z) .> 2 # exterior distance estimation
D[N] = 0.5 * log.(abs.(Z[N])) .* abs.(Z[N]) ./ abs.(dZ[N])
 
imshow(D' .^ 0.1, colormap=23)
savefig("Mercator_map_3.png", colormap=23)</lang>
 
=={{header|Kotlin}}==
305

edits