npm.io
0.0.6 • Published 6 years ago

@mystroken/canvas

Licence
MIT
Version
0.0.6
Deps
0
Size
6 kB
Vulns
0
Weekly
0

Canvas

contributions welcome

Object oriented canvas 2D rendering in JavaScript.


Installation

npm install @mystroken/canvas

Usage

Look at the sources files for more information.

Import

import Canvas from '@mystroken/canvas';
import Renderable from '@mystroken/canvas/Renderable'; 
Create a renderable.
class Circle extends Renderable {

    render(ctx) {
        ctx.beginPath();
        ctx.arc(110, 110, 25, Math.PI * 2, false);
        ctx.closePath();

        ctx.stroke();
    }
}
Add renderables on the canvas.
const canvas = new Canvas(document.querySelector('#canvas'));

// Get some renderables.
const circle = new Circle();
const rect = new Rectangle();

// Adds renderables to canvas.
canvas.add(circle);
canvas.add(rect);

// Render the canvas.
canvas.render();

Keywords