Mandelbrot set: Difference between revisions

→‎Normal Map Effect, Mercator Projection and Perturbation Theory: The original coloring methods added and subheadings inserted; Comments shortened
(→‎Normal Map Effect, Mercator Projection and Deep Zoom Images: The original coloring methods added and subheadings inserted; Comments shortened)
(→‎Normal Map Effect, Mercator Projection and Perturbation Theory: The original coloring methods added and subheadings inserted; Comments shortened)
Line 7,978:
 
===Normal Map Effect, Mercator Projection and Perturbation Theory===
====Smoothing, Normalization and Distance Estimation====
This is a translation of the corresponding Python section: see there for more explanations. 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#Normal_map_effect ''Normal map effect'']). See also [https://www.shadertoy.com/view/wtscDX Julia Stripes] on Shadertoy.
This is a translation of the corresponding Python section: see there for more explanations. 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)
 
d, h = 800, 500 # 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 = collect(x) .- 1, collect(y) .- h / d
C = (2.0 + 1.0im) .* (A' .+ B .* im) .- 0.5
 
Z, dZ = zero(C), zero(C)
S, T, D = zeros(size(C)), zeros(size(C)), zeros(size(C))
 
for k in 1:n
M = abs.(Z) .< r
S[M], T[M] = S[M] .+ exp.(.- abs.(Z[M])), T[M] .+ 1
Z[M], dZ[M] = Z[M] .^ 2 .+ C[M], 2 .* Z[M] .* dZ[M] .+ 1
end
 
heatmap(S .^ 0.1, c=:balance)
savefig("Mandelbrot_set_1.png")
 
N = abs.(Z) .>= r # normalized iteration count
T[N] = T[N] .- log2.(log.(abs.(Z[N])) ./ log(r))
 
heatmap(T .^ 0.1, c=:balance)
savefig("Mandelbrot_set_2.png")
 
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=:balance)
savefig("Mandelbrot_set_3.png")</syntaxhighlight>
 
====Normal Map Effect and Stripe Average Coloring====
This is a translation of the corresponding Python section: see there for more explanations. The Mandelbrot set is represented byusing distanceNormal estimationMaps and normalStripe mapsAverage usingColoring by complexJussi matricesHärkönen (cf. Arnaud Chéritat: [https://www.math.univ-toulouse.fr/~cheritat/wiki-draw/index.php/Mandelbrot_set#Normal_map_effect ''Normal map effect'']). See also [https://www.shadertoy.com/view/wtscDX Julia Stripes] on Shadertoy.
<syntaxhighlight lang="julia">using Plots
gr(aspect_ratio=:equal, axis=true, ticks=true, legend=false, dpi=200)
Line 8,003 ⟶ 8,042:
end
 
N = abs.(Z) .>= r # normal map effect 1 (potentialequipotential functionlines)
P, Q = S[N] ./ T[N], (S[N] .+ cos.(stripes .* angle.(Z[N]))) ./ (T[N] .+ 1)
F = log2.(log.(abs.(Z[N])) ./ log(r)) # fraction between 0 and 1 (for interpolationnormalization)
R = Q .+ (P .- Q) .* F .* F .* (3 .- 2 .* F) # hermite interpolation (r is between qlinear andor pHermite)
U, H = Z[N] ./ dZ[N], 1 .+ R ./ damping # normal vectors to the equipotential lines and height perturbationvariations
U, v = U ./ abs.(U), exp(direction / 180 * pi * im) # unit normal vectors and vector in light direction
D[N] = max.((real.(U) .* real(v) .+ imag.(U) .* imag(v) .+ H .* height) ./ (1 + height), 0)
 
Line 8,014 ⟶ 8,053:
savefig("Mandelbrot_normal_map_1.png")
 
N = abs.(Z) .>= r # normal map effect 2 (distanceequidistant estimationlines)
U = Z[N] .* dZ[N] .* ((1 .+ log.(abs.(Z[N]))) .* conj.(dZ[N] .^ 2) .- log.(abs.(Z[N])) .* conj.(Z[N] .* ddZ[N]))
U, v = U ./ abs.(U), exp(direction / 180 * pi * im) # unit normal vectors and vector in light direction
D[N] = max.((real.(U) .* real(v) .+ imag.(U) .* imag(v) .+ height) ./ (1 + height), 0)
 
Line 8,022 ⟶ 8,061:
savefig("Mandelbrot_normal_map_2.png")</syntaxhighlight>
 
====Mercator Mandelbrot Maps and Zoom Images====
A small change in the code above creates Mercator maps and zoom images of the Mandelbrot set. See also the album [https://www.flickr.com/photos/arenamontanus/albums/72157615740829949 Mercator Mandelbrot Maps] by Anders Sandberg. See also [https://commons.wikimedia.org/wiki/File:Mandelbrot_sequence_new.gif ''Mandelbrot sequence new''] (Wikimedia) for a zoom animation to the given coordinates.
<syntaxhighlight lang="julia">using Plots
Line 8,063 ⟶ 8,103:
savefig("Mercator_Mandelbrot_zoom.png")</syntaxhighlight>
 
====Perturbation Theory and Deep Mercator Maps====
For deep zoom images it is sufficient to calculate a single point with high accuracy. A good approximation can then be found for all other points by means of a perturbation calculation with standard accuracy. Rebasing is used to reduce glitches. See [https://fractalforums.org/fractal-mathematics-and-new-theories/28/another-solution-to-perturbation-glitches/4360 Another solution to perturbation glitches] (Fractalforums) for details. See also the image [https://www.flickr.com/photos/arenamontanus/3430921497/in/album-72157615740829949/ Deeper Mercator Mandelbrot] by Anders Sandberg.
<syntaxhighlight lang="julia">using Plots
305

edits