Created
November 7, 2013 19:06
-
-
Save funrep/7360093 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
foo.png: http://imgur.com/2fawij8