diff --git a/.ocamlformat b/.ocamlformat index 0b240ee..7df62da 100644 --- a/.ocamlformat +++ b/.ocamlformat @@ -1,2 +1,2 @@ profile = default -version = 0.26.0 \ No newline at end of file +version = 0.26.1 \ No newline at end of file diff --git a/examples/axes.ml b/examples/axes.ml index 2f7c461..5f97ae3 100644 --- a/examples/axes.ml +++ b/examples/axes.ml @@ -9,6 +9,6 @@ let _ = background (255, 255, 255, 255); let c = circle 50 in set_color (0, 0, 0); - show [c]; + show [ c ]; (* Write to PNG! *) write ~filename:"axes.png" () diff --git a/examples/canvas.ml b/examples/canvas.ml new file mode 100644 index 0000000..d604e03 --- /dev/null +++ b/examples/canvas.ml @@ -0,0 +1,8 @@ +open Joy.Canvas + +let () = + init (); + background (255, 255, 255, 255); + let c = circle 100 in + set_color (0, 0, 0); + show [ c ] diff --git a/examples/dune b/examples/dune index 1c42610..072dd87 100644 --- a/examples/dune +++ b/examples/dune @@ -102,3 +102,9 @@ (name donut_with_scale) (modules donut_with_scale) (libraries joy)) + +(executable + (name canvas) + (modes js) + (modules canvas) + (libraries joy)) diff --git a/index.html b/index.html new file mode 100644 index 0000000..4e39f14 --- /dev/null +++ b/index.html @@ -0,0 +1,12 @@ + + + + + + Joy + + +
+ + + diff --git a/lib/canvas.ml b/lib/canvas.ml index 8225376..4432ef3 100644 --- a/lib/canvas.ml +++ b/lib/canvas.ml @@ -19,7 +19,7 @@ module Canvas : Modules.Backend = struct axes : bool; } - let context : context option ref = ref None + let context = ref None exception Context of string @@ -179,7 +179,7 @@ module Canvas : Modules.Backend = struct begin_path ctx; List.iter (fun pair -> - let Shape.{ x = x1; y = y1 }, Shape.{ x = x2; y = y2 } = + let { x = x1; y = y1 }, { x = x2; y = y2 } = (List.nth pair 0, List.nth pair 1) in ctx##moveTo x1 y1; @@ -205,11 +205,11 @@ module Canvas : Modules.Backend = struct let show shapes = let rec render' context = function - | Shape.Circle circle' -> draw_circle context circle' - | Shape.Ellipse ellipse' -> draw_ellipse context ellipse' - | Shape.Line line' -> draw_line context line' - | Shape.Polygon polygon' -> draw_polygon context polygon' - | Shape.Complex complex' -> List.iter (render' context) complex' + | Circle circle' -> draw_circle context circle' + | Ellipse ellipse' -> draw_ellipse context ellipse' + | Line line' -> draw_line context line' + | Polygon polygon' -> draw_polygon context polygon' + | Complex complex' -> List.iter (render' context) complex' in match !context with | Some ctx -> List.iter (render' ctx.context) shapes