@armniko/canvas
v1.2.0
Published
Simplified and object-based drawing on HTML canvas!
Downloads
89
Maintainers
Readme
Installation
npm install @armniko/canvas
Usage
Create canvas with existing HTMLCanvasElement:
import { Canvas } from '@armniko/canvas';
// assuming that there is <canvas id="canvas"></canvas> in dom
const canvas: Canvas = new Canvas(document.getElementById('canvas'));
Create canvas without existing HTMLCanvasElement:
import { Canvas } from '@armniko/canvas';
const canvas: Canvas = new Canvas();
canvas.setSize({ width: 200, height: 100 });
// append canvas element to dom
document.body.appendChild(canvas.nativeElement());
Draw elements on canvas:
import { TextElement, PositionPoint } from '@armniko/canvas';
canvas.draw(
new TextElement()
.setText('Hello world!')
.setFillColor('#ff0000')
.setFontSize(20)
.setPosition({ x: 100, y: 50 }, PositionPoint.Center)
);