mirror of
https://github.com/reanimate/reanimate.git
synced 2026-09-11 16:12:20 +00:00
demo_stars: use fold, give names
This commit is contained in:
parent
82638c078c
commit
06456c44a0
1 changed files with 13 additions and 13 deletions
|
|
@ -30,12 +30,12 @@ main = reanimate $ scene $ do
|
|||
starAnimation :: Animation
|
||||
starAnimation = mkAnimation 10 $ \t ->
|
||||
let camZ = t * 4
|
||||
in withStrokeWidth 0 $ rotate (t * 360) $ mkGroup
|
||||
[ translate (x / newZ) (y / newZ) $ dot (1 - newZ)
|
||||
| (x, y, z) <-
|
||||
reverse $ take nStars $ dropWhile (\(_, _, z) -> z < camZ) allStars
|
||||
, let newZ = z - camZ
|
||||
]
|
||||
dropInvisible = dropWhile $ \(_, _, z) -> z < camZ
|
||||
placeDot (x, y, z) =
|
||||
let newZ = z - camZ
|
||||
in translate (x / newZ) (y / newZ) $ dot (1 - newZ)
|
||||
starSVGs = map placeDot . reverse . take nStars . dropInvisible $ allStars
|
||||
in withStrokeWidth 0 $ rotate (t * 360) $ mkGroup starSVGs
|
||||
where
|
||||
black = PixelRGB8 0x0 0x0 0x0
|
||||
dot o =
|
||||
|
|
@ -52,15 +52,15 @@ trails trailDur raw = mkAnimation (duration raw) $ \t ->
|
|||
in construct $ reverse [idx - trailFrames .. idx]
|
||||
where
|
||||
fps = 200
|
||||
construct [] = mkGroup []
|
||||
construct (x : xs) = mkGroup
|
||||
[ withGroupOpacity (fromIntegral trailFrames / fromIntegral (trailFrames + 1))
|
||||
$ construct xs
|
||||
, getFrame x
|
||||
]
|
||||
|
||||
construct :: [Int] -> SVG
|
||||
construct = foldl' go (mkGroup []) where
|
||||
go acc idx = mkGroup $ [reduceOpacity acc, getFrame idx]
|
||||
reduceOpacity = withGroupOpacity (fromIntegral trailFrames / fromIntegral (trailFrames + 1))
|
||||
getFrame idx = frames V.! (idx `mod` nFrames)
|
||||
|
||||
trailFrames = round (trailDur * fps)
|
||||
nFrames = round (duration raw * fps)
|
||||
getFrame idx = frames V.! (idx `mod` nFrames)
|
||||
frames = V.fromList
|
||||
[ frameAt (fromIntegral i / fromIntegral nFrames * duration raw) raw
|
||||
| i <- [0 .. nFrames]
|
||||
|
|
|
|||
Loading…
Reference in a new issue