Skip to content

Commit

Permalink
Merge branch 'main' into int_api
Browse files Browse the repository at this point in the history
  • Loading branch information
nikochiko committed Jan 16, 2024
2 parents 46c47a1 + 7f4ab94 commit e8d7783
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
8 changes: 8 additions & 0 deletions examples/donut_with_scale.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
open Joy

let () =
init ();
let c = circle 100. in
let hole = scale 0.5 c in
show [ c; hole ];
write ~filename:"donut_with_scale.png" ()
10 changes: 10 additions & 0 deletions examples/dune
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
(modules rectangle)
(libraries joy))

(executable
(name rectangle_canvas)
(modules rectangle_canvas)
(libraries joy))

(executable
(name star)
(modules star)
Expand All @@ -87,3 +92,8 @@
(name repeat)
(modules repeat)
(libraries joy))

(executable
(name donut_with_scale)
(modules donut_with_scale)
(libraries joy))
9 changes: 9 additions & 0 deletions examples/rectangle_canvas.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
open Joy

let () =
init ~size:(500., 300.) ();
background (1., 1., 1., 1.);
let c = circle 50. in
set_color (0., 0., 0.);
show [ c ];
write ~filename:"rectangular_canvas.png" ()
2 changes: 2 additions & 0 deletions lib/shape.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ let ( /~ ) p1 p2 = { x = p1.x /. p2.x; y = p1.x /. p2.x }
let ( -! ) { x; y } scalar = { x = x -. scalar; y = y -. scalar }
let ( /! ) { x; y } scalar = { x = x /. scalar; y = y /. scalar }
let ( *! ) { x; y } scalar = { x = x *. scalar; y = y *. scalar }

let pmap f { x; y } = { x = f x; y = f y }

let point x y =
Expand All @@ -29,6 +30,7 @@ let point x y =
let center = { x = 0.; y = 0. }
let circle ?(c = center) r = Circle { c; radius = float_of_int r }


let rectangle ?(c = center) width height =
let width, height = (float_of_int width, float_of_int height) in
let { x; y } = c -! ((width +. height) /. 4.) in
Expand Down
4 changes: 2 additions & 2 deletions lib/transform.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ let rec translate dx dy shape =
| Complex shapes -> Complex (List.map (translate dx dy) shapes)

let rec scale factor s =
let scale_length fact len = len *. sqrt fact in
let scale_point fact pt = pt *! sqrt fact in
let scale_length fact len = len *. fact in
let scale_point fact pt = pt *! fact in
match s with
| Circle circle' ->
Circle
Expand Down

0 comments on commit e8d7783

Please sign in to comment.