Js_of_ocaml compiles OCaml bytecode to Javascript.
This web-based OCaml toplevel is compiled using Js_of_ocaml. 99% of the toplevel code is courtesy of the js_of_ocaml developers.
The P5 API is available to browse, the library is currently incomplete.
In addition to that the "jsoo-p5" library provides typed bindings to p5.js. That library is preloaded into the toplevel for you to explore. In order to restart you can either reload the page or click "Remove Canvas". Here's a quick example to get you up and running:
# open P5
# let setup sketch () = Canvas.create ~sketch 800 800 |> ignore
# let x = ref 50.
# let draw sketch () =
Color.background ~sketch (Color.make ~sketch 0 0 0);
Color.fill ~sketch (Color.make ~sketch 255 0 0);
Shape.rect ~sketch (float_of_int ((int_of_float !x) mod 800)) 50. 50. 50.;
x := !x +. 1.
# Sketch.with_sketch ~id:"canvas" @@ fun sketch -> Sketch.run ~sketch ~setup:(setup sketch) ~draw:(draw sketch) ();;
Enter/Return | Submit code |
Ctrl + Enter | Newline |
Up / Down | Browse history |
Ctrl + l | Clear display |
Ctrl + k | Reset toplevel |
Tab | Indent code |