diff --git a/examples/dune b/examples/dune index a17bc36..79c8e10 100644 --- a/examples/dune +++ b/examples/dune @@ -98,7 +98,7 @@ (modules complex) (libraries joy)) -(executable +(executable (name repeat) (modules repeat) - (libraries joy)) \ No newline at end of file + (libraries joy)) diff --git a/examples/repeat.ml b/examples/repeat.ml index 8224038..739be62 100644 --- a/examples/repeat.ml +++ b/examples/repeat.ml @@ -1,16 +1,16 @@ -open Joy.Shape +open Joy.Shape -(* - demonstration of the repeat function - takes n, an operation, and an initial shape, and applies the operation - iteratively to the initial shape n times - - adapted from the original Joy python library's examples +(* + demonstration of the repeat function + takes n, an operation, and an initial shape, and applies the operation + iteratively to the initial shape n times + + adapted from the original Joy python library's examples *) let () = init (); - let circle = circle ~x: (-100) ~y: 0 50 in - let shapes = repeat 10 (translate 10 0) circle in + let circle = circle ~x:(-100) ~y:0 50 in + let shapes = repeat 10 (translate 10 0) circle in render_shape shapes; - close (); \ No newline at end of file + close () diff --git a/lib/shape.ml b/lib/shape.ml index a8c6e9d..9dc0901 100644 --- a/lib/shape.ml +++ b/lib/shape.ml @@ -135,15 +135,13 @@ let rec rotate degrees shape = | Complex shapes -> Complex (List.map (rotate degrees) shapes) let compose f g x = g (f x) +let rec range a b = if a >= b then [] else a :: range (a + 1) b -let rec range a b = if a >= b then [] else a :: range (a + 1) b -let repeat n op shape = - let match_list l = - match l with - | [] -> [ op shape ] - | last :: _ -> op last :: l +let repeat n op shape = + let match_list l = + match l with [] -> [ op shape ] | last :: _ -> op last :: l in - let shapes = List.fold_right (fun _ acc -> match_list acc) (range 0 n) [] in + let shapes = List.fold_right (fun _ acc -> match_list acc) (range 0 n) [] in complex shapes let render_axes () =