mirror of
https://github.com/reanimate/reanimate.git
synced 2026-09-12 00:23:08 +00:00
Begin introduction to reanimate.
Former-commit-id: aae07ee92e90626de681be94689adf206fc782b8
This commit is contained in:
parent
e39ec9e97f
commit
0da599d563
6 changed files with 150 additions and 49 deletions
55
examples/tut_glue_animate.hs
Normal file
55
examples/tut_glue_animate.hs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/env stack
|
||||
-- stack runghc --package reanimate
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Main(main) where
|
||||
|
||||
import Codec.Picture.Types
|
||||
import Data.Text (Text)
|
||||
import Reanimate
|
||||
import Reanimate.Animation
|
||||
import Reanimate.Effect
|
||||
import Reanimate.Scene
|
||||
|
||||
bgColor :: String
|
||||
bgColor = "white"
|
||||
|
||||
segmentDuration :: Double
|
||||
segmentDuration = 3
|
||||
|
||||
transitionTime :: Double
|
||||
transitionTime = 0.5
|
||||
|
||||
main :: IO ()
|
||||
main = reanimate $ bg `parA`
|
||||
transitions fadeInE fadeOutE transitionTime
|
||||
[animateCircleR, animateCircleP, animateRectR, animateColor
|
||||
,signalA (constantS 0) $ setDuration transitionTime animateCircleR]
|
||||
where
|
||||
bg = animate $ const $ mkBackground bgColor
|
||||
|
||||
animateCircleR :: Animation
|
||||
animateCircleR = mkSegment "radius" $ \t -> mkCircle (t*2)
|
||||
|
||||
animateCircleP :: Animation
|
||||
animateCircleP = mkSegment "drawn" $ \t ->
|
||||
withFillOpacity 0 $ partialSvg t (pathify $ mkCircle 2)
|
||||
|
||||
animateRectR :: Animation
|
||||
animateRectR = mkSegment "rotation" $ \t -> rotate (t*360) $ mkRect 4 2
|
||||
|
||||
animateColor :: Animation
|
||||
animateColor = mkSegment "color" $ \t ->
|
||||
withFillColorPixel (promotePixel $ turbo t) $ mkRect 4 2
|
||||
|
||||
mkSegment :: Text -> (Time -> SVG) -> Animation
|
||||
mkSegment label gen = mkAnimation segmentDuration $ \t -> env $
|
||||
mkGroup
|
||||
[ gen t
|
||||
, withStrokeWidth 0 $ translate 0 3 $ scale 2 $
|
||||
center $ latex label ]
|
||||
|
||||
env :: SVG -> SVG
|
||||
env =
|
||||
withStrokeColor "red" .
|
||||
withFillColor "black" .
|
||||
withStrokeWidth (defaultStrokeWidth*2)
|
||||
Loading…
Reference in a new issue