Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
FayCarsons committed Oct 27, 2023
1 parent 648dc6c commit 66df79e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
4 changes: 2 additions & 2 deletions examples/dune
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
(modules complex)
(libraries joy))

(executable
(executable
(name repeat)
(modules repeat)
(libraries joy))
(libraries joy))
20 changes: 10 additions & 10 deletions examples/repeat.ml
Original file line number Diff line number Diff line change
@@ -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 ();
close ()
12 changes: 5 additions & 7 deletions lib/shape.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 () =
Expand Down

0 comments on commit 66df79e

Please sign in to comment.