Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canvas backend and module functors #98

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions examples/axes.ml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
(* simple example demonstrating drawing x and y axes for debugging or plots *)
open Joy

open Joy.Svg

let _ =
(* intialize rendering context with the axes flag set to true *)
init ~axes:true ();
(* set background to opaque white *)
let c = circle 50 in
render c;
show [ c ];
(* Write to PNG! *)
write ~filename:"axes.png" ()
7 changes: 7 additions & 0 deletions examples/canvas.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
open Joy.Canvas

let () =
init ~size:(400, 400) ();
let c = circle 100 in
let r = rectangle 200 150 in
show [ c; r ]
4 changes: 2 additions & 2 deletions examples/circle.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Joy
open Joy.Svg

let () =
init ();
let c = circle 50 in
render c;
show [ c ];
write ~filename:"circle.png" ()
6 changes: 2 additions & 4 deletions examples/circle_packing.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Joy
open Joy.Svg

(* global constants // RNG initialization *)
let w, h = (900., 900.)
Expand Down Expand Up @@ -94,9 +94,7 @@ let () =
let circles =
List.map
(fun ((x, y), radius) ->
circle
~c:{x; y}
(int_of_float radius)
circle ~c:{ x; y } (int_of_float radius)
|> with_stroke (rand_nth palette))
concentric
in
Expand Down
2 changes: 1 addition & 1 deletion examples/circle_row_joy.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Joy
open Joy.Svg

let () =
init ();
Expand Down
4 changes: 2 additions & 2 deletions examples/color.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Joy
open Joy.Svg

let _ =
init ();
let c = circle 50 |> with_stroke red in
render c;
show [ c ];
write ~filename:"color.png" ()
2 changes: 1 addition & 1 deletion examples/complex.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Joy
open Joy.Svg

(*
Complex shapes can also be created from lists of shapes.
Expand Down
4 changes: 2 additions & 2 deletions examples/concentric_circles.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Joy
open Joy.Svg

let () =
init ();
Expand All @@ -12,5 +12,5 @@ let () =
| _, _ -> arr
in
let circles = complex (make_concentric [] 21) in
render circles;
show [ circles ];
write ~filename:"concentric_circles.png" ()
2 changes: 1 addition & 1 deletion examples/donut_with_scale.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Joy
open Joy.Svg

let () =
init ();
Expand Down
6 changes: 6 additions & 0 deletions examples/dune
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@
(modules donut_with_scale)
(libraries joy))

(executable
(name canvas)
(modes js)
(modules canvas)
(libraries joy))

(executable
(name color)
(modules color)
Expand Down
4 changes: 2 additions & 2 deletions examples/ellipse.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
open Joy
open Joy.Svg

let () =
init ();
(* create an ellipse *)
let e = ellipse 100 75 in
(* render it *)
render e;
show [ e ];
write ~filename:"ellipse.png" ()
4 changes: 2 additions & 2 deletions examples/higher_transforms.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Joy
open Joy.Svg

(* Higher order transformations can be composed with `comp`,
which applies its function args right-to-left.
Expand All @@ -10,5 +10,5 @@ let () =
init ();
let initial = rectangle ~c:(point (-250) (-250)) 100 100 in
let shapes = repeat 32 transform initial in
render shapes;
show [ shapes ];
write ~filename:"higher_transforms.png" ()
2 changes: 1 addition & 1 deletion examples/line.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Joy
open Joy.Svg

let size = 800
let interval = 16
Expand Down
4 changes: 2 additions & 2 deletions examples/polygon.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Joy
open Joy.Svg

let size = 100.

Expand All @@ -8,5 +8,5 @@ let () =
polygon
[ { x = -.size; y = 0. }; { x = 0.; y = size }; { x = size; y = 0. } ]
in
render poly;
show [ poly ];
write ~filename:"polygon.png" ()
2 changes: 1 addition & 1 deletion examples/rectangle.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Joy
open Joy.Svg

let () =
init ();
Expand Down
2 changes: 1 addition & 1 deletion examples/rectangle_canvas.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Joy
open Joy.Svg

let () =
init ~size:(500, 300) ();
Expand Down
4 changes: 2 additions & 2 deletions examples/repeat.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Joy
open Joy.Svg

(*
demonstration of the repeat function
Expand All @@ -12,5 +12,5 @@ let () =
init ();
let circle = circle ~c:(point (-100) 0) 50 in
let shapes = repeat 10 (translate 10 0) circle in
render shapes;
show [ shapes ];
write ~filename:"repeat.png" ()
2 changes: 1 addition & 1 deletion examples/rotate.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Joy
open Joy.Svg

let max = 32.
let rec range a b = if a > b then [] else a :: range (a +. 1.) b
Expand Down
2 changes: 1 addition & 1 deletion examples/square.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Joy
open Joy.Svg

let () =
init ();
Expand Down
4 changes: 2 additions & 2 deletions examples/star.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Joy
open Joy.Svg

let outer_radius = 200.
let inner_radius = 80.
Expand All @@ -18,5 +18,5 @@ let () =
init ();
set_line_width 3;
let star = List.init points star_section |> List.flatten |> polygon in
render star;
show [ star ];
write ~filename:"star.png" ()
2 changes: 1 addition & 1 deletion examples/translate_circle.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Joy
open Joy.Svg

let () =
init ();
Expand Down
2 changes: 1 addition & 1 deletion examples/translate_ellipse.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Joy
open Joy.Svg

let () =
init ();
Expand Down
2 changes: 1 addition & 1 deletion examples/translate_rectangle.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Joy
open Joy.Svg

let () =
init ();
Expand Down
4 changes: 2 additions & 2 deletions examples/triangle.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Joy
open Joy.Svg

let size = 100.

Expand All @@ -8,5 +8,5 @@ let () =
polygon
[ { x = -.size; y = 0. }; { x = 0.; y = size }; { x = size; y = 0. } ]
in
render triangle;
show [ triangle ];
write ~filename:"triangle.png" ()
11 changes: 11 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!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>
<script type="module" src="./_build/default/examples/canvas.bc.js"></script>
</body>
</html>
Loading
Loading