diff --git a/examples/translate_rectangle.ml b/examples/translate_rectangle.ml index cf5b984..4d0bc42 100644 --- a/examples/translate_rectangle.ml +++ b/examples/translate_rectangle.ml @@ -3,11 +3,11 @@ open Joy let () = init (); background (255, 255, 255, 255); - (* Create rectangle transform *) + (* Create rectangle transformation *) let r1 = rectangle 200 100 in let r2 = translate 100 0 r1 in - (* Display rectangle transform *) + (* Display rectangle transformation *) set_color (0, 0, 0); show [ r1; r2 ]; write ~filename:"translate_rectangle.png" () diff --git a/lib/joy.ml b/lib/joy.ml index 1096e11..6c38900 100644 --- a/lib/joy.ml +++ b/lib/joy.ml @@ -4,6 +4,8 @@ type 'a point = 'a Shape.point type shape = Shape.shape type shapes = Shape.shapes +type transformation = Transform.transformation + let point = Shape.point let circle = Shape.circle let rectangle = Shape.rectangle diff --git a/lib/joy.mli b/lib/joy.mli index d612149..d7b39f4 100644 --- a/lib/joy.mli +++ b/lib/joy.mli @@ -2,6 +2,8 @@ type 'a point = 'a Shape.point type shape = Shape.shape type shapes = Shape.shapes +type transformation = Transform.transformation + val point : int -> int -> float point val circle : ?c:float point -> int -> shape val rectangle : ?c:float point -> int -> int -> shape @@ -9,11 +11,11 @@ val ellipse : ?c:float point -> int -> int -> shape val line : ?a:float point -> float point -> shape val polygon : float point list -> shape val complex : shapes -> shape -val rotate : int -> shape -> shape -val translate : int -> int -> shape -> shape -val scale : float -> shape -> shape -val compose : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c -val repeat : int -> (shape -> shape) -> shape -> shape +val rotate : int -> transformation +val translate : int -> int -> transformation +val scale : float -> transformation +val compose : transformation -> transformation -> transformation +val repeat : int -> transformation -> transformation val context : Context.context option ref val set_color : int * int * int -> unit val background : int * int * int * int -> unit diff --git a/lib/transform.ml b/lib/transform.ml index 24831f5..29cd29b 100644 --- a/lib/transform.ml +++ b/lib/transform.ml @@ -1,5 +1,7 @@ open Shape +type transformation = (shape -> shape) + let rec translate dx dy shape = match shape with | Circle circle -> diff --git a/lib/transform.mli b/lib/transform.mli index 4dde434..6fa2fa1 100644 --- a/lib/transform.mli +++ b/lib/transform.mli @@ -1,5 +1,7 @@ -val translate : int -> int -> Shape.shape -> Shape.shape -val scale : float -> Shape.shape -> Shape.shape -val rotate : int -> Shape.shape -> Shape.shape -val compose : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c -val repeat : int -> (Shape.shape -> Shape.shape) -> Shape.shape -> Shape.shape +type transformation = (Shape.shape -> Shape.shape) + +val translate : int -> int -> transformation +val scale : float -> transformation +val rotate : int -> transformation +val compose : transformation -> transformation -> transformation +val repeat : int -> transformation -> transformation