You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is a small graphics_example.ml OCaml file to load in BetterOCaml, to check that it supports the Graphics module.
It works perfectly on my Chromium, but not great on Firefox: the canvas open, get filled, but very quickly turn blank again.
(** * Basic example of using Graphics module for OCaml * Taken from https://caml.inria.fr/pub/docs/oreilly-book/html/book-ora048.html * * to use it in a toplevel: $ ocaml graphics.cma # #use "graphics_example.ml";; * * to use it in BetterOCaml, prefer using Google Chrome or Chromium: $ ocaml graphics.cma # #use "graphics_example.ml";;*)letdraw_rectx0y0wh=let (a,b) =Graphics.current_point()and x1 = x0+w and y1 = y0+h
inGraphics.moveto x0 y0;
Graphics.lineto x0 y1; Graphics.lineto x1 y1;
Graphics.lineto x1 y0; Graphics.lineto x0 y0;
Graphics.moveto a b
;;
letdraw_polyr=let (a,b) =Graphics.current_point ()inlet (x0,y0) = r.(0) inGraphics.moveto x0 y0;
for i =1to (Array.length r)-1dolet (x,y) = r.(i) inGraphics.lineto x y
done;
Graphics.lineto x0 y0;
Graphics.moveto a b
;;
let pi =3.1415927;;
letnet_points (x,y) ln=let a =2.*. pi /. (float n) inletrec aux (xa,ya) i=if i > n then[]elselet na = (float i) *. a inlet x1 = xa + (int_of_float ( cos(na) *. l))
and y1 = ya + (int_of_float ( sin(na) *. l)) inlet np = (x1,y1) in
np::(aux np (i+1))
inArray.of_list (aux (x,y) 1)
;;
letdraw_net (x,y) lnscst=let r = net_points (x,y) l n in
draw_poly r;
letdraw_machine (x,y) =Graphics.set_color Graphics.background;
Graphics.fill_circle x y sc;
Graphics.set_color Graphics.foreground;
Graphics.draw_circle x y sc
inArray.iter draw_machine r;
Graphics.fill_circle x y st
;;
Graphics.open_graph " width=900,height=600";;
draw_net (140,20) 60.010103;;
The text was updated successfully, but these errors were encountered:
Here is a small
graphics_example.ml
OCaml file to load in BetterOCaml, to check that it supports the Graphics module.It works perfectly on my Chromium, but not great on Firefox: the canvas open, get filled, but very quickly turn blank again.
The text was updated successfully, but these errors were encountered: