diff --git a/examples/knock_knock.hs b/examples/knock_knock.hs index 02ec1cd..a01e1b2 100755 --- a/examples/knock_knock.hs +++ b/examples/knock_knock.hs @@ -49,9 +49,6 @@ main = reanimate $ docEnv $ mapA (withFillOpacity 1) $ sceneAnimation $ do wait 1 -screenTop :: Double -screenTop = screenHeight/2 - oModifyMany :: [Object s a] -> (ObjectData a -> ObjectData a) -> Scene s () oModifyMany os m = forM_ os $ \o -> oModify o m diff --git a/examples/scene_camera.hs b/examples/scene_camera.hs new file mode 100755 index 0000000..139a118 --- /dev/null +++ b/examples/scene_camera.hs @@ -0,0 +1,144 @@ +#!/usr/bin/env stack +-- stack runghc --package reanimate +{-# LANGUAGE OverloadedStrings #-} +module Main(main) where + +import Reanimate +import Reanimate.Builtin.Documentation +import Reanimate.Scene +import Control.Lens + +main :: IO () +{- +main = reanimate $ docEnv $ mapA (withFillOpacity 1) $ sceneAnimation $ do + cam <- newObject Camera + + newSpriteSVG_ $ withStrokeWidth (defaultStrokeWidth*0.5) $ mkGroup + [ mkLine (0, screenBottom) (0, screenTop) + , mkLine (screenLeft, 0) (screenRight, 0) + ] + + box <- newObject $ Rectangle 1 1 + cameraAttach cam box + oModify box $ oContext .~ withFillColor "green" + oModify box $ oMargin .~ (0,0,0,0) + oModify box $ oLeftX .~ 0 + oModify box $ oBottomY .~ 0 + oModify box $ oContext .~ withStrokeWidth 0 + + box2 <- newObject $ Rectangle 1 1 + cameraAttach cam box2 + oModify box2 $ oContext .~ withFillColor "blue" + oModify box2 $ oMargin .~ (0,0,0,0) + oModify box2 $ oCenterXY .~ (-2,2) + oModify box2 $ oContext .~ withStrokeWidth 0 + + dot <- newObject $ Circle 0.05 + cameraAttach cam dot + oModify dot $ oContext .~ withFillColor "red" + oModify dot $ oMargin .~ (0,0,0,0) + oModify dot $ oCenterXY .~ (0.5,0.5) + oModify dot $ oContext .~ withStrokeWidth 0 + + dot2 <- newObject $ Circle 0.05 + cameraAttach cam dot2 + oModify dot2 $ oContext .~ withFillColor "red" + oModify dot2 $ oMargin .~ (0,0,0,0) + oModify dot2 $ oCenterXY .~ (-2,2) + oModify dot2 $ oContext .~ withStrokeWidth 0 + + oShow box + oShow box2 + oShow dot + oShow dot2 + + wait 1 + + cameraSetFocus cam (0.5, 0.5) + waitOn $ do + fork $ cameraPan cam 1 (0.5, 0.5) + fork $ cameraZoom cam 1 2 + wait 1 + cameraSetFocus cam (-2,2) + cameraZoom cam 0.5 1.5 + cameraZoom cam 0.5 2 + wait 1 + -- cameraSetFocus cam (-0.5,0.5) + waitOn $ do + fork $ cameraPan cam 1 (-2, 2) + fork $ cameraZoom cam 1 0.5 + -- oTweenS cam 2 $ \t -> do + -- oScale %= \v -> fromToS v 3 t + + -- cameraSetFocus cam (0.5,0.5) + + -- oTweenS cam 1 $ \t -> do + -- oScale %= \v -> fromToS v 1 t + -- wait 4 + -- oTweenS cam 2 $ \t -> do + -- oScaleOrigin .= (fromToS 0.5 (-2) t, fromToS 0.5 2 t) + -- oScale .= fromToS 2 1 t + -- oTranslate . _1 %= \v -> fromToS v (-2) t + -- oTranslate . _2 %= \v -> fromToS v 2 t + {- + Origin: (-2,2) + Translate: (3, -1) + New origin: (0.5, 0.5) + + (0.5, 0.5) + (0.5+2, 0.5-2) + (2.5, -1.5) origin move + (2.5*3, -1.5*3) + (7.5, -4.5) scale + (7.5-2, -4.5+2) + (5.5, -2.5) origin move back + (5.5-3, -2.5+1) + (2.5, -1.5) translate + + (0.5-2.5, 0.5-(-1.5)) + (-2, 2) + -} + + wait 1 +-} +main = reanimate $ docEnv $ mapA (withFillOpacity 1) $ sceneAnimation $ do + cam <- newObject Camera + + txt <- newObject $ center $ latex "Fixed (non-cam)" + oModify txt $ + oTopY .~ screenTop + + circle <- newObject $ Circle 1 + cameraAttach cam circle + oModify circle $ oContext .~ withFillColor "blue" + circleRight <- oRead circle oRightX + + box <- newObject $ Rectangle 2 2 + cameraAttach cam box + oModify box $ oContext .~ withFillColor "green" + oModify box $ oLeftX .~ circleRight + boxCenter <- oRead box oCenterXY + + small <- newObject $ center $ latex "This text is very small" + cameraAttach cam small + oModifyS small $ do + oCenterXY .= boxCenter + oScale .= 0.1 + + oShow txt + oShow small + oShow circle + oShow box + + wait 1 + + cameraFocus cam boxCenter + waitOn $ do + fork $ cameraPan cam 3 boxCenter + fork $ cameraZoom cam 3 15 + + wait 2 + waitOn $ do + fork $ cameraZoom cam 3 1 + waitOn $ do + fork $ cameraPan cam 1 (0,0) diff --git a/src/Reanimate.hs b/src/Reanimate.hs index bb5498f..c2c02e1 100644 --- a/src/Reanimate.hs +++ b/src/Reanimate.hs @@ -179,6 +179,10 @@ module Reanimate -- * Constants screenWidth, screenHeight, + screenTop, + screenBottom, + screenLeft, + screenRight, defaultDPI, defaultStrokeWidth, -- * Parameters diff --git a/src/Reanimate/Constants.hs b/src/Reanimate/Constants.hs index 5289b66..fe1e46f 100644 --- a/src/Reanimate/Constants.hs +++ b/src/Reanimate/Constants.hs @@ -1,16 +1,25 @@ module Reanimate.Constants ( screenWidth , screenHeight + , screenTop + , screenBottom + , screenLeft + , screenRight , defaultDPI , defaultStrokeWidth ) where import Graphics.SvgTree -screenWidth, screenHeight :: Num a => a +screenWidth, screenHeight, screenTop :: Fractional a => a +screenBottom, screenLeft, screenRight :: Fractional a => a screenWidth = 16 screenHeight = 9 +screenTop = screenHeight/2 +screenBottom = -screenHeight/2 +screenLeft = -screenWidth/2 +screenRight = screenWidth/2 defaultDPI :: Dpi defaultDPI = 96