Added tests of the Graphics module.
[fedora-mingw.git] / ocaml / test4.ml
diff --git a/ocaml/test4.ml b/ocaml/test4.ml
new file mode 100644 (file)
index 0000000..aef535b
--- /dev/null
@@ -0,0 +1,24 @@
+(* From: http://www.ocaml-tutorial.org/the_structure_of_ocaml_programs *)
+
+let () =
+  Random.self_init ();
+  Graphics.open_graph " 640x480";
+
+  let rec iterate r x_init i =
+    if i = 1 then x_init
+    else
+      let x = iterate r x_init (i-1) in
+      r *. x *. (1.0 -. x)
+  in
+
+  for x = 0 to 639 do
+    let r = 4.0 *. (float_of_int x) /. 640.0 in
+    for i = 0 to 39 do
+      let x_init = Random.float 1.0 in
+      let x_final = iterate r x_init 500 in
+      let y = int_of_float (x_final *. 480.) in
+      Graphics.plot x y
+    done
+  done;
+
+  ignore (read_line ())