Skip to content

Instantly share code, notes, and snippets.

@funrep
Created November 7, 2013 19:06
Show Gist options
  • Save funrep/7360093 to your computer and use it in GitHub Desktop.
Save funrep/7360093 to your computer and use it in GitHub Desktop.
{-# LANGUAGE RankNTypes #-}
import Reactive.Banana
import Reactive.Banana.Frameworks
import qualified Graphics.UI.SDL as SDL
import qualified Graphics.UI.SDL.Image as Image
main = do
SDL.init [SDL.InitEverything]
SDL.rawSetCaption (Just "foobar") Nothing
SDL.setVideoMode 640 480 32 []
img <- Image.load "foo.png"
let networkDescription :: forall t. Frameworks t => Moment t ()
networkDescription = do
bMouse <- fromPoll $ SDL.getMouseState >>= \(x, y, _) -> return (x, y)
eMouse <- changes bMouse
reactimate $ fmap (render img) eMouse
network <- compile networkDescription
actuate network
loop
where
loop = do
event <- SDL.pollEvent
case event of
SDL.Quit -> return ()
_ -> loop
render :: SDL.Surface -> (Int, Int) -> IO ()
render img (x, y) = do
surf <- SDL.getVideoSurface
SDL.blitSurface img (Just (SDL.Rect (x-25) (y-25) 50 50)) surf Nothing
return ()
@funrep
Copy link
Author

funrep commented Nov 7, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment