-
Notifications
You must be signed in to change notification settings - Fork 14
Rotating Square
Andy Gill edited this page Jun 15, 2014
·
9 revisions
This example shows how to do basic animations.
- We have a recursive function,
loop
. - At the start of each iteration, we clear the screen.
- We move to the center of the canvas, and draw a green rotated square.
- We then pause for a short while. (This is critical to the animation smoothness)
- We then recursive with a slightly rotated value.
module Main where
import Graphics.Blank
import Control.Concurrent
main = blankCanvas 3000 $ \ context -> do
loop context (0 :: Float)
loop context n = do
send context $ do
(width,height) <- size
clearRect (0,0,width,height)
beginPath()
save()
translate (width / 2,height / 2)
rotate (pi * n)
beginPath()
moveTo(-100,-100)
lineTo(-100,100)
lineTo(100,100)
lineTo(100,-100)
closePath()
lineWidth 10
strokeStyle "green"
stroke()
restore()
threadDelay (20 * 1000)
loop context (n + 0.01)