(* initialisations du graphisme *) (* La ligne suivante doit être commenter si l'on veut produire le fichier .cmo #load "graphics.cmo";; (*chargement de la bibliothèque *) *) open Graphics;; let round x = if x >= 0.0 then int_of_float (x +. 0.5) else - (int_of_float (-. x +. 0.5));; let couleur_du_trace = foreground;; let couleur_du_fond = background;; (* mes noms de constantes dans le monde de l'écran *) let xEmin=0 and yEmin=0 and xEmax=size_x() and yEmax=size_y();; let xElong=xEmax-xEmin and yElong=yEmax-yEmin and xEorig = (xEmin+xEmax)/2 and yEorig = (yEmin+yEmax)/2;; let vide_ecran () = clear_graph(); set_color couleur_du_trace; moveto (xEorig) (yEorig);; (* mes noms de constantes dans le monde virtuel *) let coeff= 0.75;; (* rapport yEmax/xEmax *) let xmin= -10. and xmax=10.;; let ymin= -10.*.coeff and ymax=10.*.coeff;; let xorig=(xmin+.xmax)/.2. and yorig=(ymin+.ymax)/.2.;; let xlong=xmax-.xmin and ylong=ymax-.ymin;; let tmin= -10. and tmax=10.;; let torig=(tmax+.tmin)/.2. and tlong=tmax-.tmin;; let nbpt=1000;; let dt=tlong/.(float_of_int nbpt);; (* les conversion virtuel -> écran *) let coeffx=(float_of_int xElong)/.xlong;; let coeffy=(float_of_int yElong)/.ylong;; let virtuel_a_ecran_x x=xEorig+round (coeffx*.(x-.xorig));; let virtuel_a_ecran_y y=yEorig+round (coeffy*.(y-.yorig));; let premier_point (x,y)=plot (virtuel_a_ecran_x x) (virtuel_a_ecran_y y);; let va_en (x,y)=moveto (virtuel_a_ecran_x x) (virtuel_a_ecran_y y);; let joins_a (x,y)=lineto (virtuel_a_ecran_x x) (virtuel_a_ecran_y y);; (* les conversion écran -> virtuel *) let ecran_a_virtuel_x x= xorig+.(float_of_int (x-xEorig))/.coeffx;; let ecran_a_virtuel_y y= yorig+.(float_of_int (y-yEorig))/.coeffy;; (* le tracé du graphe de f: t->(x(t),y(t)) *) let trace f a b= let rec suit t= let tdt=t+.dt in if t>=b then () else begin joins_a (f tdt); suit tdt end in premier_point (f a); suit a ;; (* un échantillon non compilé *) (* #load "Ini_gr.cmo";; open Ini_gr;; (* ligne théoriquement inutile... *) open_graph "";; (* initialisation, mode par défaut *) vide_ecran();; let lissajous t=(sin(2.*.t),sin(3.*.t));; trace lissajous 1. 8.;; let cercle t=(cos(t),sin(t));; trace cercle 0. 6.29;; (* avec de la couleur *) open_graph "";; (* initialisation, mode par défaut *) let lissajous_couleur m t =(m*.sin(2.*.t),m*.sin(3.*.t));; vide_ecran();; for k=1 to 10 do begin set_color (rgb (10*k) (200-20*k) (20*k)); trace (lissajous_couleur (float_of_int k)) 1. 8. end done ;; *)