-
Notifications
You must be signed in to change notification settings - Fork 0
/
julia set.jl
41 lines (33 loc) · 1.15 KB
/
julia set.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using PlotlyJS
function create_grid(dims, width, height)
# Returns a grid of complex number of width and height in the
# given domain.
xmin, xmax, ymin, ymax = dims
x = range(xmin, xmax, width)
y = range(ymin, ymax, height)
return (x' .* ones(height)) .+ reverse(y .* ones(width)' .* 1im)
end
function julia_set(cp, number::ComplexF64, max_abs, N)
# Consumes the complex grid and ruuns every number through the recusive
# function. Generates a new matrix of just real numbers that represents how fast
# every point divverges. That is what is graphed.
n = zeros(Float64, size(cp))
for i in 1:N
b = abs.(cp) .<= max_abs
cp[b] .= (cp[b].^2) .+ number
n[b] .= n[b] .+ 1
println("$i/$N")
end
function data(n)
return 1 .- sqrt.(n ./ N)
end
return data(n)
end
c = -0.1 - 0.65im
const maximum_magnitude = 10
const number_of_iterations = 500
height, width = 500, 500
domain = (-2,2,-2,2)
C = create_grid(domain, width, height)
data = julia_set(C, c, maximum_magnitude, number_of_iterations)
plot(heatmap(z=data, colorscale="Jet"))