I'm trying to rotate a Picture in Haskell, using the current time as a value for a rotate function. I've got the following main
function:
main :: IO ()
main = do
args <- getArgs
time <- round <$> getPOSIXTime
let initial' = initial time
let (w, h, display) = chooseDisplay args
let background = black
let fps = 60
play display background fps initial' (draw w h) eventHandler timeHandler
The triangle (=player) is stored inside a 'World' data type: module Model where
data World = World {
-- all kinds of World properties --
player :: Picture
}
Then I have a function initial
which initializes the World, and a function playerBody
which, given a rotation value, returns a picture of player
:
initial :: Int -> World
initial _ = World{player = playerBody 0}
playerBody :: Float -> Picture
playerBody rot = Rotate rot $ color red $ Polygon[(-10, 100), (10, 100), (0, 125)]
The draw function is defined as follows:
draw :: Float -> Float -> World -> Picture
draw _ _ world = player world
It currently simply returns the player
Picture.
Now, in my timeHandler module, I want to use the time (given to timeHandler in the main
function) to rotate player
as follows:
timeHandler :: Float -> World -> World
timeHandler time = (\world -> world {player = playerBody time} )
This doesn't work. I replaced time
with a constant value (in the timeHandler function), and that did rotate the Picture. So it seems like time
is not being updated.. what am I doing wrong?