An ergonomic HTML canvas wrapper geared towards animation frames.
<script type="module">
import { Context2D } from 'https://unpkg.com/context2d';
const draw = ({ ctx, w, h, oscillate, memoize }) => {
...
}
const context2d = new Context2D();
context2d.draw(draw);
</script>
Returns an instance of Context2D, which has one public method: draw
(see below)
Type: object
Type: number
Default: Root element's offsetWidth
The canvas width.
Type: number
Default: Root element's offsetHeight
The canvas height.
Type: string
| HTMLElement
Default: document.body
The element or element ID to which the canvas will be appended.
Type: object
type: CanvasRenderingContext2D
The canvas context.
type: number
The canvas width.
type: number
The canvas height.
type: Function
Memoizes the provided fn. Re-runs fn when window is resized.
type: Function
Returns a sine wave.
type : obect
type: number
The from pixels that the oscillate fn will return. Default is -1.
type: number
The to pixels that the oscillate fn will return. Default is -1.
type: number
Speed is in Hz, so 1 is one cycle per second.
type: number