Other graphical primitives

Contacter l'auteur Pierre.Weis@inria.fr

Fichier créé le 25 mars 1998.

Primitives to draw curved lines:

Using the fill_* versions of drawing primitives (fill_rect, fill_arc, fill_ellipse, fill_circle) you may paint the areas surrounded by these curves.

Ping Pong

The ball is rebounding inside a rectangular area.
#open "graphics";;

open_graph "";;

let c = 5;;               (* The radius of the ball *)
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;;


Caml home page Last modified: Friday, March 26, 2004
Copyright © 1995 - 2004, INRIA all rights reserved.

Contact the author Pierre.Weis@inria.fr