Try to fuse functions over pictures (overPos and overCol)

This commit is contained in:
2021-03-01 12:36:57 +01:00
parent bb05bcaaf1
commit f68b8be9ce
3 changed files with 16 additions and 6 deletions
+7 -5
View File
@@ -88,7 +88,7 @@ polygonCol = PolygonCol 0
color :: RGBA -> Picture -> Picture
{-# INLINE color #-}
color c pic = Color c pic
color c pic = OverPic id id (const c) pic
translate3 :: Float -> Float -> Point3 -> Point3
{-# INLINE translate3 #-}
@@ -96,11 +96,11 @@ translate3 a b (x,y,z) = (x+a,y+b,z)
translate :: Float -> Float -> Picture -> Picture
{-# INLINE translate #-}
translate x y pic = Translate x y pic
translate x y pic = OverPic (translate3 x y) id id pic
setDepth :: Float -> Picture -> Picture
{-# INLINE setDepth #-}
setDepth d pic = SetDepth d pic
setDepth d pic = OverPic (\(x,y,_) -> (x,y,-d)) id id pic
setLayer :: Int -> Picture -> Picture
setLayer _ Blank = Blank
@@ -115,6 +115,7 @@ setLayer i (Rotate x p) = Rotate x $ setLayer i p
setLayer i (SetDepth x p) = SetDepth x $ setLayer i p
setLayer i (Color x p) = Color x $ setLayer i p
setLayer i (Pictures p) = Pictures $ map (setLayer i) p
setLayer i (OverPic f f' f'' pic) = OverPic f f' f'' (setLayer i pic)
scale3 :: Float -> Float -> Point3 -> Point3
@@ -123,15 +124,16 @@ scale3 a b (x,y,z) = (x*a,y*b,z)
scale :: Float -> Float -> Picture -> Picture
{-# INLINE scale #-}
scale x y pic = Scale x y pic
scale x y pic = OverPic (scale3 x y) ((*) x) id pic
rotate3 :: Float -> Point3 -> Point3
{-# INLINE rotate3 #-}
rotate3 a (x,y,z) = (x',y',z)
where (x',y') = rotateV a (x,y)
rotate = Rotate
rotate :: Float -> Picture -> Picture
{-# INLINE rotate #-}
rotate a pic = OverPic (rotate3 a) id id pic
--rotateRad a = Rotate a
--{-# INLINE rotateRad #-}