Skip to content
RyanGlScott edited this page Oct 9, 2014 · 7 revisions

This is our first example, a single red line.

To use blank-canvas, we import the library, then call blankCanvas to initiate a web service, in this example, on port 3000. This means that there a blank-canvas page on http://localhost:3000/. Now, for each new blank-canvas page requested, the second argument of blankCanvas is invoked with a session-specific context.

In this example, we send to session-specific page commands to draw a red line by

  • Placing the start of a path at (50,50)
  • Adding a line to (200,100)
  • Setting the line width to 10
  • Setting the stroke style (color) to red
  • Finally, performing these commands on our canvas, using stroke.

So runghc Red_Line.hs, then goto http://localhost:3000/.

{-# LANGUAGE OverloadedStrings #-}
module Main where

import Graphics.Blank                     -- import the blank canvas

main :: IO ()
main = blankCanvas 3000 $ \ context -> do -- start blank canvas on port 3000
        send context $ do                 -- send commands to this specific context
                moveTo(50,50)
                lineTo(200,100)
                lineWidth 10
                strokeStyle "red"
                stroke()                  -- this draws the ink into the canvas
Clone this wiki locally