Skip to content

Instantly share code, notes, and snippets.

@Clemapfel
Last active May 14, 2023 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Clemapfel/a04c5ec73f5f43b69c9097e068c15c7d to your computer and use it in GitHub Desktop.
Save Clemapfel/a04c5ec73f5f43b69c9097e068c15c7d to your computer and use it in GitHub Desktop.
using BenchmarkTools
function meshgrid(a, b)
x = a' .* ones(length(b))
y = ones(length(a))' .* b
return x, y
end
savetxt(filename, array) = open(filename, "w") do io
for row in eachrow(array)
line = replace(string(row), "[" => "", "]" => "", "," => "")
println(io, line)
end
end
function main()
ITERATIONS = 100
DENSITY = 1000
x_min, x_max = -2.68, 1.32
y_min, y_max = -1.5, 1.5
x,y = meshgrid(LinRange(x_min, x_max, DENSITY), LinRange(y_min, y_max, DENSITY))
c = x + (y)im
z = copy(c)
fractal = fill(UInt8(255), DENSITY, DENSITY)
for n in 1:ITERATIONS
for i in 1:length(z)
if abs(z[i]) <= 10
z[i] ^= 2
z[i] += c[i]
elseif fractal[i] == 255
fractal[i] = 254 * (n-1) ÷ ITERATIONS
end
end
end
if false
logfractal = log.(fractal) #devin.jl
println("Saving...")
savetxt("fractal.dat", logfractal)
savetxt("coord.dat", [ x_min, x_max, y_min, y_max ] )
end
end
println(@benchmark main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment