1 (***********************************************************************)
3 (* MLTk, Tcl/Tk interface of Objective Caml *)
5 (* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *)
6 (* projet Cristal, INRIA Rocquencourt *)
7 (* Jacques Garrigue, Kyoto University RIMS *)
9 (* Copyright 2002 Institut National de Recherche en Informatique et *)
10 (* en Automatique and Kyoto University. All rights reserved. *)
11 (* This file is distributed under the terms of the GNU Library *)
12 (* General Public License, with the special exception on linking *)
13 (* described in file LICENSE found in the Objective Caml source tree. *)
15 (***********************************************************************)
17 (* The eyes of Caml (CamlTk) *)
22 let top = opentk () in
24 let fw = Frame.create top [] in
26 let c = Canvas.create fw [Width (Pixels 200); Height (Pixels 200)] in
27 let create_eye cx cy wx wy ewx ewy bnd =
30 (Pixels (cx - wx)) (Pixels (cy - wy))
31 (Pixels (cx + wx)) (Pixels (cy + wy))
32 [Outline (NamedColor "black"); Width (Pixels 7);
33 FillColor (NamedColor "white")]
36 (Pixels (cx - ewx)) (Pixels (cy - ewy))
37 (Pixels (cx + ewx)) (Pixels (cy + ewy))
38 [FillColor (NamedColor "black")] in
42 (BindExtend ([Ev_MouseX; Ev_MouseY],
45 let xdiff = e.ev_MouseX - cx
46 and ydiff = e.ev_MouseY - cy in
47 let diff = sqrt ((float xdiff /. (float wx *. bnd)) ** 2.0 +.
48 (float ydiff /. (float wy *. bnd)) ** 2.0) in
50 truncate ((float xdiff) *. (1.0 /. diff)) + cx,
51 truncate ((float ydiff) *. (1.0 /. diff)) + cy
53 e.ev_MouseX, e.ev_MouseY
55 Canvas.move c o (Pixels (nx - !curx)) (Pixels (ny - !cury));
59 create_eye 60 100 30 40 5 6 0.6;
60 create_eye 140 100 30 40 5 6 0.6;
63 let _ = Printexc.print mainLoop ()