Skip to content

lisandropodesta/canvas-tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

canvas-tool

Canvas helper and primitives serializer

Usage

.getPrimitives()

Creates an object, with similar interface to canvas, that stores all primitives executed and allows to enumeration and painting.

var cvTool = require( "canvas-tool" );
var pri_ctx = cvTool.getPrimitives();
pri_ctx.fillStyle = "white";
pri_ctx.strokeStyle = "blue";
pri_ctx.moveTo( 10, 20 );
pri_ctx.lineTo( 5, 10 );
pri_ctx.stroke();

pri_ctx.enum( function( p ) {
  // do something
} );

pri_ctx.paint( "canvas-element" );

.getContext( value )

Gets the canvas context of one of this options:

  • Canvas element ID
  • Canvas element
var cvTool = require( "canvas-tool" );
var ctx = cvTool.getContext( "canvas-element" );
ctx.moveTo( 10, 20 );
ctx.lineTo( 5, 10 );
ctx.stroke();

.getAttr( value )

Checks if value is a valid canvas attribute and returns the attribute name. Future use includes translations as a dictionary.

var cvTool = require( "canvas-tool" );
if ( cvTool.getAttr( "fillStyle" ) ) {
  // fillStyle is a valid canvas attribute
}

About

Canvas helper and primitives serializer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published