on f20fa4e help sign in
elk/libraries/Transform2D.elm
57 lines 1.6 kB history raw
1module Transform2D where
2{-| A library for performing [2D matrix transformations](http://en.wikipedia.org/wiki/Transformation_matrix#Affine_transformations).
3It is used primarily with the `groupTransform` function from `Graphics.Collage` and
4allows you to do things like rotation, scaling, translation, shearing, and reflection.
6# Basic Transforms
7@docs identity, matrix, rotation
9# Multiplication
10@docs multiply
11-}
13import Native.Transform2D
15data Transform2D = Transform2D
17{-| Create an identity transform. Transforming by the identity does
18not change anything, but it can come in handy as a default or
19base case.
21 / 1 0 \
22 \ 0 1 /
23-}
24identity : Transform2D
25identity = Native.Transform2D.identity
27{-| Creates a transformation matrix. This lets you create transforms
28such as scales, shears, reflections, and translations.
30 matrix a b c d dx dy
32 / a b \
33 \ c d /
35And `dx` and `dy` are the translation values.
36-}
37matrix : Float -> Float -> Float -> Float -> Float -> Float -> Transform2D
38matrix = Native.Transform2D.matrix
40{-| Creates a [rotation matrix](http://en.wikipedia.org/wiki/Rotation_matrix).
41Given an angle t, it creates a counterclockwise rotation matrix:
43 / cos t -sin t \
44 \ sin t cos t /
45-}
46rotation : Float -> Transform2D
47rotation = Native.Transform2D.rotation
49{-| Multiplies two transforms together:
51 multiply a b
53 / a11 a12 \ . / b11 b12 \
54 \ a21 a22 / \ b21 b22 /
55-}
56multiply : Transform2D -> Transform2D -> Transform2D
57multiply = Native.Transform2D.multiply