open Graphics ;; open_graph "" ;; let arrondi x_float = let x_int = int_of_float x_float in let différence_float = x_float -. float_of_int x_int in if différence_float > 0.5 then if différence_float < 0. then x_int - 1 else x_int + 1 else x_int ;; let avance distance angle = let (x_courant_int,y_courant_int) = current_point() in let x_courant_float = float_of_int x_courant_int and y_courant_float = float_of_int y_courant_int in let x_cible_float = x_courant_float +. distance *. (cos angle) and y_cible_float = y_courant_float +. distance *. (sin angle) in let x_cible_int = arrondi x_cible_float and y_cible_int = arrondi y_cible_float in lineto x_cible_int y_cible_int ;; let pi = 3.1415926535 ;; let pi_sur_trois = pi /. 3. ;; let rec motif generation distance angle = match generation with 0 -> avance distance angle | n -> let nouvelle_distance = distance /. 3. in motif (n-1) nouvelle_distance angle ; motif (n-1) nouvelle_distance (angle +. pi_sur_trois) ; motif (n-1) nouvelle_distance (angle -. pi_sur_trois) ; motif (n-1) nouvelle_distance angle ;; clear_graph();; moveto 10 10;; motif 0 300. 0.;; moveto 10 50;; motif 1 300. 0.; moveto 10 150;; motif 2 300. 0.;; moveto 10 250;; motif 3 300. 0.;; moveto 10 350;; motif 4 300. 0.;; moveto 385 10 ;; motif 5 300. (pi /. 2.);; moveto 435 10 ;; motif 6 300. (pi /. 2.);; while not(key_pressed()) do () done;;