open Graphics;; type segment = { x1 : float; x2 : float; y1 : float; y2 : float; } ;; let approx x = 10 + int_of_float (x+.0.5) let trace_ligne color l = clear_graph(); set_color color; let size_x = size_x() - 20 and size_y = size_y() - 20 in (* bornes *) let minx = List.fold_left (fun x -> fun y -> min x (min y.x1 y.x2)) infinity l in let maxx = List.fold_left (fun x -> fun y -> max x (max y.x1 y.x2)) neg_infinity l in let miny = List.fold_left (fun x -> fun y -> min x (min y.y1 y.y2)) infinity l in let maxy = List.fold_left (fun x -> fun y -> max x (max y.y1 y.y2)) neg_infinity l in (* facteur echelle *) let fx = (float_of_int (size_x - 1)) /. (maxx -. minx) in let fy = (float_of_int (size_y - 1)) /. (maxy -. miny) in let f = min fx fy in (* centrage *) let decalage_x = (maxx +. minx) /. 2. *. f -. float_of_int (size_x - 1) /. 2. in let decalage_y = (maxy +. miny) /. 2. *. f -. float_of_int (size_y - 1) /. 2. in List.iter (fun s -> moveto (approx (f *. s.x1 -. decalage_x)) (approx (f *. s.y1 -. decalage_y)); lineto (approx (f *. s.x2 -. decalage_x)) (approx (f *. s.y2 -. decalage_y))) l ;; let rec lettres_d_un_mot s = let l = ref [] in for i = 0 to String.length s - 1 do l := s.[i]::!l; done; List.rev (!l) let _ = open_graph " 1024x768";;