Canvas
Canvas — 2D drawing bindings for March compiled with --target js.
Wraps the browser's CanvasRenderingContext2D. Requires --target js; calling these functions from a native build panics.
Usage: match Dom.find("game-canvas") do None -> () Some(node) -> match Canvas.get_context(node) do None -> () Some(ctx) -> Canvas.set_fill_style(ctx, "#e74c3c") Canvas.fill_rect(ctx, 10.0, 10.0, 80.0, 40.0) end end
Functions
Add a circular arc centered at (x, y) with the given radius, from start_angle to end_angle (radians, clockwise). Use start_angle = 0.0, end_angle = 6.283185307179586 (2*pi) for a full circle.
Start a new path, discarding any path built so far.
Add a cubic Bezier curve from the path's current point to (x, y), using (cp1x, cp1y) and (cp2x, cp2y) as control points.
Clear the rectangle at (x, y) of size (w, h) to fully transparent.
Close the current path by drawing a straight line back to its start point.
Draw img at (x, y) using its natural size.
Draw img at (x, y), scaled to (w, h).
Fill the current path with the current fill style.
Fill a circle centered at (cx, cy) with radius radius using a tileable, world-aligned value-noise texture (a soft cloudy/wispy look), faded to transparent at the edge. alpha caps the overall opacity. The noise tile is generated once and cached, so repeated calls are cheap.
Fill the rectangle at (x, y) of size (w, h) with the current fill style.
Draw text filled with the current fill style, baseline at (x, y).
Get the 2D drawing context for a <canvas> element. Returns None if node is not a canvas element.
Add a straight line from the path's current point to (x, y).
Load an image from url (asynchronously). Returns Err with a message if the image fails to load.
Move the path's current point to (x, y) without drawing.
Add a quadratic Bezier curve from the path's current point to (x, y), using (cpx, cpy) as the control point.
Pop the most recently saved drawing state, restoring transform and styles.
Rotate subsequent drawing by angle radians, clockwise around the current origin.
Push the current drawing state (transform, styles) onto a stack. Pair with restore.
Scale subsequent drawing by (sx, sy).
Set the fill color/style used by fill_rect, fill, and fill_text (any CSS color string, e.g. \
Set the font used by fill_text/stroke_text (CSS font shorthand, e.g. \
Set the global alpha (opacity) for subsequent drawing, from 0.0 (transparent) to 1.0 (opaque).
Set the line width (in canvas units) used by stroke_rect and stroke.
Set the stroke color/style used by stroke_rect, stroke, and stroke_text.
Set horizontal text alignment for fill_text/stroke_text: \
Stroke the current path's outline with the current stroke style.
Stroke the outline of the rectangle at (x, y) of size (w, h) with the current stroke style.
Draw text outlined with the current stroke style, baseline at (x, y).
Translate the drawing origin by (x, y).