- reset ();
- ( Dom_html.addEventListener canvas Dom_html.Event.mousemove
- (Dom.handler (fun ev ->
- marbling_view := add_drop (float_of_int ev##.offsetX, float_of_int ev##.offsetY) !r !color !marbling;
- Js.bool true))
- (Js.bool false),
- Dom_html.addEventListener canvas Dom_html.Event.mousedown
- (Dom.handler (fun ev ->
- marbling := add_drop (float_of_int ev##.offsetX, float_of_int ev##.offsetY) !r !color !marbling;
- reset ();
- marbling_view := add_drop (float_of_int ev##.offsetX, float_of_int ev##.offsetY) !r !color !marbling;
- Js.bool true))
- (Js.bool false),
- Dom_html.addEventListener canvas Dom_html.Event.mouseout
- (Dom.handler (fun _ev ->
- marbling_view := !marbling;
- Js.bool true))
- (Js.bool false) )
+ let rec with_drop_info marbling_view =
+ ctx##.fillStyle := Js.string "#00001f";
+ ctx##fillRect 0.0 0.0 (float_of_int canvas##.width) (float_of_int canvas##.height);
+ List.iter
+ (fun (shape, color) ->
+ ctx##.fillStyle := color;
+ Shape.path ctx shape;
+ ctx##fill)
+ marbling_view;
+ let* ev =
+ Lwt.pick
+ Lwt_js_events.
+ [
+ (let+ ev = mousedown canvas in
+ Click (float_of_int ev##.offsetX, float_of_int ev##.offsetY));
+ (let+ ev = mouseup canvas in
+ Unclick (float_of_int ev##.offsetX, float_of_int ev##.offsetY));
+ (let+ ev = mousemove canvas in
+ Move (float_of_int ev##.offsetX, float_of_int ev##.offsetY));
+ (let+ _ = mouseout canvas in
+ Out);
+ ]
+ in
+ match ev with
+ | Click p -> with_drop_info (add_drop p r color marbling)
+ | Unclick p -> main (add_drop p r color marbling) p ()
+ | Move p -> with_drop_info (add_drop p r color marbling)
+ | Out -> with_drop_info marbling
+ in
+ with_drop_info (add_drop p r color marbling)
+
+let () = Lwt.async (main [] (400., 400.))