Replace 'here' dependency with the lightweight 'neat-interpolation' (#106)

Misc improvements:
 * Add tasty-rerun
 * Extend CI coverage
This commit is contained in:
David Himmelstrup 2020-07-12 13:27:01 +08:00 committed by GitHub
commit 34aa5780ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 155 additions and 91 deletions

View file

@ -1,10 +1,11 @@
#!/usr/bin/env stack
-- stack runghc --package reanimate --package here
-- stack runghc --package reanimate
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
module Main (main) where
import Data.String.Here
import qualified Data.Text as T
import NeatInterpolation
import Reanimate
main :: IO ()
@ -12,13 +13,13 @@ main = reanimate $ mkAnimation 5 $ \t ->
let s = t * pi in
mkGroup
[ mkBackground "black"
, blender (script s)
, blender (script $ T.pack $ show s)
, withFillColor "white" $
translate 0 2 $
mkText "default cube"
]
where
script s = [iTrim|
script s = [text|
import bpy
if __name__ == "__main__":

View file

@ -1,11 +1,11 @@
#!/usr/bin/env stack
-- stack runghc --package reanimate --package here
-- stack runghc --package reanimate
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
module Main (main) where
import Data.String.Here
import qualified Data.Text as T
import NeatInterpolation
import Reanimate
main :: IO ()
@ -13,18 +13,18 @@ main = reanimate $ mkAnimation 5 $ \t ->
let s = t * pi * 2 in
mkGroup
[ mkBackground "black"
, blender (script s)
, blender (script $ T.pack $ show s)
]
texture :: FilePath
texture = svgAsPngFile (mkGroup
texture :: T.Text
texture = T.pack $ svgAsPngFile (mkGroup
[ checker 10 10
, withFillColor "red" $
scale 2 $ center $
latexAlign "\\sum_{k=1}^\\infty {1 \\over k^2} = {\\pi^2 \\over 6}"])
script :: Double -> T.Text
script s = [iTrim|
script :: T.Text -> T.Text
script s = [text|
import os
import bpy
@ -48,7 +48,7 @@ texture = mat.node_tree.nodes['Principled BSDF']
texture.inputs['Roughness'].default_value = 1
mat.node_tree.links.new(image_node.outputs['Color'], texture.inputs['Base Color'])
image_node.image = bpy.data.images.load('${T.pack texture}')
image_node.image = bpy.data.images.load('${texture}')
scn = bpy.context.scene
#scn.render.engine = 'CYCLES'

View file

@ -1,20 +1,21 @@
#!/usr/bin/env stack
-- stack runghc --package reanimate --package here
-- stack runghc --package reanimate
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE QuasiQuotes #-}
module Main (main) where
import qualified Data.Text as T
import NeatInterpolation
import Reanimate
import Data.String.Here
main :: IO ()
main = reanimate $ mkAnimation 5 $ \t ->
let s = fromToS 0 360 t in
mkGroup
[ mkBackground "black"
, povray [] (script s) ]
, povray [] (script $ T.pack $ show s) ]
where
script s = [iTrim|
script s = [text|
//EXAMPLE OF SPHERE
//Files with predefined colors and textures

View file

@ -1,8 +1,8 @@
#!/usr/bin/env stack
-- stack runghc --package reanimate --package here
-- stack runghc --package reanimate
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ApplicativeDo #-}
module Main (main) where
import Reanimate
@ -11,9 +11,9 @@ import Codec.Picture.Types
import Control.Lens ((^.))
import Control.Monad
import Data.Monoid
import Data.String.Here
import qualified Data.Text as T
import Graphics.SvgTree
import Graphics.SvgTree hiding (text)
import NeatInterpolation
import System.Random
import System.Random.Shuffle
@ -59,14 +59,21 @@ texture t = svgAsPngFile $ mkGroup
]
script :: FilePath -> Double -> Double -> Double -> Double -> T.Text
script img bend transZ rotX rotY = [iTrim|
script img bend transZ rotX rotY =
let img_ = T.pack img
bend_ = T.pack $ show bend
transZ_ = T.pack $ show transZ
rotX_ = T.pack $ show rotX
rotY_ = T.pack $ show rotY
yScale_ = T.pack $ show (fromToS (9/2) 4 bend)
in [text|
import os
import math
import bpy
cam = bpy.data.objects['Camera']
cam.location = (0,0,22.25 + ${transZ})
cam.location = (0,0,22.25 + ${transZ_})
cam.rotation_euler = (0, 0, 0)
bpy.ops.object.empty_add(location=(0.0, 0, 0))
focus_target = bpy.context.object
@ -75,7 +82,7 @@ cam.select_set(True)
focus_target.select_set(True)
bpy.ops.object.parent_set()
focus_target.rotation_euler = (${rotX}, 0, 0)
focus_target.rotation_euler = (${rotX_}, 0, 0)
origin = bpy.data.objects['Cube']
@ -83,10 +90,10 @@ bpy.ops.object.select_all(action='DESELECT')
origin.select_set(True)
bpy.ops.object.delete()
x = ${bend}
x = ${bend_}
bpy.ops.mesh.primitive_plane_add()
plane = bpy.context.object
plane.scale = (16/2,${fromToS (9/2) 4 bend},1)
plane.scale = (16/2,${yScale_},1)
bpy.ops.object.shade_smooth()
bpy.context.object.active_material = bpy.data.materials['Material']
@ -96,7 +103,7 @@ texture = mat.node_tree.nodes['Principled BSDF']
texture.inputs['Roughness'].default_value = 1
mat.node_tree.links.new(image_node.outputs['Color'], texture.inputs['Base Color'])
image_node.image = bpy.data.images.load('${T.pack img}')
image_node.image = bpy.data.images.load('${img_}')
modifier = plane.modifiers.new(name='Subsurf', type='SUBSURF')
@ -130,7 +137,7 @@ plane.select_set(True);
bpy.ops.object.origin_clear()
bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN')
plane.rotation_euler = (0, ${rotY}, 0)
plane.rotation_euler = (0, ${rotY_}, 0)
scn = bpy.context.scene

View file

@ -1,16 +1,17 @@
#!/usr/bin/env stack
-- stack runghc --package reanimate --package here
-- stack runghc --package reanimate
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
module Main (main) where
import Reanimate
import Reanimate.Povray (povraySlow')
import Reanimate.Povray (povraySlow')
import Codec.Picture
import Control.Monad
import Data.String.Here
import Data.Text (Text)
import Data.Text (Text)
import qualified Data.Text as T
import NeatInterpolation
main :: IO ()
main = reanimate $ parA bg $ sceneAnimation $ do
@ -50,7 +51,11 @@ texture :: SVG
texture = checker 10 10
script :: FilePath -> Double -> Double -> Text
script png rotX rotY = [iTrim|
script png rotX rotY =
let png_ = T.pack png
rotX_ = T.pack $ show rotX
rotY_ = T.pack $ show rotY
in [text|
#include "colors.inc"
//Place the camera
@ -73,11 +78,11 @@ sphere {
<0,0,0>, 3
texture {
uv_mapping pigment{
image_map{ png ${png} }
image_map{ png ${png_} }
}
}
rotate <0,${rotY},0>
rotate <${rotX},0,0>
rotate <0,${rotY_},0>
rotate <${rotX_},0,0>
}
|]

View file

@ -1,5 +1,5 @@
#!/usr/bin/env stack
-- stack runghc --package reanimate --package here
-- stack runghc --package reanimate
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ApplicativeDo #-}
@ -12,10 +12,11 @@ import Codec.Picture
import Codec.Picture.Types
import Control.Lens ((^.))
import Control.Monad
import qualified Data.Text as T
import Data.Monoid
import Data.String.Here
import NeatInterpolation
import Data.Text (Text)
import Graphics.SvgTree hiding (Text)
import Graphics.SvgTree hiding (Text,text)
import System.Random
import System.Random.Shuffle
@ -46,7 +47,12 @@ texture :: Double -> SVG
texture t = frameAt (t*duration latexExample) latexExample
script :: FilePath -> Double -> Double -> Double -> Text
script png transZ rotX rotZ = [iTrim|
script png transZ rotX rotZ =
let png_ = T.pack png
rotX_ = T.pack $ show rotX
transZ_ = T.pack $ show transZ
rotZ_ = T.pack $ show rotZ
in [text|
#include "colors.inc"
//Place the camera
@ -69,13 +75,13 @@ polygon {
<0, 0>, <0, 1>, <1, 1>, <1, 0>
texture {
pigment{
image_map{ png ${png} }
image_map{ png ${png_} }
}
}
translate <-1/2,-1/2>
scale <16,9>
rotate <0,${rotX},${rotZ}>
translate <0,0,${transZ}>
rotate <0,${rotX_},${rotZ_}>
translate <0,0,${transZ_}>
}
|]

View file

@ -1,8 +1,8 @@
#!/usr/bin/env stack
-- stack runghc --package reanimate --package here
-- stack runghc --package reanimate
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ApplicativeDo #-}
module Main (main) where
import Reanimate
@ -13,9 +13,10 @@ import Codec.Picture.Types
import Control.Lens ((^.))
import Control.Monad
import Data.Monoid
import Data.String.Here
import Data.Text (Text)
import Graphics.SvgTree hiding (Text)
import qualified Data.Text as T
import Graphics.SvgTree hiding (Text,text)
import NeatInterpolation
import System.Random
import System.Random.Shuffle
@ -53,7 +54,12 @@ texture t = mkGroup
]
script :: FilePath -> Double -> Double -> Double -> Text
script png rotX rotY rotZ = [iTrim|
script png rotX rotY rotZ =
let png_ = T.pack png
rotX_ = T.pack $ show rotX
rotY_ = T.pack $ show rotY
rotZ_ = T.pack $ show rotZ
in [text|
//Files with predefined colors and textures
#include "colors.inc"
@ -82,11 +88,11 @@ sphere {
<0,0,0>, 4
texture {
uv_mapping pigment{
image_map{ png ${png} }
image_map{ png ${png_} }
}
}
rotate <0,${rotY},${rotZ}>
rotate <${rotX},0,0>
rotate <0,${rotY_},${rotZ_}>
rotate <${rotX_},0,0>
}
|]