Skip to content

Commit

Permalink
fmt, cleanup, index.html, failing example
Browse files Browse the repository at this point in the history
  • Loading branch information
FayCarsons committed Feb 7, 2024
1 parent e80b4a3 commit 0fafbb0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
profile = default
version = 0.26.0
version = 0.26.1
2 changes: 1 addition & 1 deletion examples/axes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ()
8 changes: 8 additions & 0 deletions examples/canvas.ml
Original file line number Diff line number Diff line change
@@ -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 ]
6 changes: 6 additions & 0 deletions examples/dune
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@
(name donut_with_scale)
(modules donut_with_scale)
(libraries joy))

(executable
(name canvas)
(modes js)
(modules canvas)
(libraries joy))
12 changes: 12 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Joy</title>
</head>
<body class="bg-slate-50 m-0 p-0">
<div id="root" class="bg-slate-50"></div>
<script type="module" src="./_build/default/examples/canvas.bc.js"></script>
</body>
</html>
14 changes: 7 additions & 7 deletions lib/canvas.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 0fafbb0

Please sign in to comment.