let float_lo_hi_by lo hi step func =
let x = ref lo in
while !x <= hi do
func !x ;
x := !x +. step
done
let calc_color count =
let tmp =
if count < 2 then
20
else if count=max_iterations then
0
else
truncate (((log (float count)) /. (log (float max_iterations))) *. 256.)
in 255 - tmp
let mandel () =
float_lo_hi_by y_min y_max step_size
(fun y ->
float_lo_hi_by x_min x_max step_size
(fun x ->
let a = {Complex.re = x; im = y} in
let rec z_loop z count =
if (count = max_iterations) || (Cm.norm2 z) > 4.0 then
let color = calc_color count in
Printf.printf "%c" (char_of_int color)
else
z_loop (Cm.add a (Cm.mul z z)) (count + 1)
in z_loop a 0) ;
Printf.eprintf "." ; flush_all ()) ;;