diff --git a/docs/gallery.md b/docs/gallery.md index d618912..34da9e7 100644 --- a/docs/gallery.md +++ b/docs/gallery.md @@ -271,3 +271,18 @@ This file is auto-generated by docs/render_all.sh. DO NOT EDIT.


+## tut_glue_potrace + +
+ View tut_glue_potrace.hs +

+  {!examples/tut_glue_potrace.hs!}
+  
+
+
+ + +


+ diff --git a/docs/gen_gallery.sh b/docs/gen_gallery.sh index afbd8fc..799d351 100755 --- a/docs/gen_gallery.sh +++ b/docs/gen_gallery.sh @@ -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)) diff --git a/docs/glue_tut.md b/docs/glue_tut.md index b509e1f..0f1134b 100644 --- a/docs/glue_tut.md +++ b/docs/glue_tut.md @@ -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 - +
+ Toggle source code. +

+  {!examples/tut_glue_potrace.hs!}
+  
+
+
+ diff --git a/examples/tut_glue_potrace.hs b/examples/tut_glue_potrace.hs index d6ebe0c..cc67594 100755 --- a/examples/tut_glue_potrace.hs +++ b/examples/tut_glue_potrace.hs @@ -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 - -