set_line_width n
: change la largeur du trait du crayon.
draw_arc x y rx ry a1 a2
trace un arc d'ellipse de
centre (x
, y
) de rayon horizontal
rx
, vertical ry
, de l'angle a1
à l'angle a2
(en degrés).
draw_ellipse x y rx ry
trace une ellipse de
centre (x
, y
) de rayon horizontal
rx
, et de rayon vertical ry
.
draw_circle x y r
trace un cercle
centre (x
, y
) et de rayon r
.
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.
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;;
Contacter l'auteur Pierre.Weis@inria.fr