Autres primitives graphiques

Contacter l'auteur Pierre.Weis@inria.fr

Fichier créé le 25 mars 1998. Primitives de tracé de lignes courbes:

Avec les versions fill_* des primitives de tracé (fill_rect, fill_arc, fill_ellipse, fill_circle) on peut remplir les surfaces délimitées par ces courbes.

Ping Pong

Le programme suivant fait rebondir une balle dans un rectangle:

#open "graphics";;
open_graph "";;
let c = 5;;               (* Le rayon de la balle *)
let x0 = c
and x1 = size_x () - c
and y0 = c
and y1 = size_y () - c;;

let draw_ball x y =
 set_color foreground; 
 fill_circle x y c;;

let clear_ball x y =
 set_color background; 
 fill_circle x y c;;

let wait () = for i = 0 to 1000 do () done;;

let rec pong_aux x y dx dy =
 draw_ball x y;
 let new_x = x + dx
 and new_y = y + dy in
 let new_dx =
  if new_x - c <= x0 + 1 || new_x + c >= x1 - 1 then (- dx) else dx
 and new_dy =
  if new_y - c <= y0 + 1 || new_y + c >= y1 - 1 then (- dy) else dy in
 wait ();
 clear_ball x y;
 pong_aux new_x new_y new_dx new_dy;;

let pong () = clear_graph(); pong_aux 20 20 1 1;;


Page de présentation de Caml Dernière modification: mercredi 13 mai 1998
Copyright © 1995 - 2004, INRIA tous droits réservés.

Contacter l'auteur Pierre.Weis@inria.fr