null-canvas-0.2.7: HTML5 Canvas Graphics Library - forked Blank Canvas

Safe HaskellNone




Starting blank-canvas

blankCanvas :: Int -> (Context -> IO ()) -> IO ()Source

blankCanvas is the main entry point into blank-canvas. A typical invocation would be

module Main where

import Graphics.Blank

main = blankCanvas 3000 $ \ context -> do
        send context $ do
                lineWidth 10
                strokeStyle "red"

launch single-canvas app on specified port

blankCanvasMany :: Int -> [(String, Context -> IO ())] -> IO ()Source

launch multiple canvas apps, each with a prefix, like `/myprefix/foo/bar`

blankCanvasManyParams :: Int -> [(String, Context -> IO ())] -> FilePath -> Bool -> IO ()Source

as blankCanvasMany but takes customization parameters dataDir and performLogging

blankCanvasParams :: Int -> (Context -> IO ()) -> FilePath -> Bool -> String -> IO ()Source

as blankCanvas but takes customization parameters dataDir and performLogging

blankCanvasParamsScotty :: (Context -> IO ()) -> FilePath -> Bool -> String -> IO (ScottyM ())Source

parametrised version of blankCanvas, also returns ScottyM application instead of running a server. use scotty to run it.

Graphics Context

data Context Source

Context is our abstact handle into a specific 2d-context inside a browser.

send :: Context -> Canvas a -> IO aSource

Sends a set of Canvas commands to the canvas. Attempts to common up as many commands as possible.

events :: Context -> EventName -> IO EventQueueSource

events gets the raw event queue for a specific event type.

Drawing pictures using the Canvas DSL

custom :: String -> Canvas ()Source

sends command (JS) unchanged. useful for extending this library with functionality it doesn't currently have. example:

 custom $ unlines $ [
       "var grd=c.createRadialGradient(0,0,3,20,20,10); "

readEvent :: EventName -> Canvas EventSource

read a specific event; wait for it if the event is not in queue.

tryReadEvent :: EventName -> Canvas (Maybe Event)Source

read a specific event; or return Nothing if the event is not in queue.

size :: Canvas (Float, Float)Source

size of the canvas


data Event Source

Basic Event from Browser, the code is event-type specific.




jsCode :: Int
jsMouse :: Maybe (Int, Int)


data EventName Source

EventName mirrors event names from jquery, where 'map toLower (show name)' gives the jquery event name.

type EventQueue = TChan EventSource

EventQueue is a STM channel (TChan) of Events. Intentionally, EventQueue is not abstract.