(* Dessin de l'ensemble de Mandelbrot, avec des couleurs. *) open Graphics let width = 800 let height = 800 let k = 100 (* On choisit ici de donner une couleur qui est une nuance de gris, avec un gris d'autant plus foncé que le nombre d'itérations i est petit. Cela donne un joli contraste avec l'ensemble lui-même, qui est noir. Bien entendu, on peut aussi mettre de la couleur. Il suffit pour cela de remplacer "rgb f f f" par autre chose. On peut aussi choisir une formule plus subtile qu'une règle de trois. *) let color i = if i = k then black else let f = truncate (255. *. float i /. float k) in rgb f f f 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 color i 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 set_color (mandelbrot a b); plot w h done done let () = let dim = Printf.sprintf " %dx%d" width height in open_graph dim; draw (); ignore (read_key ())