diff --git a/haddock.txt b/haddock.txt index cb1ec34..05ca084 100644 --- a/haddock.txt +++ b/haddock.txt @@ -1,4 +1,5 @@ 100% (154 /154) in 'Reanimate' + 100% (128 /128) in 'Reanimate.Scene' 100% ( 55 / 55) in 'Reanimate.Svg.Constructors' 100% ( 41 / 41) in 'Reanimate.Animation' 100% ( 40 / 40) in 'Reanimate.GeoProjection' @@ -36,4 +37,3 @@ 100% ( 3 / 3) in 'Reanimate.Math.Balloon' 100% ( 3 / 3) in 'Reanimate.Blender' 100% ( 2 / 2) in 'Reanimate.Builtin.CirclePlot' - 89% (114 /128) in 'Reanimate.Scene' diff --git a/hpc_index.html b/hpc_index.html index 3a7e9d1..775e643 100644 --- a/hpc_index.html +++ b/hpc_index.html @@ -107,7 +107,7 @@ table.dashboard { border-collapse: collapse ; border: solid 1px black } 85%23/27
57%11/19
78%314/400
  module reanimate-0.5.0.1-inplace/Reanimate.Scene.Var -89%17/19
60%14/23
68%220/319
+89%17/19
60%14/23
68%214/313
  module reanimate-0.5.0.1-inplace/Reanimate.Svg 38%5/13
18%15/80
41%323/777
@@ -131,5 +131,5 @@ table.dashboard { border-collapse: collapse ; border: solid 1px black } 100%6/6
50%1/2
95%43/45
  Program Coverage Total -35%261/739
17%144/846
32%4843/14992
+35%261/739
17%144/846
32%4837/14986
diff --git a/hpc_index_alt.html b/hpc_index_alt.html index 5732ae2..bf17efb 100644 --- a/hpc_index_alt.html +++ b/hpc_index_alt.html @@ -17,7 +17,7 @@ table.dashboard { border-collapse: collapse ; border: solid 1px black } 100%14/14
60%3/5
99%1176/1180
  module reanimate-0.5.0.1-inplace/Reanimate.Scene.Var -89%17/19
60%14/23
68%220/319
+89%17/19
60%14/23
68%214/313
  module reanimate-0.5.0.1-inplace/Reanimate.Svg.LineCommand 80%12/15
58%43/74
70%659/937
@@ -131,5 +131,5 @@ table.dashboard { border-collapse: collapse ; border: solid 1px black } 66%12/18
- 0/0 72%172/236
  Program Coverage Total -35%261/739
17%144/846
32%4843/14992
+35%261/739
17%144/846
32%4837/14986
diff --git a/hpc_index_exp.html b/hpc_index_exp.html index e951604..a1aff0d 100644 --- a/hpc_index_exp.html +++ b/hpc_index_exp.html @@ -38,7 +38,7 @@ table.dashboard { border-collapse: collapse ; border: solid 1px black } 80%12/15
58%43/74
70%659/937
  module reanimate-0.5.0.1-inplace/Reanimate.Scene.Var -89%17/19
60%14/23
68%220/319
+89%17/19
60%14/23
68%214/313
  module reanimate-0.5.0.1-inplace/Reanimate.Svg.Constructors 67%33/49
37%3/8
65%368/563
@@ -131,5 +131,5 @@ table.dashboard { border-collapse: collapse ; border: solid 1px black } 0%0/1
0%0/4
0%0/61
  Program Coverage Total -35%261/739
17%144/846
32%4843/14992
+35%261/739
17%144/846
32%4837/14986
diff --git a/hpc_index_fun.html b/hpc_index_fun.html index 5cca3ca..51a3a43 100644 --- a/hpc_index_fun.html +++ b/hpc_index_fun.html @@ -23,7 +23,7 @@ table.dashboard { border-collapse: collapse ; border: solid 1px black } 90%28/31
57%8/14
87%298/341
  module reanimate-0.5.0.1-inplace/Reanimate.Scene.Var -89%17/19
60%14/23
68%220/319
+89%17/19
60%14/23
68%214/313
  module reanimate-0.5.0.1-inplace/Reanimate.Ease 87%7/8
100%4/4
96%85/88
@@ -131,5 +131,5 @@ table.dashboard { border-collapse: collapse ; border: solid 1px black } 0%0/1
0%0/4
0%0/61
  Program Coverage Total -35%261/739
17%144/846
32%4843/14992
+35%261/739
17%144/846
32%4837/14986
diff --git a/playground/snippets.js b/playground/snippets.js index c549452..a3e1f1f 100644 --- a/playground/snippets.js +++ b/playground/snippets.js @@ -9,4 +9,4 @@ const snippets = [{"title": "Hello World","url": "https://reanimate.clozecards.c ,{"title": "Object Positions","url": "https://reanimate.clozecards.com/LRZe4V6frOI/195.svg","code": "env =\n addStatic (mkBackground \"white\") .\n mapA (withStrokeColor \"black\")\n\nanimation :: Animation\nanimation = env $\n scene $ do\n -- Configure objects\n txt <- newText \"Center\"\n top <- newText \"Top\"\n oModifyS top $ \n oTopY .= screenTop\n topR <- newText \"Top right\"\n oModifyS topR $ do\n oTopY .= screenTop\n oRightX .= screenRight\n botR <- newText \"Bottom right\"\n oModifyS botR $ do\n oTranslateY .= screenBottom+0.5\n oRightX .= screenRight\n botL <- newText \"Bottom left\"\n oModifyS botL $ do\n oTranslateY .= screenBottom+0.5\n oLeftX .= screenLeft\n topL <- newText \"Top left\"\n oModifyS topL $ do\n oTopY .= screenTop\n oLeftX .= screenLeft\n -- Show objects\n oShow txt\n wait 1\n switchTo txt top\n switchTo top topR\n switchTo topR botR\n switchTo botR botL\n switchTo botL topL\n switchTo topL txt\n\nswitchTo src dst = do\n fork $ oHideWith src oFadeOut\n oShowWith dst oFadeIn\n wait 1\n\nnewText txt =\n newObject $ scale 1.5 $ centerX $ latex txt\n"} ,{"title": "Camera","url": "https://reanimate.clozecards.com/JlWlOpJvDds/150.svg","code": "animation :: Animation\nanimation = docEnv $ mapA (withFillOpacity 1) $ scene $ do\n cam <- newObject Camera\n\n txt <- newObject $ center $ latex \"Fixed (non-cam)\"\n oModifyS txt $ do\n oTopY .= screenTop \n oZIndex .= 2\n\n circle <- newObject $ withFillColor \"blue\" $ mkCircle 1\n cameraAttach cam circle\n circleRight <- oRead circle oRightX\n\n box <- newObject $ withFillColor \"green\" $ mkRect 2 2\n cameraAttach cam box\n oModify box $ oLeftX .~ circleRight\n boxCenter <- oRead box oCenterXY\n\n small <- newObject $ center $ latex \"This text is very small\"\n cameraAttach cam small\n oModifyS small $ do\n oCenterXY .= boxCenter\n oScale .= 0.1\n \n oShow txt\n oShow small\n oShow circle\n oShow box\n\n wait 1\n\n cameraFocus cam boxCenter\n waitOn $ do\n fork $ cameraPan cam 3 boxCenter\n fork $ cameraZoom cam 3 15\n \n wait 2\n cameraZoom cam 3 1\n cameraPan cam 1 (V2 0 0)\n"} ]; -const playgroundVersion = "2020-09-19 (d37e7)"; +const playgroundVersion = "2020-09-19 (217c5)"; diff --git a/reanimate-0.5.0.1-inplace/Reanimate.Render.hs.html b/reanimate-0.5.0.1-inplace/Reanimate.Render.hs.html index 73ea755..861b697 100644 --- a/reanimate-0.5.0.1-inplace/Reanimate.Render.hs.html +++ b/reanimate-0.5.0.1-inplace/Reanimate.Render.hs.html @@ -87,7 +87,7 @@ span.spaces { background: white } 68 now = (duration ani / (fromIntegral frameCount - 1)) * fromIntegral nth 69 frame = frameAt (if frameCount <= 1 then 0 else now) ani 70 path = folder </> show nth <.> "svg" - 71 ~svg = renderSvg Nothing Nothing frame + 71 svg = renderSvg Nothing Nothing frame 72 73 idempotentFile path $ 74 writeFile path svg diff --git a/reanimate-0.5.0.1-inplace/Reanimate.Scene.Core.hs.html b/reanimate-0.5.0.1-inplace/Reanimate.Scene.Core.hs.html index 5b77deb..d591145 100644 --- a/reanimate-0.5.0.1-inplace/Reanimate.Scene.Core.hs.html +++ b/reanimate-0.5.0.1-inplace/Reanimate.Scene.Core.hs.html @@ -62,120 +62,121 @@ span.spaces { background: white } 43 instance MonadFix (Scene s) where 44 mfix fn = M $ \t -> mfix (\v -> let (a, _s, _p, _gens) = v in unM (fn a) t) 45 - 46 liftST :: ST s a -> Scene s a - 47 liftST action = M $ \_ -> action >>= \a -> return (a, 0, 0, []) - 48 - 49 -- | Evaluate the value of a scene. - 50 evalScene :: (forall s. Scene s a) -> a - 51 evalScene action = runST $ do - 52 (val, _, _, _) <- unM action 0 - 53 return val - 54 - 55 -- | Render a 'Scene' to an 'Animation'. - 56 scene :: (forall s. Scene s a) -> Animation - 57 scene action = - 58 runST - 59 ( do - 60 (_, s, p, gens) <- unM action 0 - 61 let dur = max s p - 62 genFns <- sequence gens - 63 return $ - 64 mkAnimation - 65 dur - 66 ( \t -> - 67 mkGroup $ - 68 map fst $ - 69 sortOn - 70 snd - 71 [spriteRender dur (t * dur) | spriteRender <- genFns] - 72 ) - 73 ) - 74 - 75 -- | Execute actions in a scene without advancing the clock. Note that scenes do not end before - 76 -- all forked actions have completed. - 77 -- - 78 -- Example: - 79 -- - 80 -- @ - 81 -- do 'fork' $ 'play' 'Reanimate.Builtin.Documentation.drawBox' - 82 -- 'play' 'Reanimate.Builtin.Documentation.drawCircle' - 83 -- @ - 84 -- - 85 -- <<docs/gifs/doc_fork.gif>> - 86 fork :: Scene s a -> Scene s a - 87 fork (M action) = M $ \t -> do - 88 (a, s, p, gens) <- action t - 89 return (a, 0, max s p, gens) - 90 - 91 -- | Query the current clock timestamp. - 92 -- - 93 -- Example: - 94 -- - 95 -- @ - 96 -- do now \<- 'play' 'Reanimate.Builtin.Documentation.drawCircle' *\> 'queryNow' - 97 -- 'play' $ 'staticFrame' 1 $ 'scale' 2 $ 'withStrokeWidth' 0.05 $ - 98 -- 'mkText' $ "Now=" <> T.pack (show now) - 99 -- @ - 100 -- - 101 -- <<docs/gifs/doc_queryNow.gif>> - 102 queryNow :: Scene s Time - 103 queryNow = M $ \t -> return (t, 0, 0, []) - 104 - 105 -- | Advance the clock by a given number of seconds. - 106 -- - 107 -- Example: - 108 -- - 109 -- @ - 110 -- do 'fork' $ 'play' 'Reanimate.Builtin.Documentation.drawBox' - 111 -- 'wait' 1 - 112 -- 'play' 'Reanimate.Builtin.Documentation.drawCircle' - 113 -- @ - 114 -- - 115 -- <<docs/gifs/doc_wait.gif>> - 116 wait :: Duration -> Scene s () - 117 wait d = M $ \_ -> return ((), d, 0, []) - 118 - 119 -- | Wait until the clock is equal to the given timestamp. - 120 waitUntil :: Time -> Scene s () - 121 waitUntil tNew = do - 122 now <- queryNow - 123 wait (max 0 (tNew - now)) - 124 - 125 -- | Wait until all forked and sequential animations have finished. - 126 -- - 127 -- Example: - 128 -- - 129 -- @ - 130 -- do 'waitOn' $ 'fork' $ 'play' 'Reanimate.Builtin.Documentation.drawBox' - 131 -- 'play' 'Reanimate.Builtin.Documentation.drawCircle' - 132 -- @ - 133 -- - 134 -- <<docs/gifs/doc_waitOn.gif>> - 135 waitOn :: Scene s a -> Scene s a - 136 waitOn (M action) = M $ \t -> do - 137 (a, s, p, gens) <- action t - 138 return (a, max s p, 0, gens) - 139 - 140 -- | Change the ZIndex of a scene. - 141 adjustZ :: (ZIndex -> ZIndex) -> Scene s a -> Scene s a - 142 adjustZ fn (M action) = M $ \t -> do - 143 (a, s, p, gens) <- action t - 144 return (a, s, p, map genFn gens) - 145 where - 146 genFn gen = do - 147 frameGen <- gen - 148 return $ \d t -> let (svg, z) = frameGen d t in (svg, fn z) - 149 - 150 -- | Query the duration of a scene. - 151 withSceneDuration :: Scene s () -> Scene s Duration - 152 withSceneDuration s = do - 153 t1 <- queryNow - 154 s - 155 t2 <- queryNow - 156 return (t2 - t1) - 157 - 158 addGen :: Gen s -> Scene s () - 159 addGen gen = M $ \_ -> return ((), 0, 0, [gen]) + 46 -- | Lift ST action into the Scene monad. + 47 liftST :: ST s a -> Scene s a + 48 liftST action = M $ \_ -> action >>= \a -> return (a, 0, 0, []) + 49 + 50 -- | Evaluate the value of a scene. + 51 evalScene :: (forall s. Scene s a) -> a + 52 evalScene action = runST $ do + 53 (val, _, _, _) <- unM action 0 + 54 return val + 55 + 56 -- | Render a 'Scene' to an 'Animation'. + 57 scene :: (forall s. Scene s a) -> Animation + 58 scene action = + 59 runST + 60 ( do + 61 (_, s, p, gens) <- unM action 0 + 62 let dur = max s p + 63 genFns <- sequence gens + 64 return $ + 65 mkAnimation + 66 dur + 67 ( \t -> + 68 mkGroup $ + 69 map fst $ + 70 sortOn + 71 snd + 72 [spriteRender dur (t * dur) | spriteRender <- genFns] + 73 ) + 74 ) + 75 + 76 -- | Execute actions in a scene without advancing the clock. Note that scenes do not end before + 77 -- all forked actions have completed. + 78 -- + 79 -- Example: + 80 -- + 81 -- @ + 82 -- do 'fork' $ 'Reanimate.Scene.play' 'Reanimate.Builtin.Documentation.drawBox' + 83 -- 'Reanimate.Scene.play' 'Reanimate.Builtin.Documentation.drawCircle' + 84 -- @ + 85 -- + 86 -- <<docs/gifs/doc_fork.gif>> + 87 fork :: Scene s a -> Scene s a + 88 fork (M action) = M $ \t -> do + 89 (a, s, p, gens) <- action t + 90 return (a, 0, max s p, gens) + 91 + 92 -- | Query the current clock timestamp. + 93 -- + 94 -- Example: + 95 -- + 96 -- @ + 97 -- do now \<- 'Reanimate.Scene.play' 'Reanimate.Builtin.Documentation.drawCircle' *\> 'queryNow' + 98 -- 'Reanimate.Scene.play' $ 'staticFrame' 1 $ 'scale' 2 $ 'withStrokeWidth' 0.05 $ + 99 -- 'mkText' $ "Now=" <> T.pack (show now) + 100 -- @ + 101 -- + 102 -- <<docs/gifs/doc_queryNow.gif>> + 103 queryNow :: Scene s Time + 104 queryNow = M $ \t -> return (t, 0, 0, []) + 105 + 106 -- | Advance the clock by a given number of seconds. + 107 -- + 108 -- Example: + 109 -- + 110 -- @ + 111 -- do 'fork' $ 'Reanimate.Scene.play' 'Reanimate.Builtin.Documentation.drawBox' + 112 -- 'wait' 1 + 113 -- 'Reanimate.Scene.play' 'Reanimate.Builtin.Documentation.drawCircle' + 114 -- @ + 115 -- + 116 -- <<docs/gifs/doc_wait.gif>> + 117 wait :: Duration -> Scene s () + 118 wait d = M $ \_ -> return ((), d, 0, []) + 119 + 120 -- | Wait until the clock is equal to the given timestamp. + 121 waitUntil :: Time -> Scene s () + 122 waitUntil tNew = do + 123 now <- queryNow + 124 wait (max 0 (tNew - now)) + 125 + 126 -- | Wait until all forked and sequential animations have finished. + 127 -- + 128 -- Example: + 129 -- + 130 -- @ + 131 -- do 'waitOn' $ 'fork' $ 'Reanimate.Scene.play' 'Reanimate.Builtin.Documentation.drawBox' + 132 -- 'Reanimate.Scene.play' 'Reanimate.Builtin.Documentation.drawCircle' + 133 -- @ + 134 -- + 135 -- <<docs/gifs/doc_waitOn.gif>> + 136 waitOn :: Scene s a -> Scene s a + 137 waitOn (M action) = M $ \t -> do + 138 (a, s, p, gens) <- action t + 139 return (a, max s p, 0, gens) + 140 + 141 -- | Change the ZIndex of a scene. + 142 adjustZ :: (ZIndex -> ZIndex) -> Scene s a -> Scene s a + 143 adjustZ fn (M action) = M $ \t -> do + 144 (a, s, p, gens) <- action t + 145 return (a, s, p, map genFn gens) + 146 where + 147 genFn gen = do + 148 frameGen <- gen + 149 return $ \d t -> let (svg, z) = frameGen d t in (svg, fn z) + 150 + 151 -- | Query the duration of a scene. + 152 withSceneDuration :: Scene s () -> Scene s Duration + 153 withSceneDuration s = do + 154 t1 <- queryNow + 155 s + 156 t2 <- queryNow + 157 return (t2 - t1) + 158 + 159 addGen :: Gen s -> Scene s () + 160 addGen gen = M $ \_ -> return ((), 0, 0, [gen]) diff --git a/reanimate-0.5.0.1-inplace/Reanimate.Scene.Sprite.hs.html b/reanimate-0.5.0.1-inplace/Reanimate.Scene.Sprite.hs.html index 2154a96..ce2281a 100644 --- a/reanimate-0.5.0.1-inplace/Reanimate.Scene.Sprite.hs.html +++ b/reanimate-0.5.0.1-inplace/Reanimate.Scene.Sprite.hs.html @@ -60,8 +60,8 @@ span.spaces { background: white } 41 -- Example: 42 -- 43 -- @ - 44 -- do var \<- 'simpleVar' 'mkCircle' 0 - 45 -- 'tweenVar' var 2 $ \\val -> 'fromToS' val ('Reanimate.Constants.screenHeight'/2) + 44 -- do var \<- 'simpleVar' 'Reanimate.Svg.Constructors.mkCircle' 0 + 45 -- 'Reanimate.Scene.tweenVar' var 2 $ \\val -> 'Reanimate.fromToS' val ('Reanimate.Constants.screenHeight'/2) 46 -- @ 47 -- 48 -- <<docs/gifs/doc_simpleVar.gif>> @@ -117,9 +117,9 @@ span.spaces { background: white } 98 -- 99 -- @ 100 -- do v \<- 'newVar' 0 - 101 -- 'newSprite' $ 'mkCircle' \<$\> 'unVar' v - 102 -- 'tweenVar' v 1 $ \\val -> 'fromToS' val 3 - 103 -- 'tweenVar' v 1 $ \\val -> 'fromToS' val 0 + 101 -- 'newSprite' $ 'Reanimate.Svg.Constructors.mkCircle' \<$\> 'unVar' v + 102 -- 'Reanimate.Scene.tweenVar' v 1 $ \\val -> 'Reanimate.fromToS' val 3 + 103 -- 'Reanimate.Scene.tweenVar' v 1 $ \\val -> 'Reanimate.fromToS' val 0 104 -- @ 105 -- 106 -- <<docs/gifs/doc_unVar.gif>> @@ -142,7 +142,7 @@ span.spaces { background: white } 123 -- Example: 124 -- 125 -- @ - 126 -- do 'newSprite' $ 'mkCircle' \<$\> 'spriteT' -- Circle sprite where radius=time. + 126 -- do 'newSprite' $ 'Reanimate.Svg.Constructors.mkCircle' \<$\> 'spriteT' -- Circle sprite where radius=time. 127 -- 'wait' 2 128 -- @ 129 -- @@ -188,7 +188,7 @@ span.spaces { background: white } 169 -- @ 170 -- do 'fork' $ 'newSpriteA' 'Reanimate.Builtin.Documentation.drawCircle' 171 -- 'play' 'Reanimate.Builtin.Documentation.drawBox' - 172 -- 'play' $ 'reverseA' 'Reanimate.Builtin.Documentation.drawBox' + 172 -- 'play' $ 'Reanimate.Animation.reverseA' 'Reanimate.Builtin.Documentation.drawBox' 173 -- @ 174 -- 175 -- <<docs/gifs/doc_newSpriteA.gif>> @@ -201,9 +201,9 @@ span.spaces { background: white } 182 -- Example: 183 -- 184 -- @ - 185 -- do 'fork' $ 'newSpriteA'' 'SyncFreeze' 'Reanimate.Builtin.Documentation.drawCircle' + 185 -- do 'fork' $ 'newSpriteA'' 'Reanimate.Animation.SyncFreeze' 'Reanimate.Builtin.Documentation.drawCircle' 186 -- 'play' 'Reanimate.Builtin.Documentation.drawBox' - 187 -- 'play' $ 'reverseA' 'Reanimate.Builtin.Documentation.drawBox' + 187 -- 'play' $ 'Reanimate.Animation.reverseA' 'Reanimate.Builtin.Documentation.drawBox' 188 -- @ 189 -- 190 -- <<docs/gifs/doc_newSpriteA'.gif>> @@ -217,7 +217,7 @@ span.spaces { background: white } 198 -- Example: 199 -- 200 -- @ - 201 -- do 'newSpriteSVG' $ 'mkBackground' "lightblue" + 201 -- do 'newSpriteSVG' $ 'Reanimate.Svg.Constructors.mkBackground' "lightblue" 202 -- 'play' 'Reanimate.Builtin.Documentation.drawCircle' 203 -- @ 204 -- @@ -238,8 +238,8 @@ span.spaces { background: white } 219 -- @ 220 -- do s \<- 'fork' $ 'newSpriteA' 'Reanimate.Builtin.Documentation.drawBox' 221 -- v \<- 'newVar' 0 - 222 -- 'applyVar' v s 'rotate' - 223 -- 'tweenVar' v 2 $ \\val -> 'fromToS' val 90 + 222 -- 'applyVar' v s 'Reanimate.Svg.Constructors.rotate' + 223 -- 'Reanimate.Scene.tweenVar' v 2 $ \\val -> 'Reanimate.fromToS' val 90 224 -- @ 225 -- 226 -- <<docs/gifs/doc_applyVar.gif>> @@ -254,7 +254,7 @@ span.spaces { background: white } 235 -- Example: 236 -- 237 -- @ - 238 -- do s <- 'newSpriteSVG' $ 'withFillOpacity' 1 $ 'mkCircle' 1 + 238 -- do s <- 'newSpriteSVG' $ 'Reanimate.Svg.Constructors.withFillOpacity' 1 $ 'Reanimate.Svg.Constructors.mkCircle' 1 239 -- 'fork' $ 'wait' 1 \>\> 'destroySprite' s 240 -- 'play' 'Reanimate.Builtin.Documentation.drawBox' 241 -- @ @@ -286,7 +286,7 @@ span.spaces { background: white } 267 -- @ 268 -- do s \<- 'fork' $ 'newSpriteA' 'Reanimate.Builtin.Documentation.drawCircle' 269 -- 'wait' 1 - 270 -- 'spriteMap' s 'flipYAxis' + 270 -- 'spriteMap' s 'Reanimate.Svg.Constructors.flipYAxis' 271 -- @ 272 -- 273 -- <<docs/gifs/doc_spriteMap.gif>> @@ -304,7 +304,7 @@ span.spaces { background: white } 285 -- 286 -- @ 287 -- do s \<- 'fork' $ 'newSpriteA' 'Reanimate.Builtin.Documentation.drawCircle' - 288 -- 'spriteTween' s 1 $ \\val -> 'translate' ('Reanimate.Constants.screenWidth'*0.3*val) 0 + 288 -- 'spriteTween' s 1 $ \\val -> 'Reanimate.Svg.Constructors.translate' ('Reanimate.Constants.screenWidth'*0.3*val) 0 289 -- @ 290 -- 291 -- <<docs/gifs/doc_spriteTween.gif>> @@ -328,8 +328,8 @@ span.spaces { background: white } 309 -- 310 -- @ 311 -- do s \<- 'fork' $ 'newSpriteA' 'Reanimate.Builtin.Documentation.drawBox' - 312 -- v \<- 'spriteVar' s 0 'rotate' - 313 -- 'tweenVar' v 2 $ \\val -> 'fromToS' val 90 + 312 -- v \<- 'spriteVar' s 0 'Reanimate.Svg.Constructors.rotate' + 313 -- 'Reanimate.Scene.tweenVar' v 2 $ \\val -> 'Reanimate.fromToS' val 90 314 -- @ 315 -- 316 -- <<docs/gifs/doc_spriteVar.gif>> @@ -345,8 +345,8 @@ span.spaces { background: white } 326 -- 327 -- @ 328 -- do s <- 'fork' $ 'newSpriteA' 'Reanimate.Builtin.Documentation.drawCircle' - 329 -- 'spriteE' s $ 'overBeginning' 1 'fadeInE' - 330 -- 'spriteE' s $ 'overEnding' 0.5 'fadeOutE' + 329 -- 'spriteE' s $ 'Reanimate.Effect.overBeginning' 1 'Reanimate.Effect.fadeInE' + 330 -- 'spriteE' s $ 'Reanimate.Effect.overEnding' 0.5 'Reanimate.Effect.fadeOutE' 331 -- @ 332 -- 333 -- <<docs/gifs/doc_spriteE.gif>> @@ -368,8 +368,8 @@ span.spaces { background: white } 349 -- Example: 350 -- 351 -- @ - 352 -- do s1 \<- 'newSpriteSVG' $ 'withFillOpacity' 1 $ 'withFillColor' "blue" $ 'mkCircle' 3 - 353 -- 'newSpriteSVG' $ 'withFillOpacity' 1 $ 'withFillColor' "red" $ 'mkRect' 8 3 + 352 -- do s1 \<- 'newSpriteSVG' $ 'Reanimate.Svg.Constructors.withFillOpacity' 1 $ 'Reanimate.Svg.Constructors.withFillColor' "blue" $ 'Reanimate.Svg.Constructors.mkCircle' 3 + 353 -- 'newSpriteSVG' $ 'Reanimate.Svg.Constructors.withFillOpacity' 1 $ 'Reanimate.Svg.Constructors.withFillColor' "red" $ 'Reanimate.Svg.Constructors.mkRect' 8 3 354 -- 'wait' 1 355 -- 'spriteZ' s1 1 356 -- 'wait' 1 @@ -394,13 +394,13 @@ span.spaces { background: white } 375 -- 376 -- @ 377 -- do -- the rect lives through the entire 3s animation - 378 -- 'newSpriteSVG_' $ 'translate' (-3) 0 $ 'mkRect' 4 4 + 378 -- 'newSpriteSVG_' $ 'Reanimate.Svg.Constructors.translate' (-3) 0 $ 'Reanimate.Svg.Constructors.mkRect' 4 4 379 -- 'wait' 1 380 -- 'spriteScope' $ do 381 -- -- the circle only lives for 1 second. - 382 -- local \<- 'newSpriteSVG' $ 'translate' 3 0 $ 'mkCircle' 2 - 383 -- 'spriteE' local $ 'overBeginning' 0.3 'fadeInE' - 384 -- 'spriteE' local $ 'overEnding' 0.3 'fadeOutE' + 382 -- local \<- 'newSpriteSVG' $ 'Reanimate.Svg.Constructors.translate' 3 0 $ 'Reanimate.Svg.Constructors.mkCircle' 2 + 383 -- 'spriteE' local $ 'Reanimate.Effect.overBeginning' 0.3 'Reanimate.Effect.fadeInE' + 384 -- 'spriteE' local $ 'Reanimate.Effect.overEnding' 0.3 'Reanimate.Effect.fadeOutE' 385 -- 'wait' 1 386 -- 'wait' 1 387 -- @ diff --git a/reanimate-0.5.0.1-inplace/Reanimate.Scene.Var.hs.html b/reanimate-0.5.0.1-inplace/Reanimate.Scene.Var.hs.html index 926a43f..9c9d99b 100644 --- a/reanimate-0.5.0.1-inplace/Reanimate.Scene.Var.hs.html +++ b/reanimate-0.5.0.1-inplace/Reanimate.Scene.Var.hs.html @@ -24,169 +24,168 @@ span.spaces { background: white } 5 6 import Control.Monad.ST (ST) 7 import qualified Data.Map as M - 8 import Data.Maybe (fromMaybe) - 9 import Data.STRef - 10 import Reanimate.Animation (Duration, Time) - 11 import Reanimate.Scene.Core (Scene, liftST, queryNow, wait) - 12 - 13 -- | Time dependent variable. - 14 newtype Var s a = Var (STRef s (VarData a)) - 15 - 16 -- Note: We must ensure that upon transforming an VarData, - 17 -- 1. evarDefault old == evarDefault new - 18 -- 2. isNothing (evarLastTime old) || isJust (evarLastTime new) i.e. once evarLastValue has a Just value, - 19 -- it shouldn't be Nothing again. - 20 -- 3. isNothing (evarLastTime var) => M.null (evarTimeline var) - 21 data VarData a = VarData - 22 { evarDefault :: a, - 23 evarTimeline :: Timeline a, - 24 evarLastTime :: Maybe Time, - 25 evarLastValue :: a - 26 } - 27 - 28 data Modifier a = StaticValue a | TweenValue Duration (a -> Time -> a) - 29 - 30 type Timeline a = M.Map Time (Modifier a) - 31 - 32 -- | Create a new variable with a default value. - 33 -- Variables always have a defined value even if they are read at a timestamp that is - 34 -- earlier than when the variable was created. For example: - 35 -- - 36 -- @ - 37 -- do v \<- 'fork' ('wait' 10 \>\> 'newVar' 0) -- Create a variable at timestamp '10'. - 38 -- 'readVar' v -- Read the variable at timestamp '0'. - 39 -- -- The value of the variable will be '0'. - 40 -- @ - 41 newVar :: a -> Scene s (Var s a) - 42 newVar def = Var <$> liftST (newSTRef $ VarData def M.empty Nothing def) - 43 - 44 -- | Read the value of a variable at the current timestamp. - 45 readVar :: Var s a -> Scene s a - 46 readVar (Var ref) = readVarData <$> liftST (readSTRef ref) <*> queryNow - 47 - 48 unpackVar :: Var s a -> ST s (Time -> a) - 49 unpackVar (Var ref) = readVarData <$> readSTRef ref - 50 - 51 -- | Write the value of a variable at the current timestamp. - 52 -- - 53 -- Example: - 54 -- - 55 -- @ - 56 -- do v \<- 'newVar' 0 - 57 -- 'newSprite' $ 'mkCircle' \<$\> 'unVar' v - 58 -- 'writeVar' v 1; 'wait' 1 - 59 -- 'writeVar' v 2; 'wait' 1 - 60 -- 'writeVar' v 3; 'wait' 1 - 61 -- @ - 62 -- - 63 -- <<docs/gifs/doc_writeVar.gif>> - 64 writeVar :: Var s a -> a -> Scene s () - 65 writeVar (Var ref) val = do - 66 now <- queryNow - 67 liftST $ modifySTRef ref $ writeVarData now val - 68 - 69 -- | Modify the value of a variable at the current timestamp and all future timestamps. - 70 modifyVar :: Var s a -> (a -> a) -> Scene s () - 71 modifyVar (Var ref) fn = do - 72 now <- queryNow - 73 liftST $ modifySTRef ref $ modifyVarData now fn - 74 - 75 -- | Modify a variable between @now@ and @now+duration@. - 76 tweenVar :: Var s a -> Duration -> (a -> Time -> a) -> Scene s () - 77 tweenVar _ dur _ | dur < 0 = error "Reanimate.tweenVar: durations must be non-negative" - 78 tweenVar (Var ref) dur fn = do - 79 now <- queryNow - 80 liftST $ modifySTRef ref $ tweenVarData now dur fn - 81 wait dur - 82 - 83 readVarData :: VarData a -> Time -> a - 84 readVarData (VarData def _ Nothing _) _ = def - 85 readVarData (VarData def timeline (Just lastTime) lastValue) now - 86 | now < lastTime = lookupTimeline timeline def now - 87 | otherwise = lastValue - 88 - 89 lookupTimeline :: Timeline a -> a -> Time -> a - 90 lookupTimeline timeline def now = case M.lookupLE now timeline of - 91 Just (_, StaticValue sVal) -> sVal - 92 Just (t, TweenValue dur f) - 93 | t + dur > now -> f def now - 94 _ -> def - 95 - 96 writeVarData :: Time -> a -> VarData a -> VarData a - 97 writeVarData now x var = - 98 let before = keepBefore now var - 99 after = VarData (evarDefault var) M.empty (Just now) x - 100 in after `elseVar` before - 101 - 102 modifyVarData :: Time -> (a -> a) -> VarData a -> VarData a - 103 modifyVarData now fn var = - 104 let before = keepBefore now var - 105 after = keepFrom now var - 106 timeline = flip M.map (evarTimeline after) $ \case - 107 StaticValue s -> StaticValue $ fn s - 108 TweenValue dur f -> TweenValue dur $ \a t -> fn (f a t) - 109 in after {evarTimeline = timeline, evarLastValue = fn $ evarLastValue after} `elseVar` before - 110 - 111 -- Note: The function passed here takes time on the scale 0 to 1 - 112 -- while the function in `TweenValue` takes time on an absolute scale. - 113 tweenVarData :: Time -> Duration -> (a -> Time -> a) -> VarData a -> VarData a - 114 tweenVarData st dur fn var@VarData {..} = - 115 let nd = st + dur - 116 before = keepBefore st var - 117 during = keepInRange (Just st) (Just nd) var - 118 tweenFn a t = - 119 let idx = (t - st) / dur - 120 idx' = if isNaN idx then 1 else idx - 121 in fn (readVarData (during {evarDefault = a}) t) idx' - 122 valueTweenEnd = tweenFn evarDefault nd -- we'll never use the def here, replace with error? - 123 after = VarData evarDefault (M.singleton st $ TweenValue dur tweenFn) (Just nd) valueTweenEnd - 124 in after `elseVar` before - 125 - 126 -- Returns the union of two vars such that we use the second var if first var doesn't have a value. - 127 -- Assumes both vars have same default value. - 128 elseVar :: VarData a -> VarData a -> VarData a - 129 elseVar var1 var2 - 130 | Just t <- evarLastTime var1 = - 131 let afterTimeline = evarTimeline var1 - 132 joinAt = fromMaybe t . fmap fst $ M.lookupMin afterTimeline - 133 beforeTimeline = case keepBefore joinAt var2 of - 134 x - 135 | Just lastTime <- evarLastTime x, lastTime < joinAt -> M.insert lastTime (StaticValue $ evarLastValue x) $ evarTimeline x - 136 | otherwise -> evarTimeline x - 137 in var1 {evarTimeline = M.union afterTimeline beforeTimeline} - 138 | otherwise = var2 - 139 - 140 -- Restrict a var to a given time interval. - 141 keepInRange :: Maybe Time -> Maybe Time -> VarData a -> VarData a - 142 keepInRange st nd = fromMaybe id (keepFrom <$> st) . fromMaybe id (keepBefore <$> nd) - 143 - 144 -- Restrict a var to start at given timestamp. - 145 keepFrom :: Time -> VarData a -> VarData a - 146 keepFrom st VarData {..} = - 147 let timeline' = M.dropWhileAntitone (< st) evarTimeline - 148 -- if there is no modifier in timeline starting at st, - 149 -- we must get the modifier that starts before and truncate it to start at st. - 150 timeline'' = case M.lookupLE st evarTimeline of - 151 Just (t, val@(StaticValue _)) - 152 | t < st -> M.insert st val timeline' - 153 Just (t, TweenValue dur fn) - 154 | t < st, t + dur > st -> M.insert st (TweenValue (t + dur - st) fn) timeline' - 155 _ -> timeline' - 156 in VarData evarDefault timeline'' (max evarLastTime $ Just st) evarLastValue - 157 - 158 -- Restrict a var to end(clamp) at given timestamp. - 159 keepBefore :: Time -> VarData a -> VarData a - 160 keepBefore nd var@VarData {..} = - 161 let timeline' = M.takeWhileAntitone (< nd) evarTimeline - 162 lastModifier = M.lookupMax timeline' - 163 timeline'' = case lastModifier of - 164 Just (t, TweenValue dur fn) - 165 | t + dur > nd -> M.insert t (TweenValue (nd - t) fn) timeline' - 166 _ -> timeline' - 167 lastTime = case lastModifier of - 168 Just (t, TweenValue dur _) -> Just $ min nd (t + dur) - 169 _ -> min nd <$> evarLastTime - 170 in VarData evarDefault timeline'' lastTime (fromMaybe evarDefault $ fmap (readVarData var) lastTime) + 8 import Data.STRef + 9 import Reanimate.Animation (Duration, Time) + 10 import Reanimate.Scene.Core (Scene, liftST, queryNow, wait) + 11 + 12 -- | Time dependent variable. + 13 newtype Var s a = Var (STRef s (VarData a)) + 14 + 15 -- Note: We must ensure that upon transforming an VarData, + 16 -- 1. evarDefault old == evarDefault new + 17 -- 2. isNothing (evarLastTime old) || isJust (evarLastTime new) i.e. once evarLastValue has a Just value, + 18 -- it shouldn't be Nothing again. + 19 -- 3. isNothing (evarLastTime var) => M.null (evarTimeline var) + 20 data VarData a = VarData + 21 { evarDefault :: a, + 22 evarTimeline :: Timeline a, + 23 evarLastTime :: Maybe Time, + 24 evarLastValue :: a + 25 } + 26 + 27 data Modifier a = StaticValue a | TweenValue Duration (a -> Time -> a) + 28 + 29 type Timeline a = M.Map Time (Modifier a) + 30 + 31 -- | Create a new variable with a default value. + 32 -- Variables always have a defined value even if they are read at a timestamp that is + 33 -- earlier than when the variable was created. For example: + 34 -- + 35 -- @ + 36 -- do v \<- 'Reanimate.Scene.fork' ('wait' 10 \>\> 'newVar' 0) -- Create a variable at timestamp '10'. + 37 -- 'readVar' v -- Read the variable at timestamp '0'. + 38 -- -- The value of the variable will be '0'. + 39 -- @ + 40 newVar :: a -> Scene s (Var s a) + 41 newVar def = Var <$> liftST (newSTRef $ VarData def M.empty Nothing def) + 42 + 43 -- | Read the value of a variable at the current timestamp. + 44 readVar :: Var s a -> Scene s a + 45 readVar (Var ref) = readVarData <$> liftST (readSTRef ref) <*> queryNow + 46 + 47 unpackVar :: Var s a -> ST s (Time -> a) + 48 unpackVar (Var ref) = readVarData <$> readSTRef ref + 49 + 50 -- | Write the value of a variable at the current timestamp. + 51 -- + 52 -- Example: + 53 -- + 54 -- @ + 55 -- do v \<- 'newVar' 0 + 56 -- 'Reanimate.Scene.newSprite' $ 'Reanimate.Svg.Constructors.mkCircle' \<$\> 'Reanimate.Scene.unVar' v + 57 -- 'writeVar' v 1; 'wait' 1 + 58 -- 'writeVar' v 2; 'wait' 1 + 59 -- 'writeVar' v 3; 'wait' 1 + 60 -- @ + 61 -- + 62 -- <<docs/gifs/doc_writeVar.gif>> + 63 writeVar :: Var s a -> a -> Scene s () + 64 writeVar (Var ref) val = do + 65 now <- queryNow + 66 liftST $ modifySTRef ref $ writeVarData now val + 67 + 68 -- | Modify the value of a variable at the current timestamp and all future timestamps. + 69 modifyVar :: Var s a -> (a -> a) -> Scene s () + 70 modifyVar (Var ref) fn = do + 71 now <- queryNow + 72 liftST $ modifySTRef ref $ modifyVarData now fn + 73 + 74 -- | Modify a variable between @now@ and @now+duration@. + 75 tweenVar :: Var s a -> Duration -> (a -> Time -> a) -> Scene s () + 76 tweenVar _ dur _ | dur < 0 = error "Reanimate.tweenVar: durations must be non-negative" + 77 tweenVar (Var ref) dur fn = do + 78 now <- queryNow + 79 liftST $ modifySTRef ref $ tweenVarData now dur fn + 80 wait dur + 81 + 82 readVarData :: VarData a -> Time -> a + 83 readVarData (VarData def _ Nothing _) _ = def + 84 readVarData (VarData def timeline (Just lastTime) lastValue) now + 85 | now < lastTime = lookupTimeline timeline def now + 86 | otherwise = lastValue + 87 + 88 lookupTimeline :: Timeline a -> a -> Time -> a + 89 lookupTimeline timeline def now = case M.lookupLE now timeline of + 90 Just (_, StaticValue sVal) -> sVal + 91 Just (t, TweenValue dur f) + 92 | t + dur > now -> f def now + 93 _ -> def + 94 + 95 writeVarData :: Time -> a -> VarData a -> VarData a + 96 writeVarData now x var = + 97 let before = keepBefore now var + 98 after = VarData (evarDefault var) M.empty (Just now) x + 99 in after `elseVar` before + 100 + 101 modifyVarData :: Time -> (a -> a) -> VarData a -> VarData a + 102 modifyVarData now fn var = + 103 let before = keepBefore now var + 104 after = keepFrom now var + 105 timeline = flip M.map (evarTimeline after) $ \case + 106 StaticValue s -> StaticValue $ fn s + 107 TweenValue dur f -> TweenValue dur $ \a t -> fn (f a t) + 108 in after {evarTimeline = timeline, evarLastValue = fn $ evarLastValue after} `elseVar` before + 109 + 110 -- Note: The function passed here takes time on the scale 0 to 1 + 111 -- while the function in `TweenValue` takes time on an absolute scale. + 112 tweenVarData :: Time -> Duration -> (a -> Time -> a) -> VarData a -> VarData a + 113 tweenVarData st dur fn var@VarData {..} = + 114 let nd = st + dur + 115 before = keepBefore st var + 116 during = keepInRange (Just st) (Just nd) var + 117 tweenFn a t = + 118 let idx = (t - st) / dur + 119 idx' = if isNaN idx then 1 else idx + 120 in fn (readVarData (during {evarDefault = a}) t) idx' + 121 valueTweenEnd = tweenFn evarDefault nd -- we'll never use the def here, replace with error? + 122 after = VarData evarDefault (M.singleton st $ TweenValue dur tweenFn) (Just nd) valueTweenEnd + 123 in after `elseVar` before + 124 + 125 -- Returns the union of two vars such that we use the second var if first var doesn't have a value. + 126 -- Assumes both vars have same default value. + 127 elseVar :: VarData a -> VarData a -> VarData a + 128 elseVar var1 var2 + 129 | Just t <- evarLastTime var1 = + 130 let afterTimeline = evarTimeline var1 + 131 joinAt = maybe t fst $ M.lookupMin afterTimeline + 132 beforeTimeline = case keepBefore joinAt var2 of + 133 x + 134 | Just lastTime <- evarLastTime x, lastTime < joinAt -> M.insert lastTime (StaticValue $ evarLastValue x) $ evarTimeline x + 135 | otherwise -> evarTimeline x + 136 in var1 {evarTimeline = M.union afterTimeline beforeTimeline} + 137 | otherwise = var2 + 138 + 139 -- Restrict a var to a given time interval. + 140 keepInRange :: Maybe Time -> Maybe Time -> VarData a -> VarData a + 141 keepInRange st nd = maybe id keepFrom st . maybe id keepBefore nd + 142 + 143 -- Restrict a var to start at given timestamp. + 144 keepFrom :: Time -> VarData a -> VarData a + 145 keepFrom st VarData {..} = + 146 let timeline' = M.dropWhileAntitone (< st) evarTimeline + 147 -- if there is no modifier in timeline starting at st, + 148 -- we must get the modifier that starts before and truncate it to start at st. + 149 timeline'' = case M.lookupLE st evarTimeline of + 150 Just (t, val@(StaticValue _)) + 151 | t < st -> M.insert st val timeline' + 152 Just (t, TweenValue dur fn) + 153 | t < st, t + dur > st -> M.insert st (TweenValue (t + dur - st) fn) timeline' + 154 _ -> timeline' + 155 in VarData evarDefault timeline'' (max evarLastTime $ Just st) evarLastValue + 156 + 157 -- Restrict a var to end(clamp) at given timestamp. + 158 keepBefore :: Time -> VarData a -> VarData a + 159 keepBefore nd var@VarData {..} = + 160 let timeline' = M.takeWhileAntitone (< nd) evarTimeline + 161 lastModifier = M.lookupMax timeline' + 162 timeline'' = case lastModifier of + 163 Just (t, TweenValue dur fn) + 164 | t + dur > nd -> M.insert t (TweenValue (nd - t) fn) timeline' + 165 _ -> timeline' + 166 lastTime = case lastModifier of + 167 Just (t, TweenValue dur _) -> Just $ min nd (t + dur) + 168 _ -> min nd <$> evarLastTime + 169 in VarData evarDefault timeline'' lastTime (maybe evarDefault (readVarData var) lastTime)