Skip to content
Andy Gill edited this page Mar 10, 2015 · 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.
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Control.Concurrent
import Graphics.Blank

main :: IO ()
main = blankCanvas 3000 $ flip loop 0

loop :: DeviceContext -> Double -> IO ()
loop context n = do
        send context $ do
                clearRect (0,0,width context,height context)
                beginPath()
                save()
                translate (width context / 2,height context / 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)
Clone this wiki locally