我想用haskell
光泽创建一个简单的动画。我希望在前 4 秒,每个矩形都会将其颜色更改为较暗的颜色。问题是,经过较长时间的链接后,什么都没有发生——
所有矩形都出现并且它们不会改变颜色
这是我使用的以下代码 -
window :: Display
window = InWindow "Simon" (width, height) (offset, offset)
background :: Color
background = black
data SimonGame = Game {
rectangleGreen::Picture,
rectangleRed::Picture,
rectangleBlue::Picture,
rectanglYellow::Picture
} deriving Show
initialState :: SimonGame
initialState = Game
{ rectangleGreen = translate (-100) (0) $ color green $ rectangleSolid 60 60,
rectangleRed = translate (100) (0) $ color red $ rectangleSolid 60 60,
rectangleBlue = translate (0) (100) $ color blue $ rectangleSolid 60 60,
rectanglYellow = translate (0) (-100) $ color yellow $ rectangleSolid 60 60
}
render :: SimonGame -> Picture
render game = pictures
[ rectangleGreen game,
rectangleRed game,
rectangleBlue game,
rectanglYellow game
]
updateBoard :: Float-> SimonGame -> SimonGame
updateBoard 1.0 game = game {
rectangleGreen = translate (-100) (0) $ color (dark green) $ rectangleSolid 60 60,
rectangleRed = translate (100) (0) $ color red $ rectangleSolid 60 60,
rectangleBlue = translate (0) (100) $ color blue $ rectangleSolid 60 60,
rectanglYellow = translate (0) (-100) $ color yellow $ rectangleSolid 60 60
}
updateBoard 2.0 game = game {
rectangleGreen = translate (-100) (0) $ color green $ rectangleSolid 60 60,
rectangleRed = translate (100) (0) $ color (dark red) $ rectangleSolid 60 60,
rectangleBlue = translate (0) (100) $ color blue $rectangleSolid 60 60,
rectanglYellow = translate (0) (-100) $ color yellow $rectangleSolid 60 60
}
updateBoard 3.0 game = game {
rectangleGreen = translate (-100) (0) $ color green $ rectangleSolid 60 60,
rectangleRed = translate (100) (0) $ color red $ rectangleSolid 60 60,
rectangleBlue = translate (0) (100) $ color (dark blue) $rectangleSolid 60 60,
rectanglYellow = translate (0) (-100) $ color yellow $rectangleSolid 60 60
}
updateBoard 4.0 game = game {
rectangleGreen = translate (-100) (0) $ color green $ rectangleSolid 60 60,
rectangleRed = translate (100) (0) $ color red $ rectangleSolid 60 60,
rectangleBlue = translate (0) (100) $ color blue $rectangleSolid 60 60,
rectanglYellow = translate (0) (-100) $ color (dark yellow) $rectangleSolid 60 60
}
updateBoard _ game = game
main :: IO ()
main = animate window background frame
where
frame :: Float -> Picture
frame seconds = render $ updateBoard seconds initialState