-2

我有一个简单的窗口,显示两个形状,如下所示:

import Graphics.Gloss

circles = pictures [Translate 80 0 one, Translate (-80) 0 two]

main = display (InWindow "t" (400,400) (800,0)) white circles

one = Color red $ Circle 80
two = Color blue $ Circle 50

我是 Gloss 的新手,但是从我收集的内容来看,“显示”只是在运行主(即我的模块)后显示静态图像,所以你不能使用“显示”制作动画,对吗?

我想做的是用这些形状运行我的程序,但不是同时显示它们,我想先显示一个圆圈,然后再显示另一个圆圈,就像某种动画一样。

到目前为止,我只能做一些静态的事情,并在程序运行时立即显示两个圆圈。但我希望他们像Run the program -> (0 sec) Blank screen -> (1 sec) One of the circles is drawn -> (2 sec) the other circle is drawn -> The window now displays circles until I close it.

使用“动画”功能应该很简单,但我无法弄清楚。如果有人有知识,请考虑提供帮助!这真的会让我很开心。

4

1 回答 1

3

您用于animate根据动画时间绘制图片:

main = animate (InWindow "t" (400,400) (800,0)) white draw

draw :: Float -> Picture
draw t
   | t <= 1    = blank                                                -- in the first second
   | t <= 2    = pictures [Translate 80 0 one]                        -- between 1s and 2s
   | otherwise = pictures [Translate 80 0 one, Translate (-80) 0 two] -- afterwards
于 2017-02-21T18:18:18.470 回答