-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathmandelbrot.ml
76 lines (73 loc) · 4.09 KB
/
mandelbrot.ml
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
64
65
66
67
68
69
70
71
72
73
74
75
76
let rec density_str d =
if d > 8.0 then " " else
if d > 4.0 then "." else
if d > 2.0 then "*" else
"+"
in
let rec converge r i =
let rec go real imag iter creal cimag =
if iter > 255.0 || (real *. real +. imag *. imag) >= 4.0 then
iter
else
go (real *. real -. imag *. imag +. creal) (2.0 *. real *. imag +. cimag) (iter +. 1.0) creal cimag
in
go r i 0.0 r i
in
let rec mandel realstart imagstart realmag imagmag =
let rec plot x xmax xstep y ymax ystep =
let rec plot_line x y =
if x >= xmax then () else
let dens = converge x y in
print_str (density_str dens);
plot_line (x +. xstep) y
in
if y >= ymax then () else
(plot_line x y;
println_str "";
plot x xmax xstep (y +. ystep) ymax ystep)
in
plot realstart (realstart +. realmag *. 78.0) realmag imagstart (imagstart +. imagmag *. 40.0) imagmag
in
mandel (-.2.3) (-.1.3) 0.05 0.07
(* Output:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++******++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++*****...******++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++********.. ...*****++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++**********.. ..*****+++++++++++++++++++++++++
++++++++++++++++++++++++++++++**********. ..******++++++++++++++++++++++++
++++++++++++++++++++++++++++*********.... ..******+++++++++++++++++++++++
++++++++++++++++++++++++++********....... .....****++++++++++++++++++++++
+++++++++++++++++++++++++********. . ... .**+++++++++++++++++++++
+++++++++++++++++++++++********... **+++++++++++++++++++++
+++++++++++++++++++++*********.... .***++++++++++++++++++++
++++++++++++++++++***..*****.... ..***+++++++++++++++++++
++++++++++++++******. .......... ***+++++++++++++++++++
+++++++++++********.. .. .**+++++++++++++++++++
+++++++++**********... .****++++++++++++++++++
++++++++**********.. .****++++++++++++++++++
+++++++******..... ..****++++++++++++++++++
+++++++*........ ...****++++++++++++++++++
+++++++*... .... ...****++++++++++++++++++
+++++++*****...... ..****++++++++++++++++++
+++++++**********... .****++++++++++++++++++
+++++++++**********... ****++++++++++++++++++
++++++++++*********.. .. ..**+++++++++++++++++++
+++++++++++++******.. .......... ***+++++++++++++++++++
++++++++++++++++++***...***..... ..***+++++++++++++++++++
+++++++++++++++++++++*********.... ..**++++++++++++++++++++
+++++++++++++++++++++++********... ***++++++++++++++++++++
+++++++++++++++++++++++++*******.. . ... .**+++++++++++++++++++++
++++++++++++++++++++++++++********....... ......***++++++++++++++++++++++
++++++++++++++++++++++++++++*********.... ..******+++++++++++++++++++++++
+++++++++++++++++++++++++++++**********.. ..******++++++++++++++++++++++++
+++++++++++++++++++++++++++++++**********.. ...*****+++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++********.. ...*****++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++******....*****++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++********+++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*)