https://github.com/haskell-github-trust/static-canvas
A tiny DSL for HTML5 Canvas
https://github.com/haskell-github-trust/static-canvas
Last synced: about 2 months ago
JSON representation
A tiny DSL for HTML5 Canvas
- Host: GitHub
- URL: https://github.com/haskell-github-trust/static-canvas
- Owner: haskell-github-trust
- License: bsd-3-clause
- Created: 2015-02-06T23:53:54.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2019-05-22T02:55:04.000Z (over 6 years ago)
- Last Synced: 2025-12-08T14:19:51.760Z (about 2 months ago)
- Language: Haskell
- Homepage: https://hackage.haskell.org/package/static-canvas
- Size: 3.83 MB
- Stars: 34
- Watchers: 1
- Forks: 6
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
# static-canvas [](https://hackage.haskell.org/package/static-canvas)
A simple DSL for writing HTML5 Canvas in haskell and converting it
to Javascript. By static we mean non-interactive, so the parts of
the Canvas API that need to query the browser for run time information
like `isPointInPath(x, y)` are not included. This turns out to be
a surprisingly small part of HTML5 Canvas.
Here is Hello static-canvas with fancy text.

```haskell
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Graphics.Static
import Graphics.Static.ColorNames
text :: CanvasFree ()
text = do
font "italic 60pt Calibri"
lineWidth 6
strokeStyle blue
fillStyle goldenrod
textBaseline TextBaselineMiddle
strokeText "Hello" 150 100
fillText "Hello World!" 150 100
main :: IO ()
main = writeCanvasDoc "Text.html" 600 400 text
```
There are plenty of examples in [Examples](https://github.com/jeffreyrosenbluth/static-canvas/tree/master/examples).
Here is one more showing how to use pattern to fill a rectangle.

```haskell
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Graphics.Static
pattern :: CanvasFree ()
pattern = do
img <- newImage "tile.png"
onImageLoad img $ do
ptn <- createPattern img Repeat
rect 0 0 400 400
fillStyle ptn
fill
main :: IO ()
main = writeCanvasDoc "Pattern.html" 400 400 pattern
```