我正在尝试在 Haskell 中旋转图片,使用当前时间作为旋转函数的值。我有以下main
功能:
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
三角形(=玩家)存储在“世界”数据类型中:模块模型其中
data World = World {
-- all kinds of World properties --
player :: Picture
}
然后我有一个initial
初始化世界的函数,以及一个playerBody
给定旋转值的函数,它返回一张图片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)]
绘制函数定义如下:
draw :: Float -> Float -> World -> Picture
draw _ _ world = player world
它目前只是返回player
图片。
现在,在我的 timeHandler 模块中,我想使用时间(在main
函数中给定 timeHandler)旋转player
如下:
timeHandler :: Float -> World -> World
timeHandler time = (\world -> world {player = playerBody time} )
这行不通。我time
用一个常量值替换(在 timeHandler 函数中),并且确实旋转了图片。所以似乎time
没有更新..我做错了什么?