Skip to content

Commit

Permalink
applied some reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
FayCarsons committed Jan 16, 2024
1 parent ddd6677 commit 46c47a1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
16 changes: 7 additions & 9 deletions examples/axes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ open Joy
let _ =
(* intialize rendering context with the axes flag set to true *)
init ~axes:true ();
background (255, 255, 255, 255)
;;

(* set background to opaque white *)
let c = circle 50 in
set_color (0, 0, 0);
render c;
(* Write to PNG! *)
write ~filename:"axes.png" ()
(* set background to opaque white *)
background (255, 255, 255, 255);
let c = circle 50 in
set_color (0, 0, 0);
render c;
(* Write to PNG! *)
write ~filename:"axes.png" ()
21 changes: 9 additions & 12 deletions examples/line.ml
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
open Joy

let size = 800
let interval = 16.
let line_interval = 800. /. interval
let rec range a b = if a > b then [] else a :: range (a +. 1.) b
let inc x = x +. 1.
let interval = 16
let line_interval = 800 / interval
let rec range a b = if a > b then [] else a :: range (a + 1) b
let inc x = x + 1

let _ =
init ~size:(size, size) ();
let half_size = float_of_int size /. 2. in
let half_size = size / 2 in
background (255, 255, 255, 255);
let lines =
List.map
(fun i ->
let newx = i |> inc |> ( *. ) line_interval in
let newx = i |> inc |> ( * ) line_interval in
line
~a:
(point
(int_of_float (newx -. half_size))
(int_of_float (-.half_size)))
(point (int_of_float (newx -. half_size)) (int_of_float half_size)))
(range 0. interval)
~a:(point (newx - half_size) (-half_size))
(point (newx - half_size) half_size))
(range 0 interval)
in
set_color (0, 0, 0);
show lines;
Expand Down
6 changes: 5 additions & 1 deletion lib/render.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ let scale_point size point =
let x, y = (x /. fst size, y /. snd size) in
(x, y)

let euclid_norm (x, y) = (sqrt (Float.pow x 2. +. Float.pow y 2.) /. 2.)

let draw_circle ctx ({ c; radius } : circle) =
let size = tmap float_of_int ctx.size in
let x, y = scale_point size c in
let radius = radius /. min (fst size) (snd size) in
let radius =
radius /. euclid_norm size
in
Cairo.arc ctx.ctx x y ~r:radius ~a1:0. ~a2:(Float.pi *. 2.);
Cairo.stroke ctx.ctx

Expand Down

0 comments on commit 46c47a1

Please sign in to comment.