Mandelbrot set: Difference between revisions

Content added Content deleted
m (→‎Normal Map Effect, Mercator Projection and Deep Zoom Images: Added Jussi Härkönen's paper and made changes to match Arnaud Chéritat's image.)
m (→‎Normal Map Effect, Mercator Projection and Perturbation Theory: Made changes to match Arnaud Chéritat's image.)
Line 7,986: Line 7,986:


direction, height = 45, 1.5 # direction and height of the incoming light
direction, height = 45, 1.5 # direction and height of the incoming light
stripes, damping = 10, 2.0 # stripe density and damping parameter
stripes, damping = 4, 2.0 # stripe density and damping parameter


x = range(0, 2, length=d+1)
x = range(0, 2, length=d+1)
Line 7,998: Line 7,998:


for k in 1:n
for k in 1:n
M = abs2.(Z) .< abs2(r)
M = abs.(Z) .< r
S[M], T[M] = S[M] .+ sin.(stripes .* angle.(Z[M])), T[M] .+ 1
S[M], T[M] = S[M] .+ cos.(stripes .* angle.(Z[M])), T[M] .+ 1
Z[M], dZ[M], ddZ[M] = Z[M] .^ 2 .+ C[M], 2 .* Z[M] .* dZ[M] .+ 1, 2 .* (dZ[M] .^ 2 .+ Z[M] .* ddZ[M])
Z[M], dZ[M], ddZ[M] = Z[M] .^ 2 .+ C[M], 2 .* Z[M] .* dZ[M] .+ 1, 2 .* (dZ[M] .^ 2 .+ Z[M] .* ddZ[M])
end
end


N = abs.(Z) .>= r # normal map effect 1 (potential function)
N = abs.(Z) .>= r # normal map effect 1 (potential function)
P, Q = S[N] ./ T[N], (S[N] .+ sin.(stripes .* angle.(Z[N]))) ./ (T[N] .+ 1)
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 interpolation)
F = log2.(log.(abs.(Z[N])) ./ log(r)) # fraction between 0 and 1 (for interpolation)
H = F .* P .+ (1 .- F) .* Q # height perturbation (by linear interpolation)
R = Q .+ (P .- Q) .* F .* F .* (3 .- 2 .* F) # hermite interpolation (r is between q and p)
U = Z[N] ./ dZ[N] # normal vectors to the equipotential lines
U, H = Z[N] ./ dZ[N], 1 .+ R ./ damping # normal vectors to the equipotential lines and height perturbation
U, v = U ./ abs.(U), exp(direction / 180 * pi * im) # unit normal vectors and unit 2D vector
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) .+ (1 .+ H ./ damping) .* height) ./ (1 + height), 0)
D[N] = max.((real.(U) .* real(v) .+ imag.(U) .* imag(v) .+ H .* height) ./ (1 + height), 0)


heatmap(D .^ 1.0, c=:bone_1)
heatmap(D .^ 1.0, c=:bone_1)
Line 8,016: Line 8,016:
N = abs.(Z) .>= r # normal map effect 2 (distance estimation)
N = abs.(Z) .>= r # normal map effect 2 (distance estimation)
U = Z[N] .* dZ[N] .* ((1 .+ log.(abs.(Z[N]))) .* conj.(dZ[N] .^ 2) .- log.(abs.(Z[N])) .* conj.(Z[N] .* ddZ[N]))
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 unit 2D vector
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)
D[N] = max.((real.(U) .* real(v) .+ imag.(U) .* imag(v) .+ height) ./ (1 + height), 0)