Skip to content

Commit

Permalink
cleanup and adding explanatory comments
Browse files Browse the repository at this point in the history
  • Loading branch information
FayCarsons committed Dec 18, 2023
1 parent 4f7e93e commit 7787c84
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions examples/cairo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ let get_dimensions () =
let set_color color =
match !context with
| Some ctx ->
let r, g, b = color in
Cairo.set_source_rgb ctx.ctx r g b
let r, g, b, a = color in
Cairo.set_source_rgba ctx.ctx r g b a
| None -> failwith fail

let background color =
Expand All @@ -72,12 +72,14 @@ let background color =
Cairo.paint ctx.ctx
| None -> failwith fail

(* Scales points from 0 - image size to 0-1 *)
let scale_point size point =
let { x; y } = point in
let x, y = (x /. size.x, y /. size.y) in
List.iter (fun n -> print_float n |> print_newline) [ x; y ];
(x, y)

(* Shape rendering fns *)
let draw_circle ctx (circle : circle) =
let x, y = scale_point ctx.size circle.c in
let radius = circle.radius /. min ctx.size.x ctx.size.y in
Expand Down Expand Up @@ -159,9 +161,6 @@ let draw () =
let c = { x = w /. 2.; y = h /. 2. } in
let circle = Circle { c; radius = 100. } in
let rect = Rectangle { c; width = w /. 4.; height = h /. 4. } in
let _cartesian_product l l' =
List.concat (List.map (fun e -> List.map (fun e' -> (e, e')) l') l)
in
let polygon =
Polygon
(List.map
Expand All @@ -185,7 +184,7 @@ let init ?size ?filename () =
let filename = match filename with Some s -> s | None -> "cairo.png" in
init_context (x, y) filename;
background (1., 1., 1.);
set_color (0., 0., 0.);
set_color (0., 0., 0., 1.);
draw ()

let () = init ()

0 comments on commit 7787c84

Please sign in to comment.