module Test where
import Data.Monoid
import Control.Applicative
import Data.VectorSpace
import FRP.Reactive
import FRP.Reactive.GLUT.Adapter
import Graphics.FieldTrip
import FRP.Reactive.FieldTrip.Adapter
main :: IO ()
main =
anim3 lplace
txt :: Geometry2
txt = utext "Reactive + FieldTrip"
accumLB :: a -> (a->a) -> Anim a
accumLB a f ui = a `accumB` (f <$ leftButtonPressed ui)
signFlip :: Anim Double
signFlip = accumLB 1 negate
revTxt :: String -> Anim2
revTxt str ui = utext <$> accumLB str reverse ui
rotTxt :: Double -> Geometry2
rotTxt t = rotate2 t *% txt
motionTxt :: Anim3
motionTxt = (fmap.fmap) (flatG . (uscale2 (0.5::R) *%) . utext . show) mouseMotion
track :: Anim2
track = (fmap.fmap) (f . uncurry Vector2) mousePosition
where
f = (uscale2 (0.5::Float) *%) . utext . show
spin :: Anim3
spin = spinningG $
torusPair
torusPair :: Geometry3
torusPair = f red (1/2) `mappend` pivot3X (f green (1/2))
where
tor = torus 1 (2/5)
f :: Col -> R -> Geometry3
f col dx = plasmat col (move3X dx tor)
reverseVel :: (UI -> Event a) -> Anim Double
reverseVel ue = uiIntegral vel
where
vel ui = 1 `accumB` (negate <$ ue ui)
drops :: Event () -> Behavior Geometry3
drops e = monoidB (g <$> withTimeE_ e)
where
g0 = uscale3 (0.3 :: R) *% torusPair
g t0 = liftA2 (*%) (f <$> time) (pure g0)
where
f t = translate3 (Vector3 (tt0) 0 (5))
drops' :: Event (Vector3 Double) -> Event () -> Behavior Geometry3
drops' starts tick = monoidB (g <$> (starts `snapRemainderE` tick))
where
g0 = uscale3 (0.3 :: R) *% torusPair
g (start,tick') = f <$> integral tick' (integral tick' acc)
where
f pos = translate3 (start ^+^ pos) *% g0
acc = pure ((2) *^ yVector3)
ldrops :: Anim3
ldrops ui =
drops' (leftButtonPressed ui `snapshot_` mouseMotion ui)
(framePass ui)
place :: Event (Vector3 Double) -> Behavior Geometry3
place starts = monoidB (g <$> starts)
where
g start = f <$> spinningG torusPair (error "blort!")
where f = (translate3 start *%)
lplace :: Anim3
lplace ui = place (leftButtonPressed ui `snapshot_` mouseMotion ui)
mouseMotion :: Anim (Vector3 Double)
mouseMotion = (fmap.fmap) f mousePosition
where
f (mx,my) = vector3 mx my 0
plasmat :: Col -> Filter3
plasmat col = materialG (plastic col)
spinningG :: Geometry3 -> Anim3
spinningG g env = liftA2 (*%) (spinning env) (pure g)
spinning :: Anim (Transform3 Double)
spinning = const (xf . (*2) <$> time)
where
xf t = translate3 (Vector3 (0::Double) 0 (3*sin (t/5)))
`mappend` rotate3 t (Vector3 0.1 0.2 0.3)
`mappend` uscale3 0.2