set_line_width n
: modifies the width of the pencil.
Primitives to draw curved lines:
draw_arc x y rx ry a1 a2
draws an ellipse, with
center (x
, y
), horizontal radius
rx
, vertical radius ry
, from angle a1
to angle a2
(in degrees).
draw_ellipse x y rx ry
draws an ellipse, with
center (x
, y
), horizontal radius
rx
, and vertical radius ry
.
draw_circle x y r
draws a circle, with
center (x
, y
) and radius r
.
Using the fill_*
versions of drawing primitives
(fill_rect
, fill_arc
, fill_ellipse
,
fill_circle
) you may paint the areas surrounded by these curves.
#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;;
Contact the author Pierre.Weis@inria.fr