Skip to content
Andy Gill edited this page Jun 19, 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.
{-# LANGUAGE OverloadedStrings #-}
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
                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