forked from crystal-lang/crystal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mandelbrot.cr
38 lines (33 loc) · 828 Bytes
/
mandelbrot.cr
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
def print_density(d)
if d > 8
print ' '
elsif d > 4
print '.'
elsif d > 2
print '*'
else
print '+'
end
end
def mandelconverger(real, imag, iters, creal, cimag)
if iters > 255 || real*real + imag*imag >= 4
iters
else
mandelconverger real*real - imag*imag + creal, 2*real*imag + cimag, iters + 1, creal, cimag
end
end
def mandelconverge(real, imag)
mandelconverger real, imag, 0, real, imag
end
def mandelhelp(xmin, xmax, xstep, ymin, ymax, ystep)
ymin.step(to: ymax, by: ystep) do |y|
xmin.step(to: xmax, by: xstep) do |x|
print_density mandelconverge(x, y)
end
puts
end
end
def mandel(realstart, imagstart, realmag, imagmag)
mandelhelp realstart, realstart + realmag*78, realmag, imagstart, imagstart + imagmag*40, imagmag
end
mandel -2.3, -1.3, 0.05, 0.07