Last active
January 6, 2021 15:56
-
-
Save Cj-bc/7246af31c927a8cf8075b303474846cf to your computer and use it in GitHub Desktop.
Some snippets for reanimate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
animation, animation' :: Animation | |
animation = scene $ do | |
play $ mkAnimation 1 $ const $ withFillOpacity 0 $ center $ mkRoundedBox (screenWidth/2) (screenHeight/2) 0.1 | |
animation' = scene $ do | |
s <- fork $ newSpriteA drawBox' | |
spriteE s $ overBeginning 0.5 fadeInE | |
spriteE s $ overEnding 0.5 fadeOutE | |
fork $ play $ mapA (withStrokeColor "red") $ drawCircle' | |
obj <- oNew $ mkText "Test" | |
oShow obj | |
oTweenS obj 2 (\t -> oRightX %= \origin -> fromToS origin screenRight t) | |
drawBox' :: Animation | |
drawBox' = mkAnimation 2 $ \t -> | |
partialSvg t $ pathify $ withStrokeColor "black" $ withFillOpacity 0 $ mkRect (screenWidth/2) (screenHeight/2) | |
drawCircle' :: Animation | |
drawCircle' = mkAnimation 2 $ \t -> | |
partialSvg t $ pathify $withFillOpacity 0 $ mkCircle (screenHeight/2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkRoundedBox :: Double -> Double -> Double -> SVG | |
mkRoundedBox w h rpercent = withStrokeColor "black" | |
$ mkPath [ SVG.MoveTo SVG.OriginRelative [V2 0 0] | |
, SVG.HorizontalTo SVG.OriginRelative [w'] | |
, SVG.QuadraticBezier SVG.OriginRelative [(V2 radW 0, V2 radW (-radH))] | |
, SVG.VerticalTo SVG.OriginRelative [-h'] | |
, SVG.QuadraticBezier SVG.OriginRelative [(V2 0 (-radH), V2 (-radW) (-radH))] | |
, SVG.HorizontalTo SVG.OriginRelative [-w'] | |
, SVG.QuadraticBezier SVG.OriginRelative [(V2 (-radW) 0, V2 (-radW) radH)] | |
, SVG.VerticalTo SVG.OriginRelative [h'] | |
, SVG.QuadraticBezier SVG.OriginRelative [(V2 0 radH, V2 radW radH)] | |
] | |
where | |
radW = w * rpercent | |
radH = h * rpercent | |
w' = w - radW | |
h' = h - radH | |
editor :: Double -> Double -> SVG | |
editor w h = withStrokeColor "gray" | |
$ mkGroup [ translate 0.2 0 $ | |
mkPath [SVG.MoveTo SVG.OriginRelative [V2 0 0] | |
, SVG.VerticalTo SVG.OriginRelative [-h] | |
] | |
, mkRoundedBox w h 0.05 | |
, mkClipPath "Editor" [mkRoundedBox w h 0.05] | |
, withClipPathRef (SVG.Ref "Editor") $ translate (-0.1) 0 numberLine | |
] | |
numberLine :: SVG | |
numberLine = gridLayout $ sequence [map (scale 0.15 . mkText . T.pack . show) [0..30]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment