diff --git a/examples/complex.ml b/examples/complex.ml index 6619283..615d15a 100644 --- a/examples/complex.ml +++ b/examples/complex.ml @@ -28,7 +28,6 @@ let () = (fun (x, y) -> circle ~c:(point (x * radius) (y * radius)) radius) coords) in - let complex_shape = circle 50 :: complex_shape in (* translating that complex shape by radius / 2 *) let complex_transformed = translate half_radius half_radius complex_shape in show [ complex_shape; complex_transformed ]; diff --git a/lib/context.ml b/lib/context.ml index db3f007..7c46d92 100644 --- a/lib/context.ml +++ b/lib/context.ml @@ -21,73 +21,30 @@ let () = match e with Context err -> Some ("Context: " ^ err) | _ -> None) let fail () = raise (Context "not initialized") -<<<<<<< HEAD - -<<<<<<< HEAD -let init_context line_width (w, h) axes = - (* Fail if context has already been instantiated *) - if Option.is_some !context then - raise (Context "Cannot initialize context twice"); - - let surface = Cairo.Image.create Cairo.Image.ARGB32 ~w ~h in - let ctx = Cairo.create surface in - Cairo.set_line_width ctx line_width; - Cairo.translate ctx (w / 2 |> float_of_int) (h / 2 |> float_of_int); - context := Some { ctx; surface; size = (w, h); axes } let resolution () = match !context with Some ctx -> ctx.size | None -> fail () let tmap3 f (a, b, c) = (f a, f b, f c) let tmap4 f (a, b, c, d) = (f a, f b, f c, f d) -let scale_color_channel x = x /. 256. -let scale_color_channel = float_of_int >> scale_color_channel - -let tmap3 f (a, b, c) = (f a, f b, f c) -let tmap4 f (a, b, c, d) = (f a, f b, f c, f d) -let scale_channel n = float_of_int n /. 255. +let (>>) f g x = g (f x) +let scale_channel n = n /. 255. +let scale_color_channel = float_of_int >> scale_channel let set_color color = match !context with | Some ctx -> let r, g, b = tmap3 scale_color_channel color in -<<<<<<< HEAD Cairo.set_source_rgb ctx.ctx r g b -======= - Cairo.set_source_rgba ctx.ctx r g b 1. ->>>>>>> 9b47680 (dune fmt) | None -> fail () (* sets background color *) let background color = match !context with - | Some { ctx; _ } -> + | Some { ctx; _ } -> let r, g, b, alpha = tmap4 scale_color_channel color in Cairo.set_source_rgb ctx r g b; Cairo.paint ctx ~alpha; Cairo.fill ctx -======= -======= ->>>>>>> 40ac680 (added stroke and fill fields, 'with' fns to add them to shapes, and map fns for applying fns to those fields) -let resolution () = match !context with Some ctx -> ctx.size | None -> fail () -let tmap3 f (a, b, c) = (f a, f b, f c) -let tmap4 f (a, b, c, d) = (f a, f b, f c, f d) -let scale_channel n = float_of_int n /. 255. - -(* sets background color *) -let background color = - match !context with - | Some ctx -> - let r, g, b, a = tmap4 scale_channel color in - Cairo.set_source_rgba ctx.ctx r g b a; - Cairo.paint ctx.ctx ->>>>>>> b1a2518 (merging w/ main branch) - | None -> fail () - -let set_color color = - match !context with - | Some ctx -> - let r, g, b = tmap3 scale_channel color in - Cairo.set_source_rgba ctx.ctx r g b 1. - | None -> fail () + | None -> fail () (** Sets the width of lines for both stroke of shapes and line primitives. Can be any positive integer, with larger numbers producing thicker lines. diff --git a/lib/joy.ml b/lib/joy.ml index ae023ef..49d18b7 100644 --- a/lib/joy.ml +++ b/lib/joy.ml @@ -5,13 +5,8 @@ type shape = Shape.shape type shapes = Shape.shapes type transformation = Transform.transformation -type color = Color.color -<<<<<<< HEAD -<<<<<<< HEAD -======= -======= (** Three-tuple representing a 24-bit RGB color *) ->>>>>>> 40ac680 (added stroke and fill fields, 'with' fns to add them to shapes, and map fns for applying fns to those fields) +type color = Color.color let black = Color.black let white = Color.white @@ -21,11 +16,7 @@ let blue = Color.blue let yellow = Color.yellow let transparent = Color.transparent let opaque = Color.opaque -<<<<<<< HEAD ->>>>>>> b1a2518 (merging w/ main branch) -======= ->>>>>>> 40ac680 (added stroke and fill fields, 'with' fns to add them to shapes, and map fns for applying fns to those fields) let point = Shape.point let circle = Shape.circle let rectangle = Shape.rectangle