mirror of
https://github.com/reanimate/reanimate.git
synced 2026-09-10 23:52:22 +00:00
Potrace example.
Former-commit-id: 5206414b9c83ce38fac903fc00a735207acff25d
This commit is contained in:
parent
80321bbb61
commit
eadc0ef23a
4 changed files with 67 additions and 19 deletions
|
|
@ -271,3 +271,18 @@ This file is auto-generated by docs/render_all.sh. DO NOT EDIT.
|
|||
|
||||
<br/><hr><br/>
|
||||
|
||||
## tut_glue_potrace
|
||||
|
||||
<details>
|
||||
<summary>View tut_glue_potrace.hs</summary>
|
||||
<pre><code class="haskell">
|
||||
{!examples/tut_glue_potrace.hs!}
|
||||
</code></pre>
|
||||
</details>
|
||||
<br/>
|
||||
<video width="640" height="360" autoplay loop>
|
||||
<source src="https://github.com/Lemmih/reanimate/raw/master/docs/rendered/tut_glue_potrace.mp4">
|
||||
</video>
|
||||
|
||||
<br/><hr><br/>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ EXAMPLES='boundingbox colormaps goo latex_basic latex_color latex_draw
|
|||
latex_wheel raster sphere blender_default_cube
|
||||
tut_glue_svg tut_glue_animate tut_glue_keyframe tut_glue_fourier
|
||||
tut_glue_physics tut_glue_latex tut_glue_povray
|
||||
tut_glue_povray_ortho'
|
||||
tut_glue_povray_ortho tut_glue_potrace'
|
||||
|
||||
WIDTH=640
|
||||
HEIGHT=$((WIDTH*9/16))
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ Scripting in Haskell also gives access to the extensive body of code libraries.
|
|||
|
||||
LaTeX is a widely used system for typesetting equations and documents. It is most commonly used by writing TeX documents which are then converted to pdfs. However, since the output of LaTeX is natively vector graphics, it is trivial to get SVG documents instead of pdfs. Armed with this knowledge, Reanimate offers a simple yet powerful function: `latex :: Text -> SVG`
|
||||
|
||||
The `latex` function takes a snippet of TeX code, passes it through the LaTeX system, and converts the result to an SVG image. Furthermore, since the result is entirely determined by the TeX code, caching is used to hide the overhead of invoking LaTeX.
|
||||
The `latex` function takes a snippet of TeX code, passes it through the LaTeX system, and converts the result to an SVG image. Furthermore, since the result is entirely determined by the TeX code, caching is used to hide the overhead of invoking LaTeX.
|
||||
|
||||
The resulting SVGs can be manipulated just like any other. The below examples illustrates how different effects can be applied to different glyphs in the equation.
|
||||
|
||||
|
|
@ -158,4 +158,14 @@ TODO: Morph SVG animation into sphere.
|
|||
|
||||
## Pillar V: potrace
|
||||
|
||||
|
||||
<details>
|
||||
<summary>Toggle source code.</summary>
|
||||
<pre><code class="haskell">
|
||||
{!examples/tut_glue_potrace.hs!}
|
||||
</code></pre>
|
||||
</details>
|
||||
<br/>
|
||||
<video width="640" height="360" autoplay loop>
|
||||
<source src="../rendered/tut_glue_potrace.mp4">
|
||||
<source src="https://github.com/Lemmih/reanimate/raw/master/docs/rendered/tut_glue_potrace.mp4">
|
||||
</video>
|
||||
|
|
|
|||
|
|
@ -24,30 +24,55 @@ import System.Random.Shuffle
|
|||
|
||||
main :: IO ()
|
||||
main = reanimate $ parA bg $ sceneAnimation $ do
|
||||
play $ mkAnimation drawDuration $ \t -> partialSvg t (wireframe (-45) 220)
|
||||
xRot <- newVar (-45)
|
||||
yRot <- newVar 220
|
||||
_ <- newSprite $ do
|
||||
-- _ <- newSprite $ do
|
||||
-- getX <- freezeVar xRot
|
||||
-- getY <- freezeVar yRot
|
||||
-- return $ \real_t dur t ->
|
||||
-- povraySlow [] $
|
||||
-- script (svgAsPngFile (texture (t/dur))) (getX real_t) (getY real_t) 0
|
||||
wf <- newSprite $ do
|
||||
getX <- freezeVar xRot
|
||||
getY <- freezeVar yRot
|
||||
return $ \real_t dur t ->
|
||||
povray [] $
|
||||
script (svgAsPngFile (texture (t/dur))) (getX real_t) (getY real_t) 0
|
||||
wireframe (getX real_t) (getY real_t)
|
||||
--wait 2
|
||||
let tDuration = 3
|
||||
tweenVar yRot tDuration (\t v -> fromToS v (v+180) $ curveS 2 (t/tDuration))
|
||||
tweenVar xRot (tDuration/2) (\t v -> fromToS v (v+90) $ curveS 2 (t/(tDuration/2)))
|
||||
fork $ do
|
||||
wait (tDuration/2)
|
||||
tweenVar xRot (tDuration/2) (\t v -> fromToS v (v-90) $ curveS 2 (t/(tDuration/2)))
|
||||
wait tDuration
|
||||
tweenVar yRot spinDur (\t v -> fromToS v (v+60*3) $ curveS 2 (t/spinDur))
|
||||
replicateM_ wobbles $ do
|
||||
tweenVar xRot (wobbleDur/2) (\t v -> fromToS v (v+90) $ curveS 2 (t/(wobbleDur/2)))
|
||||
fork $ do
|
||||
wait (wobbleDur/2)
|
||||
tweenVar xRot (wobbleDur/2) (\t v -> fromToS v (v-90) $ curveS 2 (t/(wobbleDur/2)))
|
||||
wait wobbleDur
|
||||
--wait 2
|
||||
destroySprite wf
|
||||
play $ mkAnimation drawDuration (\t -> partialSvg t (wireframe (-45) 220))
|
||||
# reverseA
|
||||
where
|
||||
drawDuration = 10
|
||||
wobbles = 3
|
||||
wobbleDur = 3
|
||||
spinDur = fromIntegral wobbles * wobbleDur
|
||||
bg = animate $ const $ mkBackgroundPixel $ PixelRGBA8 252 252 252 0xFF
|
||||
|
||||
texture :: Double -> SVG
|
||||
texture t = mkGroup
|
||||
[ checker 20 20
|
||||
]
|
||||
wireframe :: Double -> Double -> SVG
|
||||
wireframe rotX rotY =
|
||||
withStrokeColor "black" $
|
||||
withStrokeWidth (defaultStrokeWidth*0.2) $
|
||||
withFillOpacity 0 $
|
||||
lowerTransformations $
|
||||
flipYAxis $
|
||||
translate (-screenWidth/2) (-screenHeight/2) $
|
||||
scale (screenWidth/2560) $
|
||||
mkPath $ extractPath $
|
||||
vectorize_ ["-t","100"] $
|
||||
povraySlow' [] $
|
||||
script (svgAsPngFile texture) rotX rotY 0
|
||||
|
||||
texture :: SVG
|
||||
texture = checker 10 10
|
||||
|
||||
script :: FilePath -> Double -> Double -> Double -> Text
|
||||
script png rotX rotY rotZ = [iTrim|
|
||||
|
|
@ -119,5 +144,3 @@ checker w h =
|
|||
stepY = screenHeight/fromIntegral h
|
||||
offsetX = screenWidth/2
|
||||
offsetY = screenHeight/2
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue