我希望能够使用haskell和gloss绘制类似国际象棋棋盘的东西。
我可以用任何其他语言做类似的事情
for( i=0; i < 10; i++){
for( j=0; j < 10; j++){
drawSquare(radius, i, j)
}
}
就是这样,但是我对Haskell还是陌生的,我不知道如何做到这一点。我正在使用Gloss,并且能够手动绘制东西,但是我希望能够在我绘制100个正方形之前,以程序化的方式逐一创建它们。
如果您在IO monad内部工作,则可以使用相同的样式。例如
printSquares :: IO ()
printSquares =
forM_ [0..9] $ \x ->
forM_ [0..9] $ \y -> do
putStrLn "Here's a square!"
putStrLn ("Square(" ++ show x ++ ", " ++ show y ++ ")")
-- add here the actual drawing Gloss commands
我不熟悉Gloss来建议实际的绘图命令。
更新:Gloss的界面似乎与上述使用IO的界面不同。您可能需要类似的东西
squares :: Picture
squares = Pictures [ square x y | x<-[0..9], y<-[0..9] ]
square :: Float -> Float -> Picture
square x y = Polygon [(x,y), (x+1,y), (x+1,y+1), (x,y+1) ]
-- even better: use rectangleWire and then translate
-- rectangleUpperWire also seems useful
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句