module Graphics.LambdaCanvas
(
Point
, Graphics.Rendering.OpenGL.PrimitiveMode(..)
, animate
, draw
, put
, stepOf
) where
import Data.Time.Clock.POSIX (POSIXTime, getPOSIXTime)
import Graphics.Rendering.OpenGL
import Graphics.UI.GLUT hiding (initialize)
type Point = (GLfloat, GLfloat)
vertex2 :: Point -> IO ()
vertex2 (x, y) = vertex $ Vertex2 x y
put :: PrimitiveMode -> [Point] -> IO ()
put mode pts = renderPrimitive mode $ mapM_ vertex2 pts
initialize :: String -> IO ()
initialize title = do
_ <- getArgsAndInitialize
initialWindowSize $= Size 500 500
initialDisplayMode $= [DoubleBuffered, WithAlphaComponent]
_ <- createWindow title
reshapeCallback $= Just reshape
draw :: String -> IO () -> IO ()
draw title actions = do
initialize title
displayCallback $= do
clear [ColorBuffer]
actions
swapBuffers
mainLoop
animate :: String -> (POSIXTime -> IO ()) -> IO ()
animate title actions = do
initialize title
displayCallback $= do
clear [ColorBuffer]
time <- getPOSIXTime
actions time
swapBuffers
idleCallback $= Just (postRedisplay Nothing)
mainLoop
reshape :: Size -> IO ()
reshape size = do
viewport $= (Position 0 0, size)
postRedisplay Nothing
stepOf :: Num a => Integer -> POSIXTime -> a
stepOf total = fromIntegral . (`mod` total) . truncate . (*1000)