(***********************************************************************) (* *) (* OCaml library from the book ``Apprendre à programmer avec OCaml'' *) (* *) (* Sylvain Conchon and Jean-Christophe Filliâtre *) (* Université Paris Sud *) (* *) (* Copyright 2014 Université Paris Sud. All rights reserved. This *) (* file is distributed under the terms of the GNU Library General *) (* Public License, with the same special exception on linking as the *) (* OCaml library. See http://caml.inria.fr/ocaml/license.fr.html *) (* *) (***********************************************************************) (* Programme 4 page 32 Dessin de la fractale de Mandelbrot *) open Graphics let width = 800 let height = 800 let k = 100 let norm2 x y = x *. x +. y *. y let mandelbrot a b = let rec mandel_rec x y i = if i = k || norm2 x y > 4. then i = k else let x' = x *. x -. y *. y +. a in let y' = 2. *. x *. y +. b in mandel_rec x' y' (i + 1) in mandel_rec 0. 0. 0 let draw () = for w = 0 to width - 1 do for h = 0 to height - 1 do let a = 4. *. float w /. float width -. 2. in let b = 4. *. float h /. float height -. 2. in if mandelbrot a b then plot w h done done let () = let dim = Printf.sprintf " %dx%d" width height in open_graph dim; draw (); ignore (read_key ())
This document was generated using caml2html