forked from jheinen/GR.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mandel.jl
63 lines (50 loc) · 1.32 KB
/
mandel.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env julia
import GR
function mandel(x, y, iters)
c = complex(x, y)
z = 0.0im
ci = 0
inc = 1
for i in 0:iters
z = z^2 + c
if abs2(z) >= 4
return ci
end
ci += inc
if ci == 0 || ci == 255
inc = -inc
end
end
return 255
end
function main()
function create_fractal(min_x, max_x, min_y, max_y, image, iters)
height = size(image, 1)
width = size(image, 2)
pixel_size_x = (max_x - min_x) / width
pixel_size_y = (max_y - min_y) / height
for i in 1:width
real = min_x + (i - 1) * pixel_size_x
for j in 1:height
imag = min_y + (j - 1) * pixel_size_y
color = mandel(real, imag, iters)
image[j, i] = color
end
end
end
x = -0.9223327810370947027656057193752719757635
y = 0.3102598350874576432708737495917724836010
f = 0.5
for i in 0:200
image = zeros(Int32, 500, 500)
dt = @elapsed create_fractal(x-f, x+f, y-f, y+f, image, 400)
println("Mandelbrot created in $dt s")
GR.clearws()
GR.setviewport(0, 1, 0, 1)
GR.setcolormap(13)
GR.cellarray(0, 1, 0, 1, 500, 500, image .+ 1000)
GR.updatews()
f *= 0.9
end
end
main()