Animation Haskell光泽未设置动画
我有一个模拟社区中许多代理交互的程序。我正在使用动画制作交互,代理的图片正确渲染,而不是动画。我通过生成一个模拟来设置它的动画,这个模拟是一个交互列表,然后我取对应于第二个动画的一个,然后在那里渲染该交互。用于模拟的代码在输出到终端时工作良好。守则:Animation Haskell光泽未设置动画,animation,haskell,graphics,gloss,Animation,Haskell,Graphics,Gloss,我有一个模拟社区中许多代理交互的程序。我正在使用动画制作交互,代理的图片正确渲染,而不是动画。我通过生成一个模拟来设置它的动画,这个模拟是一个交互列表,然后我取对应于第二个动画的一个,然后在那里渲染该交互。用于模拟的代码在输出到终端时工作良好。守则: render :: Int -> History -> Picture -- assume window to be square render size (History int agents) = Pictures $ map
render :: Int -> History -> Picture -- assume window to be square
render size (History int agents) = Pictures $ map (drawAgent (step`div`2) colors step) agents
where step = size*6 `div` (length agents)
--agents = nub $ concat $ map (\(Interaction a1 a2 _ ) -> [a1,a2]) int
nubNames = nub $ map (getName . name) agents --ignore the first two letters of name
colors = Map.fromList $ zipWith (\name color-> (name, color)) nubNames (cycle colorlist)
colorlist = [red,green,blue,yellow,cyan,magenta,rose,violet,azure,aquamarine,chartreuse,orange]
drawAgent :: Int -> Map.Map String Color -> Int -> Agent -> Picture
drawAgent size colors step agent =
color aColor (Polygon [(posA,posB),(posA,negB),(negA,negB),(negA,posB)])
where aColor = fromMaybe black $ Map.lookup (getName $ name agent ) colors
a = (fst $ position agent) * step
b = (snd $ position agent) * step
posA = fromIntegral $ a+size
negA = fromIntegral $ a-size
posB = fromIntegral $ b+size
negB = fromIntegral $ b-size
simulate :: Int -> [Agent] -> [History]
simulate len agents = trace ("simulation"
(playRound agents len) :
simulate len (reproduce (playRound agents len))
main = do
a <- getStdGen
G.animate (G.InWindow "My Window" (400, 400) (0,0)) G.white
(\time ->(render 400) $ ((simulate 5 (agent a))!!(floor time)))
where agent a = generate a 9
sim a = simulate 40 (agent a)
它将继续这样,直到我停止它,每次渲染相同的图片。我做错了什么?(所以评论框不允许我粘贴代码)
你的代码不适合我。您使用的是哪个版本的Gloss,API已从v1.0更改为v1.7.x。什么版本的GHC?什么操作系统
这个简单的例子对你有用吗
{- left click to create a circle; escape to quit -}
import Graphics.Gloss
import Graphics.Gloss.Interface.Pure.Game
initial _ = [(0.0,0.0) :: Point]
event (EventMotion (x,y)) world = world --(x,y)
event (EventKey (MouseButton LeftButton) Up mods (x,y)) world = (x,y):world
event _ world = world
step time world = world
draw pts = Pictures $ map f pts
where f (x,y) = translate x y (circle 10)
m = play (InWindow "Hi" (600,600) (200,200)) white 1 (initial 0) draw event step
你的代码不适合我。您使用的是哪个版本的Gloss,API已从v1.0更改为v1.7.x。这个简单的例子对你有用吗?谢谢,只要更新gloss并切换到游戏,我就能让它工作了。
{- left click to create a circle; escape to quit -}
import Graphics.Gloss
import Graphics.Gloss.Interface.Pure.Game
initial _ = [(0.0,0.0) :: Point]
event (EventMotion (x,y)) world = world --(x,y)
event (EventKey (MouseButton LeftButton) Up mods (x,y)) world = (x,y):world
event _ world = world
step time world = world
draw pts = Pictures $ map f pts
where f (x,y) = translate x y (circle 10)
m = play (InWindow "Hi" (600,600) (200,200)) white 1 (initial 0) draw event step