(* initialisations du graphisme *) #open "graphics";; (*chargement de la bibliothèque *) 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;; let yEmin=0;; let xEmax=size_x();; let yEmax=size_y();; let xElong=xEmax-xEmin;; let yElong=yEmax-yEmin;; let xEorig = div_int (xEmin+xEmax) 2;; let yEorig = div_int (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.;; let xmax=10.;; let ymin= -10.*.coeff;; let ymax=10.*.coeff;; let xorig=(xmin+.xmax)/.2.;; let yorig=(ymin+.ymax)/.2.;; let xlong=xmax-.xmin;; let ylong=ymax-.ymin;; let tmin= -10.;; let tmax=10. ;;let torig=(tmax+.tmin)/.2.;; let 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_object "C:/OPTION/MODULES/Ini_gr.zo";; #open "C:/OPTION/MODULES/Ini_gr";; #open "Ini_gr";; (* ligne théoriquement inutile... *) #open "graphics";; (* bizarremnt indispensable alors que c'est en ligne 1 *) 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 ;; *)