Created
March 5, 2020 09:53
-
-
Save SimonDanisch/a68920476ed1ed14aadd9bb117cd93ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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