Use V2 instead of tuples and rename 'sceneAnimation' to 'scene'. (#165)

This commit is contained in:
David Himmelstrup 2020-09-19 22:17:51 +08:00 committed by GitHub
commit d37e71ca94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
68 changed files with 140 additions and 214 deletions

View file

@ -6,6 +6,6 @@ import Reanimate
-- This should give circle. -- This should give circle.
main :: IO () main :: IO ()
main = reanimate $ signalA (constantS 0) $ sceneAnimation $ do main = reanimate $ signalA (constantS 0) $ scene $ do
play $ animate $ const $ mkCircle 1 play $ animate $ const $ mkCircle 1
play $ animate $ const $ mkRect 1 1 play $ animate $ const $ mkRect 1 1

View file

@ -6,6 +6,6 @@ import Reanimate
-- This should give rect. -- This should give rect.
main :: IO () main :: IO ()
main = reanimate $ signalA (constantS 0.5) $ sceneAnimation $ do main = reanimate $ signalA (constantS 0.5) $ scene $ do
play $ animate $ const $ mkCircle 1 play $ animate $ const $ mkCircle 1
play $ animate $ const $ mkRect 1 1 play $ animate $ const $ mkRect 1 1

View file

@ -6,6 +6,6 @@ import Reanimate
-- This should give rect. -- This should give rect.
main :: IO () main :: IO ()
main = reanimate $ signalA (constantS 1) $ sceneAnimation $ do main = reanimate $ signalA (constantS 1) $ scene $ do
play $ animate $ const $ mkCircle 1 play $ animate $ const $ mkCircle 1
play $ animate $ const $ mkRect 1 1 play $ animate $ const $ mkRect 1 1

View file

@ -8,7 +8,7 @@ import Reanimate.Morph.Common
import Reanimate.Morph.Linear import Reanimate.Morph.Linear
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
play $ animate $ \t -> morph rawLinear src dst t play $ animate $ \t -> morph rawLinear src dst t
where where
src = mkPathString "M 0 0 q 1 1, 2 0 z" src = mkPathString "M 0 0 q 1 1, 2 0 z"

View file

@ -23,7 +23,7 @@ import Codec.Picture.Types
import qualified Data.Vector as V import qualified Data.Vector as V
main :: IO () main :: IO ()
main = reanimate $ sceneAnimation $ do main = reanimate $ scene $ do
newSpriteSVG_ $ mkBackgroundPixel rtfdBackgroundColor newSpriteSVG_ $ mkBackgroundPixel rtfdBackgroundColor
play $ trails 0.05 starAnimation play $ trails 0.05 starAnimation

View file

@ -6,7 +6,7 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
s <- fork $ newSpriteA drawBox s <- fork $ newSpriteA drawBox
v <- newVar 0 v <- newVar 0
applyVar v s rotate applyVar v s rotate

View file

@ -8,7 +8,7 @@ import Reanimate.Scene
import Control.Lens import Control.Lens
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
cam <- newObject Camera cam <- newObject Camera
circ <- newObject $ Circle 2 circ <- newObject $ Circle 2
oModifyS circ $ oModifyS circ $

View file

@ -6,20 +6,21 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
import Reanimate.Scene import Reanimate.Scene
import Control.Lens import Control.Lens
import Linear.V2
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
cam <- newObject Camera cam <- newObject Camera
circ <- newObject $ Circle 2; oShow circ circ <- newObject $ Circle 2; oShow circ
oModify circ $ oTranslate .~ (-3,0) oModify circ $ oTranslate .~ V2 (-3) 0
box <- newObject $ Rectangle 4 4; oShow box box <- newObject $ Rectangle 4 4; oShow box
oModify box $ oTranslate .~ (3,0) oModify box $ oTranslate .~ V2 3 0
cameraAttach cam circ cameraAttach cam circ
cameraAttach cam box cameraAttach cam box
cameraFocus cam (-3,0) cameraFocus cam (V2 (-3) 0)
cameraZoom cam 2 2 cameraZoom cam 2 2
cameraZoom cam 2 1 cameraZoom cam 2 1
cameraFocus cam (3,0) cameraFocus cam (V2 3 0)
cameraZoom cam 2 2 cameraZoom cam 2 2
cameraZoom cam 2 1 cameraZoom cam 2 1

View file

@ -6,7 +6,7 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
s <- newSpriteSVG $ withFillOpacity 1 $ mkCircle 1 s <- newSpriteSVG $ withFillOpacity 1 $ mkCircle 1
fork $ wait 1 >> destroySprite s fork $ wait 1 >> destroySprite s
play drawBox play drawBox

View file

@ -6,6 +6,6 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
fork $ play drawBox fork $ play drawBox
play drawCircle play drawCircle

View file

@ -6,6 +6,6 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
_ <- newSprite $ mkCircle <$> spriteT -- Circle sprite where radius=time. _ <- newSprite $ mkCircle <$> spriteT -- Circle sprite where radius=time.
wait 2 wait 2

View file

@ -7,7 +7,7 @@ import Reanimate.Animation
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
_ <- fork $ newSpriteA' SyncFreeze drawCircle _ <- fork $ newSpriteA' SyncFreeze drawCircle
play drawBox play drawBox
play $ reverseA drawBox play $ reverseA drawBox

View file

@ -6,7 +6,7 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
_ <- fork $ newSpriteA drawCircle _ <- fork $ newSpriteA drawCircle
play drawBox play drawBox
play $ reverseA drawBox play $ reverseA drawBox

View file

@ -6,6 +6,6 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
_ <- newSpriteSVG $ mkBackground "lightblue" _ <- newSpriteSVG $ mkBackground "lightblue"
play drawCircle play drawCircle

View file

@ -6,6 +6,6 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
play drawBox play drawBox
play drawCircle play drawCircle

View file

@ -8,7 +8,7 @@ import Reanimate.Builtin.Documentation
import qualified Data.Text as T import qualified Data.Text as T
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
now <- play drawCircle *> queryNow now <- play drawCircle *> queryNow
play $ staticFrame 1 $ scale 2 $ withStrokeWidth 0.05 $ play $ staticFrame 1 $ scale 2 $ withStrokeWidth 0.05 $
mkText $ "Now=" <> T.pack (show now) mkText $ "Now=" <> T.pack (show now)

View file

@ -6,6 +6,6 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
var <- simpleVar mkCircle 0 var <- simpleVar mkCircle 0
tweenVar var 2 $ \val -> fromToS val (screenHeight/2) tweenVar var 2 $ \val -> fromToS val (screenHeight/2)

View file

@ -6,7 +6,7 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
s <- fork $ newSpriteA drawCircle s <- fork $ newSpriteA drawCircle
spriteE s $ overBeginning 1 fadeInE spriteE s $ overBeginning 1 fadeInE
spriteE s $ overEnding 0.5 fadeOutE spriteE s $ overEnding 0.5 fadeOutE

View file

@ -6,7 +6,7 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
s <- fork $ newSpriteA drawCircle s <- fork $ newSpriteA drawCircle
wait 1 wait 1
spriteMap s flipYAxis spriteMap s flipYAxis

View file

@ -6,7 +6,7 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
-- the rect lives through the entire 3s animation -- the rect lives through the entire 3s animation
newSpriteSVG_ $ translate (-3) 0 $ mkRect 4 4 newSpriteSVG_ $ translate (-3) 0 $ mkRect 4 4
wait 1 wait 1

View file

@ -6,6 +6,6 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
s <- fork $ newSpriteA drawCircle s <- fork $ newSpriteA drawCircle
spriteTween s 1 $ \val -> translate (screenWidth*0.3*val) 0 spriteTween s 1 $ \val -> translate (screenWidth*0.3*val) 0

View file

@ -6,7 +6,7 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
s <- fork $ newSpriteA drawBox s <- fork $ newSpriteA drawBox
v <- spriteVar s 0 rotate v <- spriteVar s 0 rotate
tweenVar v 2 $ \val -> fromToS val 90 tweenVar v 2 $ \val -> fromToS val 90

View file

@ -6,7 +6,7 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
s1 <- newSpriteSVG $ withFillOpacity 1 $ withFillColor "blue" $ mkCircle 3 s1 <- newSpriteSVG $ withFillOpacity 1 $ withFillColor "blue" $ mkCircle 3
_ <- newSpriteSVG $ withFillOpacity 1 $ withFillColor "red" $ mkRect 8 3 _ <- newSpriteSVG $ withFillOpacity 1 $ withFillColor "red" $ mkRect 8 3
wait 1 wait 1

View file

@ -6,7 +6,7 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
v <- newVar 0 v <- newVar 0
_ <- newSprite $ mkCircle <$> unVar v _ <- newSprite $ mkCircle <$> unVar v
tweenVar v 1 $ \val -> fromToS val 3 tweenVar v 1 $ \val -> fromToS val 3

View file

@ -6,7 +6,7 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
fork $ play drawBox fork $ play drawBox
wait 1 wait 1
play drawCircle play drawCircle

View file

@ -6,6 +6,6 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
waitOn $ fork $ play drawBox waitOn $ fork $ play drawBox
play drawCircle play drawCircle

View file

@ -6,7 +6,7 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
main :: IO () main :: IO ()
main = reanimate $ docEnv $ sceneAnimation $ do main = reanimate $ docEnv $ scene $ do
v <- newVar 0 v <- newVar 0
_ <- newSprite $ mkCircle <$> unVar v _ <- newSprite $ mkCircle <$> unVar v
writeVar v 1; wait 1 writeVar v 1; wait 1

View file

@ -61,7 +61,7 @@ whiteGithub = withFillOpacity 1 $ withFillColor "white" $
scaleToHeight screenHeight $ center $ unpackImage githubIcon scaleToHeight screenHeight $ center $ unpackImage githubIcon
main :: IO () main :: IO ()
main = reanimate $ sceneAnimation $ do main = reanimate $ scene $ do
newSpriteSVG_ $ mkBackground "white" newSpriteSVG_ $ mkBackground "white"
-- newSpriteSVG_ $ -- newSpriteSVG_ $
-- mkClipPath "clip" $ -- mkClipPath "clip" $

View file

@ -22,7 +22,7 @@ import Graphics.SvgTree
import Reanimate import Reanimate
main :: IO () main :: IO ()
main = reanimate $ sceneAnimation $ do main = reanimate $ scene $ do
newSpriteSVG_ $ mkBackground "white" newSpriteSVG_ $ mkBackground "white"
let circles = let circles =
[ (900, 0.3) [ (900, 0.3)

View file

@ -18,7 +18,7 @@ import Geom2D.CubicBezier.Linear
import Text.Printf import Text.Printf
main :: IO () main :: IO ()
main = reanimate $ sceneAnimation $ do main = reanimate $ scene $ do
newSpriteSVG_ $ mkBackgroundPixel rtfdBackgroundColor newSpriteSVG_ $ mkBackgroundPixel rtfdBackgroundColor
newSpriteSVG_ static newSpriteSVG_ static
dotPath <- newVar (QuadBezier (V2 0 0) (V2 0 0) (V2 0 0)) dotPath <- newVar (QuadBezier (V2 0 0) (V2 0 0) (V2 0 0))

View file

@ -22,7 +22,7 @@ newWidth = 8
newHeight = 8 newHeight = 8
main :: IO () main :: IO ()
main = reanimate $ mapA squareViewBox $ sceneAnimation $ do main = reanimate $ mapA squareViewBox $ scene $ do
newSpriteSVG_ $ mkBackgroundPixel rtfdBackgroundColor newSpriteSVG_ $ mkBackgroundPixel rtfdBackgroundColor
newSpriteSVG_ static newSpriteSVG_ static
dotPath <- newVar (QuadBezier (V2 0 0) (V2 0 0) (V2 0 0)) dotPath <- newVar (QuadBezier (V2 0 0) (V2 0 0) (V2 0 0))

View file

@ -12,7 +12,7 @@ import Reanimate.LaTeX
import Reanimate.Scene import Reanimate.Scene
main :: IO () main :: IO ()
main = reanimate $ docEnv $ mapA (withFillOpacity 1) $ sceneAnimation $ do main = reanimate $ docEnv $ mapA (withFillOpacity 1) $ scene $ do
line1 <- newLaTeX ["$>$ ", "knock!", " ", "knock!"] line1 <- newLaTeX ["$>$ ", "knock!", " ", "knock!"]
oModifyMany line1 $ oModifyMany line1 $
oTopY .~ screenTop oTopY .~ screenTop

View file

@ -15,7 +15,7 @@ main = reanimate $ bg `parA` mainScene
bg = animate $ const $ mkBackground "black" bg = animate $ const $ mkBackground "black"
mainScene :: Animation mainScene :: Animation
mainScene = sceneAnimation $ mdo mainScene = scene $ mdo
play $ drawCircle play $ drawCircle
& setDuration drawCircleT & setDuration drawCircleT
& applyE (constE $ scaleXY (-1) 1) & applyE (constE $ scaleXY (-1) 1)

View file

@ -23,7 +23,7 @@ main = reanimate $
mapA (withStrokeColor "black") $ mapA (withStrokeColor "black") $
mapA (withStrokeLineJoin JoinRound) $ mapA (withStrokeLineJoin JoinRound) $
mapA (withFillOpacity 1) $ mapA (withFillOpacity 1) $
sceneAnimation $ do scene $ do
_ <- newSpriteSVG $ _ <- newSpriteSVG $
withStrokeWidth 0 $ translate (-4) 4 $ withStrokeWidth 0 $ translate (-4) 4 $
center $ latex "no-op" center $ latex "no-op"

View file

@ -19,7 +19,7 @@ main = reanimate $
setDuration 5 $ setDuration 5 $
mapA (withStrokeWidth 0) $ mapA (withStrokeWidth 0) $
mapA (withFillOpacity 1) $ mapA (withFillOpacity 1) $
sceneAnimation $ do scene $ do
doMorph yellow blue doMorph yellow blue
doMorph blue yellow doMorph blue yellow
where where

View file

@ -19,7 +19,7 @@ main = reanimate $
mapA (withStrokeWidth 0) $ mapA (withStrokeWidth 0) $
mapA (withStrokeColor "black") $ mapA (withStrokeColor "black") $
mapA (withFillOpacity 1) $ mapA (withFillOpacity 1) $
sceneAnimation $ do scene $ do
play $ step stage1 stage2 play $ step stage1 stage2
play $ step stage2 stage3 play $ step stage2 stage3
play $ step stage3 stage4 play $ step stage3 stage4

View file

@ -22,7 +22,7 @@ main = reanimate $
mapA (withStrokeColor "black") $ mapA (withStrokeColor "black") $
mapA (withStrokeLineJoin JoinRound) $ mapA (withStrokeLineJoin JoinRound) $
mapA (withFillOpacity 1) $ mapA (withFillOpacity 1) $
sceneAnimation $ scene $
showPair (stages ++ take 1 stages) showPair (stages ++ take 1 stages)
where where
showPair (from:to:rest) = showPair (from:to:rest) =

View file

@ -19,7 +19,7 @@ main = reanimate $
mapA (withStrokeWidth 0) $ mapA (withStrokeWidth 0) $
mapA (withStrokeColor "black") $ mapA (withStrokeColor "black") $
mapA (withFillOpacity 1) $ mapA (withFillOpacity 1) $
sceneAnimation $ do scene $ do
let showLabel label = do let showLabel label = do
fork $ play $ staticFrame 4 (center $ latex label) fork $ play $ staticFrame 4 (center $ latex label)
& mapA (translate 0 4) & mapA (translate 0 4)

View file

@ -26,7 +26,7 @@ main = reanimate $
mapA (withStrokeWidth 0) $ mapA (withStrokeWidth 0) $
mapA (withStrokeColor "black") $ mapA (withStrokeColor "black") $
mapA (withFillOpacity 1) $ mapA (withFillOpacity 1) $
sceneAnimation $ do scene $ do
let pl1 = translate (-4) 0 $ mkGroup let pl1 = translate (-4) 0 $ mkGroup
[ lowerTransformations $ scale 3 $ withFillOpacity 1 $ [ lowerTransformations $ scale 3 $ withFillOpacity 1 $
withStrokeColor "black" $ withStrokeColor "black" $

View file

@ -24,7 +24,7 @@ main = reanimate $
mapA (withStrokeColor "black") $ mapA (withStrokeColor "black") $
mapA (withStrokeLineJoin JoinRound) $ mapA (withStrokeLineJoin JoinRound) $
mapA (withFillOpacity 1) $ mapA (withFillOpacity 1) $
sceneAnimation $ do scene $ do
_ <- newSpriteSVG $ _ <- newSpriteSVG $
withStrokeWidth 0 $ translate (-3) 4 $ withStrokeWidth 0 $ translate (-3) 4 $
center $ latex "linear" center $ latex "linear"

View file

@ -43,7 +43,7 @@ main = reanimate $
mapA (withStrokeColor "black") $ mapA (withStrokeColor "black") $
mapA (withStrokeLineJoin JoinRound) $ mapA (withStrokeLineJoin JoinRound) $
mapA (withFillOpacity 1) $ mapA (withFillOpacity 1) $
sceneAnimation $ do scene $ do
_ <- newSpriteSVG $ _ <- newSpriteSVG $
withStrokeWidth 0 $ translate (-4) 4 $ withStrokeWidth 0 $ translate (-4) 4 $
center $ latex "linear" center $ latex "linear"

View file

@ -7,101 +7,10 @@ import Reanimate
import Reanimate.Builtin.Documentation import Reanimate.Builtin.Documentation
import Reanimate.Scene import Reanimate.Scene
import Control.Lens import Control.Lens
import Linear.V2
main :: IO () main :: IO ()
{- main = reanimate $ docEnv $ mapA (withFillOpacity 1) $ scene $ do
main = reanimate $ docEnv $ mapA (withFillOpacity 1) $ sceneAnimation $ do
cam <- newObject Camera
newSpriteSVG_ $ withStrokeWidth (defaultStrokeWidth*0.5) $ mkGroup
[ mkLine (0, screenBottom) (0, screenTop)
, mkLine (screenLeft, 0) (screenRight, 0)
]
box <- newObject $ Rectangle 1 1
cameraAttach cam box
oModify box $ oContext .~ withFillColor "green"
oModify box $ oMargin .~ (0,0,0,0)
oModify box $ oLeftX .~ 0
oModify box $ oBottomY .~ 0
oModify box $ oContext .~ withStrokeWidth 0
box2 <- newObject $ Rectangle 1 1
cameraAttach cam box2
oModify box2 $ oContext .~ withFillColor "blue"
oModify box2 $ oMargin .~ (0,0,0,0)
oModify box2 $ oCenterXY .~ (-2,2)
oModify box2 $ oContext .~ withStrokeWidth 0
dot <- newObject $ Circle 0.05
cameraAttach cam dot
oModify dot $ oContext .~ withFillColor "red"
oModify dot $ oMargin .~ (0,0,0,0)
oModify dot $ oCenterXY .~ (0.5,0.5)
oModify dot $ oContext .~ withStrokeWidth 0
dot2 <- newObject $ Circle 0.05
cameraAttach cam dot2
oModify dot2 $ oContext .~ withFillColor "red"
oModify dot2 $ oMargin .~ (0,0,0,0)
oModify dot2 $ oCenterXY .~ (-2,2)
oModify dot2 $ oContext .~ withStrokeWidth 0
oShow box
oShow box2
oShow dot
oShow dot2
wait 1
cameraSetFocus cam (0.5, 0.5)
waitOn $ do
fork $ cameraPan cam 1 (0.5, 0.5)
fork $ cameraZoom cam 1 2
wait 1
cameraSetFocus cam (-2,2)
cameraZoom cam 0.5 1.5
cameraZoom cam 0.5 2
wait 1
-- cameraSetFocus cam (-0.5,0.5)
waitOn $ do
fork $ cameraPan cam 1 (-2, 2)
fork $ cameraZoom cam 1 0.5
-- oTweenS cam 2 $ \t -> do
-- oScale %= \v -> fromToS v 3 t
-- cameraSetFocus cam (0.5,0.5)
-- oTweenS cam 1 $ \t -> do
-- oScale %= \v -> fromToS v 1 t
-- wait 4
-- oTweenS cam 2 $ \t -> do
-- oScaleOrigin .= (fromToS 0.5 (-2) t, fromToS 0.5 2 t)
-- oScale .= fromToS 2 1 t
-- oTranslate . _1 %= \v -> fromToS v (-2) t
-- oTranslate . _2 %= \v -> fromToS v 2 t
{-
Origin: (-2,2)
Translate: (3, -1)
New origin: (0.5, 0.5)
(0.5, 0.5)
(0.5+2, 0.5-2)
(2.5, -1.5) origin move
(2.5*3, -1.5*3)
(7.5, -4.5) scale
(7.5-2, -4.5+2)
(5.5, -2.5) origin move back
(5.5-3, -2.5+1)
(2.5, -1.5) translate
(0.5-2.5, 0.5-(-1.5))
(-2, 2)
-}
wait 1
-}
main = reanimate $ docEnv $ mapA (withFillOpacity 1) $ sceneAnimation $ do
cam <- newObject Camera cam <- newObject Camera
txt <- newObject $ center $ latex "Fixed (non-cam)" txt <- newObject $ center $ latex "Fixed (non-cam)"
@ -141,4 +50,4 @@ main = reanimate $ docEnv $ mapA (withFillOpacity 1) $ sceneAnimation $ do
waitOn $ do waitOn $ do
fork $ cameraZoom cam 3 1 fork $ cameraZoom cam 3 1
waitOn $ do waitOn $ do
fork $ cameraPan cam 1 (0,0) fork $ cameraPan cam 1 (V2 0 0)

View file

@ -22,7 +22,7 @@ import "random-shuffle" System.Random.Shuffle
-- spritePercent = (/) <$> spriteT <*> spriteDur -- spritePercent = (/) <$> spriteT <*> spriteDur
main :: IO () main :: IO ()
main = seq texture $ reanimate $ pauseAtEnd 1 $ addStatic bg $ sceneAnimation $ do main = seq texture $ reanimate $ pauseAtEnd 1 $ addStatic bg $ scene $ do
bend <- newVar 0 bend <- newVar 0
trans <- newVar 0 trans <- newVar 0
rotX <- newVar 0 rotX <- newVar 0
@ -200,7 +200,7 @@ checker w h =
latexExample :: Animation latexExample :: Animation
latexExample = sceneAnimation $ do latexExample = scene $ do
-- Draw equation -- Draw equation
play $ drawAnimation strokedSvg play $ drawAnimation strokedSvg
sprites <- forM glyphs $ \(fn, _, elt) -> sprites <- forM glyphs $ \(fn, _, elt) ->
@ -250,7 +250,7 @@ drawAnimation :: SVG -> Animation
drawAnimation = drawAnimation' Nothing 0.5 0.3 drawAnimation = drawAnimation' Nothing 0.5 0.3
drawAnimation' :: Maybe Int -> Double -> Double -> SVG -> Animation drawAnimation' :: Maybe Int -> Double -> Double -> SVG -> Animation
drawAnimation' mbSeed fillDur step svg = sceneAnimation $ do drawAnimation' mbSeed fillDur step svg = scene $ do
forM_ (zip [0..] $ shuf $ svgGlyphs svg) $ \(n, (fn, attr, tree)) -> do forM_ (zip [0..] $ shuf $ svgGlyphs svg) $ \(n, (fn, attr, tree)) -> do
let sWidth = let sWidth =
case toUserUnit defaultDPI <$> getLast (attr ^. strokeWidth) of case toUserUnit defaultDPI <$> getLast (attr ^. strokeWidth) of

View file

@ -12,7 +12,7 @@ import Reanimate
-- layer 3 -- layer 3
main :: IO () main :: IO ()
main = reanimate $ setDuration 30 $ sceneAnimation $ do main = reanimate $ setDuration 30 $ scene $ do
_ <- newSpriteSVG $ mkBackgroundPixel (PixelRGBA8 252 252 252 0xFF) _ <- newSpriteSVG $ mkBackgroundPixel (PixelRGBA8 252 252 252 0xFF)
play $ fourierA (fromToS 0 5) -- Rotate 15 times play $ fourierA (fromToS 0 5) -- Rotate 15 times
& setDuration 50 & setDuration 50

View file

@ -21,7 +21,7 @@ main = reanimate $ bg `parA` mainScene
bg = animate $ const $ mkBackgroundPixel (PixelRGBA8 252 252 252 0xFF) bg = animate $ const $ mkBackgroundPixel (PixelRGBA8 252 252 252 0xFF)
mainScene :: Animation mainScene :: Animation
mainScene = sceneAnimation $ mdo mainScene = scene $ mdo
play $ drawCircle play $ drawCircle
& setDuration drawCircleT & setDuration drawCircleT
& applyE (constE flipXAxis) & applyE (constE flipXAxis)

View file

@ -22,7 +22,7 @@ main = reanimate $ parA bg latexExample
bg = animate $ const $ mkBackgroundPixel (PixelRGBA8 252 252 252 0xFF) bg = animate $ const $ mkBackgroundPixel (PixelRGBA8 252 252 252 0xFF)
latexExample :: Animation latexExample :: Animation
latexExample = sceneAnimation $ do latexExample = scene $ do
-- Draw equation -- Draw equation
play $ drawAnimation strokedSvg play $ drawAnimation strokedSvg
sprites <- forM glyphs $ \(fn, _, elt) -> sprites <- forM glyphs $ \(fn, _, elt) ->
@ -72,7 +72,7 @@ drawAnimation :: SVG -> Animation
drawAnimation = drawAnimation' Nothing 0.5 0.3 drawAnimation = drawAnimation' Nothing 0.5 0.3
drawAnimation' :: Maybe Int -> Double -> Double -> SVG -> Animation drawAnimation' :: Maybe Int -> Double -> Double -> SVG -> Animation
drawAnimation' mbSeed fillDur step svg = sceneAnimation $ do drawAnimation' mbSeed fillDur step svg = scene $ do
forM_ (zip [0..] $ shuf $ svgGlyphs svg) $ \(n, (fn, attr, tree)) -> do forM_ (zip [0..] $ shuf $ svgGlyphs svg) $ \(n, (fn, attr, tree)) -> do
let sWidth = let sWidth =
case toUserUnit defaultDPI <$> getLast (attr ^. strokeWidth) of case toUserUnit defaultDPI <$> getLast (attr ^. strokeWidth) of

View file

@ -15,7 +15,7 @@ import qualified Data.Text as T
import NeatInterpolation import NeatInterpolation
main :: IO () main :: IO ()
main = reanimate $ parA bg $ sceneAnimation $ do main = reanimate $ parA bg $ scene $ do
play $ mkAnimation drawDuration $ \t -> partialSvg t (wireframe (-45) 220) play $ mkAnimation drawDuration $ \t -> partialSvg t (wireframe (-45) 220)
xRot <- newVar (-45) xRot <- newVar (-45)
yRot <- newVar 220 yRot <- newVar 220

View file

@ -23,7 +23,7 @@ import "random-shuffle" System.Random.Shuffle
main :: IO () main :: IO ()
main = reanimate $ sceneAnimation $ do main = reanimate $ scene $ do
newSpriteSVG $ mkBackgroundPixel $ PixelRGBA8 252 252 252 0xFF newSpriteSVG $ mkBackgroundPixel $ PixelRGBA8 252 252 252 0xFF
zPos <- newVar 0 zPos <- newVar 0
xRot <- newVar 0 xRot <- newVar 0
@ -93,7 +93,7 @@ polygon {
latexExample :: Animation latexExample :: Animation
latexExample = sceneAnimation $ do latexExample = scene $ do
-- Draw equation -- Draw equation
play $ drawAnimation strokedSvg play $ drawAnimation strokedSvg
sprites <- forM glyphs $ \(fn, _, elt) -> sprites <- forM glyphs $ \(fn, _, elt) ->
@ -143,7 +143,7 @@ drawAnimation :: SVG -> Animation
drawAnimation = drawAnimation' Nothing 0.5 0.3 drawAnimation = drawAnimation' Nothing 0.5 0.3
drawAnimation' :: Maybe Int -> Double -> Double -> SVG -> Animation drawAnimation' :: Maybe Int -> Double -> Double -> SVG -> Animation
drawAnimation' mbSeed fillDur step svg = sceneAnimation $ do drawAnimation' mbSeed fillDur step svg = scene $ do
forM_ (zip [0..] $ shuf $ svgGlyphs svg) $ \(n, (fn, attr, tree)) -> do forM_ (zip [0..] $ shuf $ svgGlyphs svg) $ \(n, (fn, attr, tree)) -> do
let sWidth = let sWidth =
case toUserUnit defaultDPI <$> getLast (attr ^. strokeWidth) of case toUserUnit defaultDPI <$> getLast (attr ^. strokeWidth) of

View file

@ -23,7 +23,7 @@ import "random-shuffle" System.Random.Shuffle
main :: IO () main :: IO ()
main = reanimate $ parA bg $ sceneAnimation $ do main = reanimate $ parA bg $ scene $ do
xRot <- newVar (-30) xRot <- newVar (-30)
yRot <- newVar 180 yRot <- newVar 180
zRot <- newVar 0 zRot <- newVar 0
@ -131,7 +131,7 @@ checker w h =
latexExample :: Animation latexExample :: Animation
latexExample = sceneAnimation $ do latexExample = scene $ do
-- Draw equation -- Draw equation
play $ drawAnimation strokedSvg play $ drawAnimation strokedSvg
sprites <- forM glyphs $ \(fn, _, elt) -> sprites <- forM glyphs $ \(fn, _, elt) ->
@ -181,7 +181,7 @@ drawAnimation :: SVG -> Animation
drawAnimation = drawAnimation' Nothing 0.5 0.3 drawAnimation = drawAnimation' Nothing 0.5 0.3
drawAnimation' :: Maybe Int -> Double -> Double -> SVG -> Animation drawAnimation' :: Maybe Int -> Double -> Double -> SVG -> Animation
drawAnimation' mbSeed fillDur step svg = sceneAnimation $ do drawAnimation' mbSeed fillDur step svg = scene $ do
forM_ (zip [0..] $ shuf $ svgGlyphs svg) $ \(n, (fn, attr, tree)) -> do forM_ (zip [0..] $ shuf $ svgGlyphs svg) $ \(n, (fn, attr, tree)) -> do
let sWidth = let sWidth =
case toUserUnit defaultDPI <$> getLast (attr ^. strokeWidth) of case toUserUnit defaultDPI <$> getLast (attr ^. strokeWidth) of

View file

@ -19,7 +19,7 @@ transcript :: Transcript
transcript = loadTranscript "voice_advanced.txt" transcript = loadTranscript "voice_advanced.txt"
main :: IO () main :: IO ()
main = reanimate $ sceneAnimation $ do main = reanimate $ scene $ do
bg <- newSpriteSVG $ mkBackgroundPixel rtfdBackgroundColor bg <- newSpriteSVG $ mkBackgroundPixel rtfdBackgroundColor
spriteZ bg (-100) spriteZ bg (-100)
newSpriteSVG_ $ mkGroup newSpriteSVG_ $ mkGroup

View file

@ -21,7 +21,7 @@ transcript =
\during development" \during development"
main :: IO () main :: IO ()
main = reanimate $ sceneAnimation $ do main = reanimate $ scene $ do
newSpriteSVG_ $ mkBackgroundPixel rtfdBackgroundColor newSpriteSVG_ $ mkBackgroundPixel rtfdBackgroundColor
waitOn $ forM_ (splitTranscript transcript) $ \(svg, tword) -> do waitOn $ forM_ (splitTranscript transcript) $ \(svg, tword) -> do
highlighted <- newVar 0 highlighted <- newVar 0

View file

@ -15,7 +15,7 @@ transcript :: Transcript
transcript = loadTranscript "voice_transcript.txt" transcript = loadTranscript "voice_transcript.txt"
main :: IO () main :: IO ()
main = reanimate $ sceneAnimation $ do main = reanimate $ scene $ do
newSpriteSVG_ $ mkBackgroundPixel rtfdBackgroundColor newSpriteSVG_ $ mkBackgroundPixel rtfdBackgroundColor
waitOn $ forM_ (splitTranscript transcript) $ \(svg, tword) -> fork $ do waitOn $ forM_ (splitTranscript transcript) $ \(svg, tword) -> fork $ do
let render v = centerUsing (latex $ transcriptText transcript) $ masked let render v = centerUsing (latex $ transcriptText transcript) $ masked

View file

@ -20,7 +20,7 @@ transformer =
translate (-4) 0 . centerUsing (latex $ transcriptText transcript) translate (-4) 0 . centerUsing (latex $ transcriptText transcript)
main :: IO () main :: IO ()
main = reanimate $ sceneAnimation $ do main = reanimate $ scene $ do
newSpriteSVG_ $ mkBackgroundPixel rtfdBackgroundColor newSpriteSVG_ $ mkBackgroundPixel rtfdBackgroundColor
waitOn $ forM_ (splitTranscript transcript) $ \(svg, tword) -> do waitOn $ forM_ (splitTranscript transcript) $ \(svg, tword) -> do
let render v = transformer $ masked (wordKey tword) let render v = transformer $ masked (wordKey tword)

View file

@ -1,5 +1,5 @@
animation :: Animation animation :: Animation
animation = docEnv $ sceneAnimation $ do animation = docEnv $ scene $ do
play $ drawBox `parA` drawCircle play $ drawBox `parA` drawCircle
& label "parA" & label "parA"
play $ drawBox `seqA` drawCircle play $ drawBox `seqA` drawCircle

View file

@ -1,5 +1,5 @@
animation :: Animation animation :: Animation
animation = docEnv $ sceneAnimation $ do animation = docEnv $ scene $ do
play $ staticFrame 1 (showColorMap parula) play $ staticFrame 1 (showColorMap parula)
& label "Parula" & label "Parula"
play $ staticFrame 1 (showColorMap viridis) play $ staticFrame 1 (showColorMap viridis)

View file

@ -4,7 +4,7 @@ env =
animation :: Animation animation :: Animation
animation = env $ animation = env $
sceneAnimation $ do scene $ do
circ <- newObject $ Circle 3 circ <- newObject $ Circle 3
oModify circ $ oModify circ $
oContext .~ withFillColor "pink" oContext .~ withFillColor "pink"

View file

@ -4,7 +4,7 @@ env =
animation :: Animation animation :: Animation
animation = env $ animation = env $
sceneAnimation $ do scene $ do
drawLatex "e^{i\\pi}+1=0" drawLatex "e^{i\\pi}+1=0"
drawLatex "\\sum_{k=1}^\\infty {1 \\over k^2} = {\\pi^2 \\over 6}" drawLatex "\\sum_{k=1}^\\infty {1 \\over k^2} = {\\pi^2 \\over 6}"
drawLatex "\\sum_{k=1}^\\infty" drawLatex "\\sum_{k=1}^\\infty"

View file

@ -1,5 +1,5 @@
animation :: Animation animation :: Animation
animation = docEnv $ pauseAtEnd 1 $ sceneAnimation $ do animation = docEnv $ pauseAtEnd 1 $ scene $ do
showEasing 0 "curveS" (curveS 2) showEasing 0 "curveS" (curveS 2)
showEasing 1 "bellS" (bellS 2) showEasing 1 "bellS" (bellS 2)
showEasing 2 "constantS" (constantS 0.7) showEasing 2 "constantS" (constantS 0.7)

View file

@ -10,7 +10,7 @@ fns =
] ]
animation :: Animation animation :: Animation
animation = docEnv $ pauseAtEnd 1 $ sceneAnimation $ do animation = docEnv $ pauseAtEnd 1 $ scene $ do
newSpriteSVG_ $ mkBackground "white" newSpriteSVG_ $ mkBackground "white"
play $ signalA (curveS 2) $ animate $ \t -> partialSvg t grid play $ signalA (curveS 2) $ animate $ \t -> partialSvg t grid
newSpriteSVG_ grid newSpriteSVG_ grid

View file

@ -4,7 +4,7 @@ env =
animation :: Animation animation :: Animation
animation = env $ animation = env $
sceneAnimation $ do scene $ do
-- Configure objects -- Configure objects
txt <- newText "Center" txt <- newText "Center"
top <- newText "Top" top <- newText "Top"
@ -16,11 +16,11 @@ animation = env $
oRightX .= screenRight oRightX .= screenRight
botR <- newText "Bottom right" botR <- newText "Bottom right"
oModifyS botR $ do oModifyS botR $ do
oTranslate .= (0, screenBottom+0.5) oTranslateY .= screenBottom+0.5
oRightX .= screenRight oRightX .= screenRight
botL <- newText "Bottom left" botL <- newText "Bottom left"
oModifyS botL $ do oModifyS botL $ do
oTranslate .= (0, screenBottom+0.5) oTranslateY .= screenBottom+0.5
oLeftX .= screenLeft oLeftX .= screenLeft
topL <- newText "Top left" topL <- newText "Top left"
oModifyS topL $ do oModifyS topL $ do

View file

@ -1,5 +1,5 @@
animation :: Animation animation :: Animation
animation = docEnv $ mapA (withFillOpacity 1) $ sceneAnimation $ do animation = docEnv $ mapA (withFillOpacity 1) $ scene $ do
cam <- newObject Camera cam <- newObject Camera
txt <- newObject $ center $ latex "Fixed (non-cam)" txt <- newObject $ center $ latex "Fixed (non-cam)"
@ -36,4 +36,4 @@ animation = docEnv $ mapA (withFillOpacity 1) $ sceneAnimation $ do
wait 2 wait 2
cameraZoom cam 3 1 cameraZoom cam 3 1
cameraPan cam 1 (0,0) cameraPan cam 1 (V2 0 0)

View file

@ -77,7 +77,7 @@ module Reanimate
-- ** Scenes -- ** Scenes
Scene Scene
, ZIndex , ZIndex
, sceneAnimation -- :: (forall s. Scene s a) -> Animation , scene -- :: (forall s. Scene s a) -> Animation
, play -- :: Animation -> Scene s () , play -- :: Animation -> Scene s ()
, fork -- :: Scene s a -> Scene s a , fork -- :: Scene s a -> Scene s a
, queryNow -- :: Scene s Time , queryNow -- :: Scene s Time

View file

@ -19,7 +19,6 @@ module Reanimate.Scene
Scene, Scene,
ZIndex, ZIndex,
scene, -- :: (forall s. Scene s a) -> Animation scene, -- :: (forall s. Scene s a) -> Animation
sceneAnimation, -- :: (forall s. Scene s a) -> Animation
play, -- :: Animation -> Scene s () play, -- :: Animation -> Scene s ()
fork, -- :: Scene s a -> Scene s a fork, -- :: Scene s a -> Scene s a
queryNow, -- :: Scene s Time queryNow, -- :: Scene s Time
@ -77,6 +76,8 @@ module Reanimate.Scene
-- ** Object Properties -- ** Object Properties
oTranslate, oTranslate,
oTranslateX,
oTranslateY,
oSVG, oSVG,
oContext, oContext,
oMargin, oMargin,
@ -100,6 +101,8 @@ module Reanimate.Scene
oLeftX, oLeftX,
oRightX, oRightX,
oCenterXY, oCenterXY,
oCenterX,
oCenterY,
oValue, oValue,
-- ** Graphics object methods -- ** Graphics object methods

View file

@ -54,11 +54,7 @@ evalScene action = runST $ do
-- | Render a 'Scene' to an 'Animation'. -- | Render a 'Scene' to an 'Animation'.
scene :: (forall s. Scene s a) -> Animation scene :: (forall s. Scene s a) -> Animation
scene = sceneAnimation scene action =
-- | Render a 'Scene' to an 'Animation'.
sceneAnimation :: (forall s. Scene s a) -> Animation
sceneAnimation action =
runST runST
( do ( do
(_, s, p, gens) <- unM action 0 (_, s, p, gens) <- unM action 0

View file

@ -2,6 +2,8 @@
{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE RecordWildCards #-}
module Reanimate.Scene.Object where module Reanimate.Scene.Object where
import Linear.V2
import Linear.Vector
import Control.Lens import Control.Lens
import Control.Monad (forM_, void) import Control.Monad (forM_, void)
import Control.Monad.State (State, execState) import Control.Monad.State (State, execState)
@ -46,7 +48,7 @@ data Object s a = Object
-- | Container for object properties. -- | Container for object properties.
data ObjectData a = ObjectData data ObjectData a = ObjectData
{ _oTranslate :: (Double, Double), { _oTranslate :: V2 Double,
_oValueRef :: a, _oValueRef :: a,
_oSVG :: SVG, _oSVG :: SVG,
_oContext :: SVG -> SVG, _oContext :: SVG -> SVG,
@ -58,7 +60,7 @@ data ObjectData a = ObjectData
_oZIndex :: Int, _oZIndex :: Int,
_oEasing :: Signal, _oEasing :: Signal,
_oScale :: Double, _oScale :: Double,
_oScaleOrigin :: (Double, Double) _oScaleOrigin :: V2 Double
} }
-- Basic lenses -- Basic lenses
@ -66,9 +68,17 @@ data ObjectData a = ObjectData
-- FIXME: Maybe 'position' is a better name. -- FIXME: Maybe 'position' is a better name.
-- | Object position. Default: \<0,0\> -- | Object position. Default: \<0,0\>
oTranslate :: Lens' (ObjectData a) (Double, Double) oTranslate :: Lens' (ObjectData a) (V2 Double)
oTranslate = lens _oTranslate $ \obj val -> obj {_oTranslate = val} oTranslate = lens _oTranslate $ \obj val -> obj {_oTranslate = val}
-- | Object X position. Default: 0
oTranslateX :: Lens' (ObjectData a) Double
oTranslateX = oTranslate . _x
-- | Object Y position. Default: 0
oTranslateY :: Lens' (ObjectData a) Double
oTranslateY = oTranslate . _y
-- | Rendered SVG node of an object. Does not include context -- | Rendered SVG node of an object. Does not include context
-- or object properties. Read-only. -- or object properties. Read-only.
oSVG :: Getter (ObjectData a) SVG oSVG :: Getter (ObjectData a) SVG
@ -112,7 +122,7 @@ oScale :: Lens' (ObjectData a) Double
oScale = lens _oScale $ \obj val -> oComputeBB obj {_oScale = val} oScale = lens _oScale $ \obj val -> oComputeBB obj {_oScale = val}
-- | Origin point for scaling. Default: \<0,0\> -- | Origin point for scaling. Default: \<0,0\>
oScaleOrigin :: Lens' (ObjectData a) (Double, Double) oScaleOrigin :: Lens' (ObjectData a) (V2 Double)
oScaleOrigin = lens _oScaleOrigin $ \obj val -> oComputeBB obj {_oScaleOrigin = val} oScaleOrigin = lens _oScaleOrigin $ \obj val -> oComputeBB obj {_oScaleOrigin = val}
-- Smart lenses -- Smart lenses
@ -184,7 +194,7 @@ oRightX = lens getter setter
obj & (oTranslate . _1) +~ val - getter obj obj & (oTranslate . _1) +~ val - getter obj
-- | Derived location of an object's center point. -- | Derived location of an object's center point.
oCenterXY :: Lens' (ObjectData a) (Double, Double) oCenterXY :: Lens' (ObjectData a) (V2 Double)
oCenterXY = lens getter setter oCenterXY = lens getter setter
where where
getter obj = getter obj =
@ -192,13 +202,21 @@ oCenterXY = lens getter setter
miny = obj ^. oBBMinY miny = obj ^. oBBMinY
w = obj ^. oBBWidth w = obj ^. oBBWidth
h = obj ^. oBBHeight h = obj ^. oBBHeight
(dx, dy) = obj ^. oTranslate V2 dx dy = obj ^. oTranslate
in (dx + minx + w / 2, dy + miny + h / 2) in V2 (dx + minx + w / 2) (dy + miny + h / 2)
setter obj (dx, dy) = setter obj (V2 dx dy) =
let (x, y) = getter obj let V2 x y = getter obj
in obj & (oTranslate . _1) +~ dx - x in obj & (oTranslate . _1) +~ dx - x
& (oTranslate . _2) +~ dy - y & (oTranslate . _2) +~ dy - y
-- | Derived location of an object's center X value.
oCenterX :: Lens' (ObjectData a) Double
oCenterX = oCenterXY . _x
-- | Derived location of an object's center Y value.
oCenterY :: Lens' (ObjectData a) Double
oCenterY = oCenterXY . _y
-- | Object's top margin. -- | Object's top margin.
oMarginTop :: Lens' (ObjectData a) Double oMarginTop :: Lens' (ObjectData a) Double
oMarginTop = oMargin . _1 oMarginTop = oMargin . _1
@ -278,7 +296,7 @@ newObject val = do
ref <- ref <-
newVar newVar
ObjectData ObjectData
{ _oTranslate = (0, 0), { _oTranslate = V2 0 0,
_oValueRef = val, _oValueRef = val,
_oSVG = svg, _oSVG = svg,
_oContext = id, _oContext = id,
@ -289,14 +307,14 @@ newObject val = do
_oZIndex = 1, _oZIndex = 1,
_oEasing = curveS 2, _oEasing = curveS 2,
_oScale = 1, _oScale = 1,
_oScaleOrigin = (0, 0) _oScaleOrigin = V2 0 0
} }
sprite <- newSprite $ do sprite <- newSprite $ do
~obj@ObjectData {..} <- unVar ref ~obj@ObjectData {..} <- unVar ref
pure $ pure $
if _oShown if _oShown
then then
uncurry translate _oTranslate $ uncurryV2 translate _oTranslate $
oScaleApply obj $ oScaleApply obj $
withGroupOpacity _oOpacity $ withGroupOpacity _oOpacity $
mkGroup [_oContext _oSVG] mkGroup [_oContext _oSVG]
@ -314,9 +332,12 @@ newObject val = do
oScaleApply :: ObjectData a -> (SVG -> SVG) oScaleApply :: ObjectData a -> (SVG -> SVG)
oScaleApply ObjectData {..} = oScaleApply ObjectData {..} =
uncurry translate (_oScaleOrigin & both %~ negate) uncurryV2 translate (negate _oScaleOrigin)
. scale _oScale . scale _oScale
. uncurry translate _oScaleOrigin . uncurryV2 translate _oScaleOrigin
uncurryV2 :: (a -> a -> b) -> V2 a -> b
uncurryV2 fn (V2 a b) = fn a b
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- Graphical transformations -- Graphical transformations
@ -463,13 +484,10 @@ oTransform src dst d = do
oShown .= True oShown .= True
oEasing .= srcEase oEasing .= srcEase
oTranslate .= srcLoc oTranslate .= srcLoc
fork $ oTween m d $ \t -> oTranslate %~ moveTo t dstLoc fork $ oTween m d $ \t -> oTranslate %~ lerp t dstLoc
oTweenV m d $ \t -> morphDelta .~ t oTweenV m d $ \t -> morphDelta .~ t
oModify m $ oShown .~ False oModify m $ oShown .~ False
oModify dst $ oShown .~ True oModify dst $ oShown .~ True
where
moveTo t (dstX, dstY) (srcX, srcY) =
(fromToS srcX dstX t, fromToS srcY dstY t)
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- Built-in objects -- Built-in objects
@ -547,12 +565,12 @@ cameraAttach cam obj =
spriteModify (objectSprite obj) $ do spriteModify (objectSprite obj) $ do
camData <- unVar (objectData cam) camData <- unVar (objectData cam)
return $ \(svg, zindex) -> return $ \(svg, zindex) ->
let (x, y) = camData ^. oTranslate let V2 x y = camData ^. oTranslate
ctx = ctx =
translate (- x) (- y) translate (- x) (- y)
. uncurry translate (camData ^. oScaleOrigin) . uncurryV2 translate (camData ^. oScaleOrigin)
. scale (camData ^. oScale) . scale (camData ^. oScale)
. uncurry translate (camData ^. oScaleOrigin & both %~ negate) . uncurryV2 translate (negate $ camData ^. oScaleOrigin)
in (ctx svg, zindex) in (ctx svg, zindex)
-- | -- |
@ -576,15 +594,15 @@ cameraAttach cam obj =
-- @ -- @
-- --
-- <<docs/gifs/doc_cameraFocus.gif>> -- <<docs/gifs/doc_cameraFocus.gif>>
cameraFocus :: Object s Camera -> (Double, Double) -> Scene s () cameraFocus :: Object s Camera -> V2 Double -> Scene s ()
cameraFocus cam (x, y) = do cameraFocus cam new = do
(ox, oy) <- oRead cam oScaleOrigin origin <- oRead cam oScaleOrigin
(tx, ty) <- oRead cam oTranslate t <- oRead cam oTranslate
s <- oRead cam oScale s <- oRead cam oScale
let newLocation = (x - ((x - ox) * s + ox - tx), y - ((y - oy) * s + oy - ty)) let newLocation = new - ((new - origin) ^* s + origin - t)
oModifyS cam $ do oModifyS cam $ do
oTranslate .= newLocation oTranslate .= newLocation
oScaleOrigin .= (x, y) oScaleOrigin .= new
-- | Instantaneously set camera zoom level. -- | Instantaneously set camera zoom level.
cameraSetZoom :: Object s Camera -> Double -> Scene s () cameraSetZoom :: Object s Camera -> Double -> Scene s ()
@ -599,14 +617,13 @@ cameraZoom cam d s =
oScale %= \v -> fromToS v s t oScale %= \v -> fromToS v s t
-- | Instantaneously set camera location. -- | Instantaneously set camera location.
cameraSetPan :: Object s Camera -> (Double, Double) -> Scene s () cameraSetPan :: Object s Camera -> V2 Double -> Scene s ()
cameraSetPan cam location = cameraSetPan cam location =
oModifyS cam $ oModifyS cam $
oTranslate .= location oTranslate .= location
-- | Change camera location over a set duration. -- | Change camera location over a set duration.
cameraPan :: Object s Camera -> Duration -> (Double, Double) -> Scene s () cameraPan :: Object s Camera -> Duration -> V2 Double -> Scene s ()
cameraPan cam d (x, y) = cameraPan cam d pos =
oTweenS cam d $ \t -> do oTweenS cam d $ \t ->
oTranslate . _1 %= \v -> fromToS v x t oTranslate %= lerp t pos
oTranslate . _2 %= \v -> fromToS v y t

View file

@ -29,7 +29,7 @@ import Reanimate.Scene.Core
fork, fork,
liftST, liftST,
queryNow, queryNow,
sceneAnimation, scene,
wait, wait,
) )
import Reanimate.Scene.Var (unpackVar, Var (..), newVar, readVar) import Reanimate.Scene.Var (unpackVar, Var (..), newVar, readVar)
@ -402,7 +402,7 @@ spriteScope (M action) = M $ \t -> do
asAnimation :: (forall s'. Scene s' a) -> Scene s Animation asAnimation :: (forall s'. Scene s' a) -> Scene s Animation
asAnimation s = do asAnimation s = do
now <- queryNow now <- queryNow
return $ dropA now (sceneAnimation (wait now >> s)) return $ dropA now (scene (wait now >> s))
-- | Apply a transformation with a given overlap. This makes sure -- | Apply a transformation with a given overlap. This makes sure
-- to keep timestamps intact such that events can still be timed -- to keep timestamps intact such that events can still be timed

View file

@ -56,7 +56,7 @@ main =
-- $ dropA (wordStart beginWord) -- $ dropA (wordStart beginWord)
-- $ takeA (wordEnd endWord) -- $ takeA (wordEnd endWord)
-- $ takeA 20 -- $ takeA 20
$ sceneAnimation $ scene
$ do $ do
newSpriteSVG_ $ mkBackground "black" newSpriteSVG_ $ mkBackground "black"
monalisaScene monalisaScene

View file

@ -73,7 +73,7 @@ playbackTest :: Animation
playbackTest = setDuration 10 feat3D playbackTest = setDuration 10 feat3D
sphereIntro :: Animation sphereIntro :: Animation
sphereIntro = sceneAnimation $ do sphereIntro = scene $ do
-- play $ drawSphere -- play $ drawSphere
-- # setDuration 15 -- # setDuration 15
-- # pauseAtEnd 2 -- # pauseAtEnd 2
@ -227,7 +227,7 @@ featWireSphere = rotateWireSphere
& repeatA 10 & repeatA 10
introSVG :: Animation introSVG :: Animation
introSVG = sceneAnimation $ do introSVG = scene $ do
fork $ play $ animate $ const $ fork $ play $ animate $ const $
mkBackground "black" mkBackground "black"
-- Title -- Title
@ -291,7 +291,7 @@ drawAnimation :: SVG -> Animation
drawAnimation = drawAnimation' 0.5 0.3 drawAnimation = drawAnimation' 0.5 0.3
drawAnimation' :: Double -> Double -> SVG -> Animation drawAnimation' :: Double -> Double -> SVG -> Animation
drawAnimation' fillDur step svg = sceneAnimation $ do drawAnimation' fillDur step svg = scene $ do
forM_ (zip [0..] $ svgGlyphs svg) $ \(n, (fn, attr, tree)) -> do forM_ (zip [0..] $ svgGlyphs svg) $ \(n, (fn, attr, tree)) -> do
let sWidth = let sWidth =
case toUserUnit defaultDPI <$> getLast (attr ^. strokeWidth) of case toUserUnit defaultDPI <$> getLast (attr ^. strokeWidth) of