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 (* $Id: eyes.ml 4745 2002-04-26 12:16:26Z furuse $ *)
22 let top = openTk () in
23 let fw = Frame.create top in
25 let c = Canvas.create ~width: 200 ~height: 200 fw in
26 let create_eye cx cy wx wy ewx ewy bnd =
27 let o2 = Canvas.create_oval
28 ~x1:(cx - wx) ~y1:(cy - wy)
29 ~x2:(cx + wx) ~y2:(cy + wy)
30 ~outline: `Black ~width: 7
33 and o = Canvas.create_oval
34 ~x1:(cx - ewx) ~y1:(cy - ewy)
35 ~x2:(cx + ewx) ~y2:(cy + ewy)
40 bind ~events:[`Motion] ~extend:true ~fields:[`MouseX; `MouseY]
43 let xdiff = e.ev_MouseX - cx
44 and ydiff = e.ev_MouseY - cy in
45 let diff = sqrt ((float xdiff /. (float wx *. bnd)) ** 2.0 +.
46 (float ydiff /. (float wy *. bnd)) ** 2.0) in
48 truncate ((float xdiff) *. (1.0 /. diff)) + cx,
49 truncate ((float ydiff) *. (1.0 /. diff)) + cy
51 e.ev_MouseX, e.ev_MouseY
53 Canvas.move c o ~x: (nx - !curx) ~y: (ny - !cury);
58 create_eye 60 100 30 40 5 6 0.6;
59 create_eye 140 100 30 40 5 6 0.6;
62 let _ = Printexc.print mainLoop ()