module Test where
import Control.Applicative (pure,(<$>))
import qualified Graphics.UI.GLUT as G
import FRP.Reactive (Behavior,time)
import FRP.Reactive.GLUT.Adapter
main :: IO ()
main = adapt "Reactive on GLUT" $ (fmap.fmap) view t2
type G = UI -> Behavior Action
t1, t2 :: G
t1 = const (pure (drawBox (0::Double,0)))
t2 = const (f <$> time)
where
f t = drawBox (t',t') where t' = t * 1
view :: IO () -> IO ()
view act = G.preservingMatrix $
do G.translate (G.Vector3 0 0 (30 :: Double))
act
vertexPF :: G.VertexComponent a => (a,a) -> IO ()
vertexPF = G.vertex . uncurry G.Vertex2
drawBox :: (G.MatrixComponent c, Fractional c) => (c, c) -> IO ()
drawBox (centerX,centerY) = G.preservingMatrix $
do G.translate $ G.Vector3 centerX centerY 0
G.renderPrimitive G.Polygon (mapM_ vertexPF ps)
where
ps :: [(Float,Float)]
ps = [(1,1),(1,1),(1,1),(1,1)]