mirror of
https://github.com/reanimate/reanimate.git
synced 2026-09-14 09:32:22 +00:00
Add function for modifying glyphs.
This commit is contained in:
parent
a72e95332b
commit
2ae9ad53ca
4 changed files with 65 additions and 13 deletions
19
README.md
19
README.md
|
|
@ -70,6 +70,25 @@ bbox2 = defineAnimation $ proc () -> do
|
||||||
```
|
```
|
||||||

|

|
||||||
|
|
||||||
|
## Colorful LaTeX
|
||||||
|
```haskell
|
||||||
|
latex_color :: Ani ()
|
||||||
|
latex_color = proc () -> do
|
||||||
|
duration 0.1 -< ()
|
||||||
|
emit -< toHtml $ mkBackground "black"
|
||||||
|
emit -< toHtml $ translate (320/2) (180/2) $ withStrokeWidth (Num 0.2) $
|
||||||
|
withStrokeColor "white" $
|
||||||
|
withSubglyphs 0 1 (withFillColor "blue") $
|
||||||
|
withSubglyphs 1 2 (withFillColor "yellow") $
|
||||||
|
withSubglyphs 2 3 (withFillColor "green") $
|
||||||
|
withSubglyphs 3 4 (withFillColor "red") $
|
||||||
|
withSubglyphs 4 5 (withFillColor "darkslategrey") $
|
||||||
|
svg
|
||||||
|
where
|
||||||
|
svg = scale 10 $ center $ latex "\\LaTeX"
|
||||||
|
```
|
||||||
|

|
||||||
|
|
||||||
## Bezier curves
|
## Bezier curves
|
||||||
|
|
||||||

|

|
||||||
|
|
|
||||||
BIN
gifs/latex_color.gif
Normal file
BIN
gifs/latex_color.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.5 KiB |
|
|
@ -478,3 +478,18 @@ heartShape =
|
||||||
"M0.0,40.0 v-40.0 h40.0\
|
"M0.0,40.0 v-40.0 h40.0\
|
||||||
\a20.0 20.0 90.0 0 1 0.0,40.0\
|
\a20.0 20.0 90.0 0 1 0.0,40.0\
|
||||||
\a20.0 20.0 90.0 0 1 -40.0,0.0 Z"
|
\a20.0 20.0 90.0 0 1 -40.0,0.0 Z"
|
||||||
|
|
||||||
|
latex_color :: Ani ()
|
||||||
|
latex_color = proc () -> do
|
||||||
|
duration 0.1 -< ()
|
||||||
|
emit -< toHtml $ mkBackground "black"
|
||||||
|
emit -< toHtml $ translate (320/2) (180/2) $ withStrokeWidth (Num 0.2) $
|
||||||
|
withStrokeColor "white" $
|
||||||
|
withSubglyphs 0 1 (withFillColor "blue") $
|
||||||
|
withSubglyphs 1 2 (withFillColor "yellow") $
|
||||||
|
withSubglyphs 2 3 (withFillColor "green") $
|
||||||
|
withSubglyphs 3 4 (withFillColor "red") $
|
||||||
|
withSubglyphs 4 5 (withFillColor "darkslategrey") $
|
||||||
|
svg
|
||||||
|
where
|
||||||
|
svg = scale 10 $ center $ latex "\\LaTeX"
|
||||||
|
|
|
||||||
|
|
@ -340,14 +340,8 @@ svgBoundingPoints t = map (Transform.transformPoint m) $
|
||||||
mapTuple f = f *** f
|
mapTuple f = f *** f
|
||||||
|
|
||||||
withTransformations :: [Transformation] -> Tree -> Tree
|
withTransformations :: [Transformation] -> Tree -> Tree
|
||||||
withTransformations transformations = withDrawAttributes (transform .~ Just transformations)
|
withTransformations transformations t =
|
||||||
|
mkGroup [t] & drawAttr %~ transform .~ Just transformations
|
||||||
withDrawAttributes :: (DrawAttributes -> DrawAttributes) -> Tree -> Tree
|
|
||||||
withDrawAttributes lens tree = GroupTree $ defaultSvg
|
|
||||||
& drawAttr .~ attr
|
|
||||||
& groupChildren .~ [tree]
|
|
||||||
where
|
|
||||||
attr = defaultSvg & lens
|
|
||||||
|
|
||||||
translate :: Double -> Double -> Tree -> Tree
|
translate :: Double -> Double -> Tree -> Tree
|
||||||
translate x y = withTransformations [Translate x y]
|
translate x y = withTransformations [Translate x y]
|
||||||
|
|
@ -411,19 +405,19 @@ mkColor name =
|
||||||
Just c -> ColorRef c
|
Just c -> ColorRef c
|
||||||
|
|
||||||
withStrokeColor :: String -> Tree -> Tree
|
withStrokeColor :: String -> Tree -> Tree
|
||||||
withStrokeColor color = withDrawAttributes (strokeColor .~ pure (mkColor color))
|
withStrokeColor color = drawAttr %~ strokeColor .~ pure (mkColor color)
|
||||||
|
|
||||||
withFillColor :: String -> Tree -> Tree
|
withFillColor :: String -> Tree -> Tree
|
||||||
withFillColor color = withDrawAttributes (fillColor .~ pure (mkColor color))
|
withFillColor color = drawAttr %~ fillColor .~ pure (mkColor color)
|
||||||
|
|
||||||
withFillOpacity :: Double -> Tree -> Tree
|
withFillOpacity :: Double -> Tree -> Tree
|
||||||
withFillOpacity opacity = withDrawAttributes (fillOpacity .~ Just (realToFrac opacity))
|
withFillOpacity opacity = drawAttr %~ fillOpacity .~ Just (realToFrac opacity)
|
||||||
|
|
||||||
withStrokeWidth :: Number -> Tree -> Tree
|
withStrokeWidth :: Number -> Tree -> Tree
|
||||||
withStrokeWidth width = withDrawAttributes (strokeWidth .~ pure width)
|
withStrokeWidth width = drawAttr %~ strokeWidth .~ pure width
|
||||||
|
|
||||||
withClipPathRef :: ElementRef -> Tree -> Tree
|
withClipPathRef :: ElementRef -> Tree -> Tree
|
||||||
withClipPathRef ref = withDrawAttributes (clipPathRef .~ pure ref)
|
withClipPathRef ref = drawAttr %~ clipPathRef .~ pure ref
|
||||||
|
|
||||||
mkRect :: Point -> Number -> Number -> Tree
|
mkRect :: Point -> Number -> Number -> Tree
|
||||||
mkRect corner width height = RectangleTree $ defaultSvg
|
mkRect corner width height = RectangleTree $ defaultSvg
|
||||||
|
|
@ -451,3 +445,27 @@ mkPathText str =
|
||||||
|
|
||||||
mkBackground :: String -> Tree
|
mkBackground :: String -> Tree
|
||||||
mkBackground color = withFillColor color $ mkRect (Num 0, Num 0) (Percent 100) (Percent 100)
|
mkBackground color = withFillColor color $ mkRect (Num 0, Num 0) (Percent 100) (Percent 100)
|
||||||
|
|
||||||
|
withSubglyphs :: Int -> Int -> (Tree -> Tree) -> Tree -> Tree
|
||||||
|
withSubglyphs from to fn t = evalState (worker t) 0
|
||||||
|
where
|
||||||
|
worker :: Tree -> State Int Tree
|
||||||
|
worker t =
|
||||||
|
case t of
|
||||||
|
GroupTree g -> do
|
||||||
|
cs <- mapM worker (g ^. groupChildren)
|
||||||
|
return $ GroupTree $ g & groupChildren .~ cs
|
||||||
|
PathTree{} -> handleGlyph t
|
||||||
|
CircleTree{} -> handleGlyph t
|
||||||
|
PolyLineTree{} -> handleGlyph t
|
||||||
|
PolygonTree{} -> handleGlyph t
|
||||||
|
EllipseTree{} -> handleGlyph t
|
||||||
|
LineTree{} -> handleGlyph t
|
||||||
|
RectangleTree{} -> handleGlyph t
|
||||||
|
_ -> return t
|
||||||
|
handleGlyph :: Tree -> State Int Tree
|
||||||
|
handleGlyph t = do
|
||||||
|
n <- get <* modify (+1)
|
||||||
|
if n >= from && n < to
|
||||||
|
then return $ fn t
|
||||||
|
else return t
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue