0 | module Web.MVC.Canvas.Transformation
4 | import Web.MVC.Canvas.Angle
11 | data Transformation : Type where
13 | Transform : (a,b,c,d,e,f : Double) -> Transformation
16 | scale : (h,w : Double) -> Transformation
17 | scale h w = Transform h 0 0 w 0 0
20 | rotate : Angle -> Transformation
22 | let r := toRadians phi
25 | in Transform c s (-s) c 0 0
28 | translate : (dx,dy : Double) -> Transformation
29 | translate dx dy = Transform 0 0 0 0 dx dy
32 | mult : Transformation -> Transformation -> Transformation
35 | mult (Transform a1 b1 c1 d1 e1 f1) (Transform a2 b2 c2 d2 e2 f2) =
41 | (a1 * e2 + c1 * f2 + e1)
42 | (b1 * e2 + d1 * f2 + f1)
45 | Semigroup Transformation where
49 | Monoid Transformation where
57 | apply : CanvasRenderingContext2D -> Transformation -> JSIO ()
58 | apply ctxt Id = pure ()
59 | apply ctxt (Transform a b c d e f) = setTransform ctxt a b c d e f