UNPKG

zdog

Version:

Round, flat, designer-friendly pseudo-3D engine

72 lines (57 loc) 1.48 kB
/** * CanvasRenderer */ ( function( root, factory ) { // module definition if ( typeof module == 'object' && module.exports ) { // CommonJS module.exports = factory(); } else { // browser global root.Zdog.CanvasRenderer = factory(); } }( this, function factory() { var CanvasRenderer = { isCanvas: true }; CanvasRenderer.begin = function( ctx ) { ctx.beginPath(); }; CanvasRenderer.move = function( ctx, elem, point ) { ctx.moveTo( point.x, point.y ); }; CanvasRenderer.line = function( ctx, elem, point ) { ctx.lineTo( point.x, point.y ); }; CanvasRenderer.bezier = function( ctx, elem, cp0, cp1, end ) { ctx.bezierCurveTo( cp0.x, cp0.y, cp1.x, cp1.y, end.x, end.y ); }; CanvasRenderer.closePath = function( ctx ) { ctx.closePath(); }; CanvasRenderer.setPath = function() {}; CanvasRenderer.renderPath = function( ctx, elem, pathCommands, isClosed ) { this.begin( ctx, elem ); pathCommands.forEach( function( command ) { command.render( ctx, elem, CanvasRenderer ); } ); if ( isClosed ) { this.closePath( ctx, elem ); } }; CanvasRenderer.stroke = function( ctx, elem, isStroke, color, lineWidth ) { if ( !isStroke ) { return; } ctx.strokeStyle = color; ctx.lineWidth = lineWidth; ctx.stroke(); }; CanvasRenderer.fill = function( ctx, elem, isFill, color ) { if ( !isFill ) { return; } ctx.fillStyle = color; ctx.fill(); }; CanvasRenderer.end = function() {}; return CanvasRenderer; } ) );