Skip to content

Instantly share code, notes, and snippets.

@SimonDanisch
Created March 5, 2020 09:53
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 SimonDanisch/a68920476ed1ed14aadd9bb117cd93ae to your computer and use it in GitHub Desktop.
Save SimonDanisch/a68920476ed1ed14aadd9bb117cd93ae to your computer and use it in GitHub Desktop.
using StructArrays
using BenchmarkTools
using LoopVectorization
function juliaset2(re, im, c, maxiter)
result = re % UInt8
for i in 1:maxiter
abs = re*re + im*im
mask = abs > 4f0
result = mask & ((i - 1) % UInt8)
re = re * re - im * im
im = re * im + im * re
re += real(c)
im += imag(c)
end
return result
end
# scale should change with picture size
scale = 200.0 # the greater the more details
width, height = 800, 700
x = -0.5; y = 1.2
c = x+y*im
xvalues = LinRange(-width/2, width/2, width) ./ scale
yvalues = LinRange(-height/2, height/2, height) ./ scale
inputmatrix = xvalues' .+ yvalues .* im
result = fill(UInt(8), height, width)
in = StructArray(inputmatrix)
test3(result, i, c) = @avx result .= juliaset2.(i.re, i.im, c, 255)
@time test3(result, in, c)
using Colors, ImageShow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment