~ubuntu-branches/ubuntu/karmic/ocaml-doc/karmic

« back to all changes in this revision

Viewing changes to examples/minilogo/crayon.ml

  • Committer: Bazaar Package Importer
  • Author(s): Vanicat Rémi
  • Date: 2002-02-05 10:51:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020205105143-a061tunf8tev07ne
Tags: 3.04-4
* New debian maintainer
* Split doc-base file
* Move to non-free
* Change the copyright file to the copyright of the documentation
* remove FAQs (their license prohibit their redistribution)
* corrected the examples

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
open Graphics;;
 
2
 
 
3
open_graph "";;
 
4
 
 
5
let round x =
 
6
  if x >= 0.0
 
7
  then int_of_float (x +. 0.5)
 
8
  else - (int_of_float (-. x +. 0.5));;
 
9
 
 
10
type �tat =
 
11
   { mutable x : float; mutable y : float;
 
12
     mutable vis�e : float; mutable lev� : bool };;
 
13
 
 
14
let crayon = { x = 0.0; y = 0.0; vis�e = 0.0; lev� = false };;
 
15
 
 
16
let fixe_crayon b = crayon.lev� <- b;;
 
17
 
 
18
let pi_sur_180 =
 
19
    let pi = 4.0 *. (atan 1.0) in pi /. 180.0;;
 
20
 
 
21
let tourne angle =
 
22
    crayon.vis�e <- (crayon.vis�e +. angle *. pi_sur_180);;
 
23
 
 
24
let avance d =
 
25
    let dx = d *. cos (crayon.vis�e)
 
26
    and dy = d *. sin (crayon.vis�e) in
 
27
    crayon.x <- crayon.x +. dx;
 
28
    crayon.y <- crayon.y +. dy;
 
29
    if crayon.lev�
 
30
    then moveto (round crayon.x) (round crayon.y)
 
31
    else lineto (round crayon.x) (round crayon.y);;
 
32
 
 
33
let couleur_du_trac� = foreground;;
 
34
let couleur_du_fond = background;;
 
35
 
 
36
let z�ro_x = float_of_int ((size_x ()) / 2);;
 
37
let z�ro_y = float_of_int ((size_y ()) / 2);;
 
38
 
 
39
let vide_�cran () =
 
40
    clear_graph ();
 
41
    set_color couleur_du_trac�;
 
42
    crayon.x <- z�ro_x;
 
43
    crayon.y <- z�ro_y;
 
44
    crayon.vis�e <- 0.0;
 
45
    crayon.lev� <- false;
 
46
    moveto (round crayon.x) (round crayon.y);;