{-# LANGUAGE RecordWildCards #-}
module Graphics.Data.Image
( Image(..)
, rotate
)
where
import Data.Angle
import qualified Graphics.Gloss as G
data Image = Image {width :: Float ,
height :: Float ,
shapes :: [(G.Picture, G.Point)]
} deriving Eq
rotate
:: Float
-> Image
-> Image
rotate deg Image {..} = Image newW newH
$ map (\(p, c) -> (G.rotate (negate deg) p, rotateC c)) shapes
where
newW =
width
* (abs . sine . Degrees $ 90 - deg)
+ height
* (abs . sine . Degrees $ deg)
newH =
width
* (abs . sine . Degrees $ deg)
+ height
* (abs . sine . Degrees $ 90 - deg)
rotateC :: (Float, Float) -> (Float, Float)
rotateC (x, y) =
( x * (cosine . Degrees $ deg) + y * (negate . sine . Degrees $ deg)
, x * (sine . Degrees $ deg) + y * (cosine . Degrees $ deg)
)