1.0.1 • Published 6 years ago

ts-simplecanvas v1.0.1

Weekly downloads
4
License
GNU GPL v3
Repository
github
Last release
6 years ago

SimpleCanvas

Simple HTML5 Canvas wrapper written with typescript.

This is a simple wrapper around HTML5 canvas. It simplifies using canvas.

Example:

var canvas = new SimpleCanvas("my-canvas");
canvas.drawLine(20, 20, 150, 200, "red");

API

constructor

var canvas = new SimpleCanvas("mycanvas"); Creates a new SimpleCanvas.

Parameters:

NameTypeDescriptionDefault value
containerstring or HTMLElementEither ID of the container element or ID of the canvas or container element itself or the canvas element itself

if the 'container' argument is not a canvas (or ID of a canvas element), then a canvas will be created inside the container.

  • drawLine(x1, y1, x2, y2, color, lineWidth, alpha)

Draws a line from (x1,y1) to (x2,y2).

Parameters:

NameTypeDescriptionDefault value
x1, y1numberStarting point coordinates
x2, y2numberEnd point coordinates
colorstringDrawing color"black"
lineWidthnumberLine width1
alphafloating point numberAlpha. 0 means transparent. 1 means opaque.1
  • drawRect(x, y, width, height, strokeColor, lineWidth, fillColor, alpha)

Draws a rectangle. Optionally filled with a color.

Parameters:

NameTypeDescriptionDefault value
x, ynumberTop-left corner coordinates
width, heightnumberSize of the rectangle
strokeColorstringLines color"black"
lineWidthnumberLine width1
fillColorstringFill color'' (not filled)
alphafloating point numberAlpha. 0 means transparent. 1 means opaque.
  • drawCircle(x, y, radius, strokeColor, lineWidth, fillColor, alpha)

Draws a circle. Optionally filled with a color.

Parameters:

NameTypeDescriptionDefault value
x, ynumberCenter coordinates
radiusnumberCircle radius
strokeColorstringLine color"black"
lineWidthnumberLine width1
fillColorstringFill color'' (not filled)
alphafloating point numberAlpha. 0 means transparent. 1 means opaque.
  • drawImage(src, x, y, width, height, alpha)

Draws an image with specified URL on the canvas.

Parameters:

NameTypeDescriptionDefault value
srcstringURL of the image
x, ynumberTop-left corner coordinates
width, heightnumberSize of the image
alphafloating point numberAlpha. 0 means transparent. 1 means opaque.