Canvas~ Canvas

A canvas for drawing paths

Constructor

new Canvas(paint, startPointopt)

Creates a new `Canvas`
Parameters:
NameTypeAttributesDefaultDescription
paintPaintThe paint to use for rendering
startPointPoint<optional>
Point.zero()The starting point of the path
Example
// Create a new canvas, with a stroke of red
const canvas = new Canvas(new Paint(Color.red));

Members

paint :Paint

The paint to use for rendering
Type:
  • Paint

(readonly) size :Size

The size of the canvas (The size of the terminal)
Type:
  • Size

(readonly) startPoint :Point

The starting point of the path
Type:
  • Point

Methods

addPath(path, transformopt)

Adds a subpath to the path, and optionally applies a transform to it
Parameters:
NameTypeAttributesDescription
pathPathThe subpath to add
transformMatrix<optional>
The optional transform to apply to the subpath

arc(center, radius, startAngle, endAngle, anticlockwiseopt)

Draws an arc
Parameters:
NameTypeAttributesDefaultDescription
centerPointThe center-point of the arc
radiusnumberThe radius of the arc
startAnglenumberThe angle to start at
endAnglenumberThe angle to end at
anticlockwiseboolean<optional>
falseWhether or not to draw the arc in an anticlockwise direction

arcTo(controlPoint1, controlPoint2, radius)

Draws an arc through two controls points
Parameters:
NameTypeDescription
controlPoint1PointThe first control point
controlPoint2PointThe second control point
radiusnumberThe radius of the arc

beginPath(paintopt) → {Canvas}

Creates a new subpath at the current point
Parameters:
NameTypeAttributesDefaultDescription
paintPaint<optional>
this.paintThe paint to use for the subpath
Returns:
The subpath
Type: 
Canvas

bezierCurveTo(controlPoint1, controlPoint2, endPoint)

Draws a cubic bezier curve from the current point to the specified point
Parameters:
NameTypeDescription
controlPoint1PointThe first control point
controlPoint2PointThe second control point
endPointPointThe end point

clear()

Without resetting the operations, clears the canvas

clearRect(start, size)

Clears a rectangle at the specified point in the screen
Parameters:
NameTypeDescription
startPointThe top left corner of the rectangle
sizeSizeThe size of the rectangle

clip(path)

Clears a path out of the current path (like a mask)
Parameters:
NameTypeDescription
pathCanvasThe path to clip to

close()

Closes the last opened subpath, or closes the path if no subpaths are open

draw(clearopt)

Draws the current canvas to the terminal
Parameters:
NameTypeAttributesDefaultDescription
clearboolean<optional>
trueWhether or not to clear the screen before rendering

ellipse(center, radiusX, radiusY, rotation, startAngle, endAngle)

Draws an ellipse
Parameters:
NameTypeDescription
centerPointThe center of the ellipse
radiusXnumberThe radius of the ellipse on the x axis
radiusYnumberThe radius of the ellipse on the y axis
rotationnumberThe rotation of the ellipse (in radians)
startAnglenumberThe start angle of the ellipse (in radians)
endAnglenumberThe end angle of the ellipse (in radians)

getBounds() → {Array.<Point>}

Gets the bounds of the path, hoping that the path is closed
Returns:
The points that make up the path bounds
Type: 
Array.<Point>

isPointInPath(point) → {boolean}

Checks if the specified point is in the path
Parameters:
NameTypeDescription
pointPointThe point to check
Returns:
Whether or not the point is in the path
Type: 
boolean

isPointInStroke(point, start, end) → {boolean}

Determines if the specified point is in the stroke
Parameters:
NameTypeDescription
pointPointThe point to check
startPointThe start point of the line
endPointThe end point of the line
Returns:
Whether or not the point is in the stroke
Type: 
boolean

lineTo(point)

Draws a line from the current point to the specified point
Parameters:
NameTypeDescription
pointPointThe point to draw a line to

quadraticCurveTo(controlPoint, endPoint)

Draws a quadratic bezier curve from the current point to the specified point
Parameters:
NameTypeDescription
controlPointPointThe control point
endPointPointThe end point

rect(startingPoint, size)

Draws a rectangle
Parameters:
NameTypeDescription
startingPointPointThe starting point of the rectangle (top left)
sizeSizeThe size of the rectangle

reset(start)

Resets the path, including all the operations
Parameters:
NameTypeDescription
startPointThe new starting point

roundRect(startingPoint, size, radii)

Makes a rounded rectangle
Parameters:
NameTypeDescription
startingPointPointThe starting point
sizeSizeThe size of the rectangle
radiiArray.<number> | numberThe radii of the corners. If it is a number, or number[1], it will be applied to all corners. If it is a number[2], the first element will apply to the top left and bottom right corners, and the second element will apply to the top right and bottom left corners. If it is a number[4], then the array will be applied to the top left, top right, bottom right, and bottom left corners, respectively.

subpathAt(point) → {Canvas}

Moves the current point to the specified point
Parameters:
NameTypeDescription
pointPointThe point to move to
Returns:
Type: 
Canvas

transform(matrix)

Transforms all the points in the path by the specified matrix
Parameters:
NameTypeDescription
matrixMatrixThe matrix to transform the path by

translate(x, y)

Translates all the points in the path by the specified amount
Parameters:
NameTypeDescription
xnumberThe x value to translate by
ynumberThe y value to translate by