This is a spin-off project from [[https://github.com/sabo2/pzprjs]] and [[https://github.com/sabo2/pzprv3]] about drawing routine.
This script enables drawing SVG, canvas by common canvas-like API.
<script src='path/to/dist/candle.js'></src>
By default, this script is exported as Candle
to global.
const Candle = require('pzpr-canvas')
import Candle from 'path/to/dist/candle.module.js'
Use Candle.start(element, [type, [callback]])
to enable this script.
It is recommended to use block elements except <canvas>
HTMLElement.
var Candle = require('pzpr-canvas');
var element = document.getElementById('div');
Candle.start(element, 'svg', function(ctx){
ctx.fillStyle = 'red';
ctx.fillRect(100, 100, 10, 10);
});
After that, document.getElementById('div').getContext('2d')
can be used to obtain context.
element
doesn't have to be an Element. This means, SVG file data can be outputted under node.js environment.
var Candle = require('pzpr-canvas');
var obj = {offsetWidth:200, offsetHeight:200}; // Set default canvas size (optional)
Candle.start(obj);
var ctx = obj.getContext('2d');
ctx.fillStyle = 'red';
ctx.fillRect(100, 100, 10, 10);
console.log(obj.toBuffer()); // <-- output svg data to console buffer
- 2019/05/18 v0.9.0-beta1
- 2017/06/11 v0.8.2
- 2017/04/21 v0.8.1
- 2017/03/20 v0.8.0
MIT