Mandelbrot set: Difference between revisions

(→‎Normalized Counting, Distance Estimation, Mercator Maps and Deep Zoom: Smoothing and normalized iteration numbers replaced by normal maps (sources adjusted).)
Line 6,566:
gif(smoothing, "Mandelbrot_smoothing.gif", fps=2)</syntaxhighlight>
 
===NormalizedDistance CountingEstimation, DistanceNormal EstimationMaps, Mercator Maps and Perturbation Theory ===
This is a translation of the corresponding Python section. The Mandelbrot set is represented by distance estimation and normal maps using complex matrices (cf. Arnaud Chéritat: [https://www.math.univ-toulouse.fr/~cheritat/wiki-draw/index.php/Mandelbrot_set#Boundary_detection_methods_via_distance_estimators ''Boundary detection methods via distance estimators''] and [https://www.math.univ-toulouse.fr/~cheritat/wiki-draw/index.php/Mandelbrot_set#Normal_map_effect ''Normal map effect'']).
This is a translation of the corresponding Python section. The ''e^(-|z|)-smoothing'', ''normalized iteration count'' and ''exterior distance estimation'' algorithms are used.
<syntaxhighlight lang="julia">using Plots
gr(aspect_ratio=:equal, axis=true, ticks=true, legend=false, dpi=200)
Line 6,573:
d, h = 800, 500 # pixel density (= image width) and image height
n, r = 200, 500 # number of iterations and escape radius (r > 2)
 
height, angle = 1.5, 45 # height factor of the incoming light and direction of this light
v = exp(angle / 180 * pi * im) # unit 2D vector in this direction
 
x = range(0, 2, length=d+1)
Line 6,580 ⟶ 6,583:
C = (2.0 + 1.0im) .* (A' .+ B .* im) .- 0.5
 
Z, dZ, ddZ, U = zero(C), zero(C), zero(C), zero(C)
SD, T, D = zeros(size(C)), zeros(size(C)), zeros(size(C))
 
iteration(Z, dZ, ddZ, C) = Z .^ 2 .+ C, 2 .* Z .* dZ .+ 1, 2 .* (dZ .^ 2 .+ Z .* ddZ)
for k in 1:n
M = absabs2.(Z) .< abs2(r)
SZ[M], TdZ[M], = SddZ[M] .+= exp.(.- abs.iteration(Z[M])), TdZ[M], .+ddZ[M], 1C[M])
Z[M], dZ[M] = Z[M] .^ 2 .+ C[M], 2 .* Z[M] .* dZ[M] .+ 1
end
 
N = abs.(Z) .> 2 # exterior distance estimation
heatmap(S .^ 0.1, c=:jet)
D[N] = log.(abs.(Z[N])) .* abs.(Z[N]) ./ abs.(dZ[N])
 
heatmap(SD .^ 0.1, c=:jet)
savefig("Mandelbrot_set_1.png")
 
N = abs.(Z) .> r2 # normalizednormal iterationmap count(potential function)
TU[N] = TZ[N] .-/ log2.(log.(abs.(ZdZ[N])) ./ log(r))
T[N] = max.(((real.(U[N]) .* real.(v) .+ imag.(U[N]) .* imag.(v)) ./ abs.(U[N]) .+ height) ./ (1 .+ height), 0)
 
heatmap(T .^ 0.1.0, c=:jetgrays)
savefig("Mandelbrot_set_2.png")
 
N = abs.(Z) .> 2 # exteriornormal map (distance estimation)
DU[N] = 0Z[N] .5* dZ[N] .* ((1 .+ log.(abs.(Z[N]))) .* conj.(dZ[N] .^ 2) .- log.(abs.(Z[N])) ./* absconj.(dZZ[N] .* ddZ[N]))
T[N] = max.(((real.(U[N]) .* real.(v) .+ imag.(U[N]) .* imag.(v)) ./ abs.(U[N]) .+ height) ./ (1 .+ height), 0)
 
heatmap(DT .^ 0.1.0, c=:jetgrays)
savefig("Mandelbrot_set_3.png")</syntaxhighlight>
 
A small change in the code above creates Mercator maps and zoom images of the Mandelbrot set. Using the abs2 function and moving the iteration to a separate function speeds up the calculations inside the loop. See also the album [https://www.flickr.com/photos/arenamontanus/albums/72157615740829949 Mercator Mandelbrot Maps] by Anders Sandberg.
<syntaxhighlight lang="julia">using Plots
gr(aspect_ratio=:equal, axis=true, ticks=true, legend=false, dpi=200)
Line 6,627 ⟶ 6,635:
 
N = abs.(Z) .> 2 # exterior distance estimation
D[N] = 0.5 .* log.(abs.(Z[N])) .* abs.(Z[N]) ./ abs.(dZ[N])
 
heatmap(D' .^ 0.1, c=:nipy_spectral)
Line 6,685 ⟶ 6,693:
 
N = abs.(Z) .> 2 # exterior distance estimation
D[N] = 0.5 .* log.(abs.(Z[N])) .* abs.(Z[N]) ./ abs.(dZ[N])
 
heatmap(D .^ 0.3, c=:nipy_spectral)
Line 6,733 ⟶ 6,741:
 
N = abs.(Z) .> 2 # exterior distance estimation
D[N] = 0.5 .* log.(abs.(Z[N])) .* abs.(Z[N]) ./ abs.(dZ[N])
 
heatmap(D' .^ 0.03, c=:nipy_spectral)
305

edits