Skip to content

Latest commit

 

History

History
977 lines (715 loc) · 35.9 KB

API.md

File metadata and controls

977 lines (715 loc) · 35.9 KB

Modules

Canvas
Geometry
Paint

Canvas

Canvas~Canvas

A canvas for drawing paths

Kind: inner class of Canvas

new Canvas(paint, [startPoint])

Creates a new Canvas

Param Type Default Description
paint Paint The paint to use for rendering
[startPoint] Point 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));

canvas.size : Size

The size of the canvas (The size of the terminal)

Kind: instance property of Canvas
Read only: true

canvas.paint : Paint

The paint to use for rendering

Kind: instance property of Canvas

canvas.startPoint : Point

The starting point of the path

Kind: instance property of Canvas
Read only: true

canvas.draw([clear])

Draws the current canvas to the terminal

Kind: instance method of Canvas

Param Type Default Description
[clear] boolean true Whether or not to clear the screen before rendering

canvas.clear()

Without resetting the operations, clears the canvas

Kind: instance method of Canvas

canvas.arc(center, radius, startAngle, endAngle, [anticlockwise])

Draws an arc

Kind: instance method of Canvas

Param Type Default Description
center Point The center-point of the arc
radius number The radius of the arc
startAngle number The angle to start at
endAngle number The angle to end at
[anticlockwise] boolean false Whether or not to draw the arc in an anticlockwise direction

canvas.arcTo(controlPoint1, controlPoint2, radius)

Draws an arc through two controls points

Kind: instance method of Canvas

Param Type Description
controlPoint1 Point The first control point
controlPoint2 Point The second control point
radius number The radius of the arc

canvas.getBounds() ⇒ Array.<Point>

Gets the bounds of the path, hoping that the path is closed

Kind: instance method of Canvas
Returns: Array.<Point> - The points that make up the path bounds

canvas.beginPath([paint]) ⇒ Canvas

Creates a new subpath at the current point

Kind: instance method of Canvas
Returns: Canvas - The subpath

Param Type Default Description
[paint] Paint this.paint The paint to use for the subpath

canvas.bezierCurveTo(controlPoint1, controlPoint2, endPoint)

Draws a cubic bezier curve from the current point to the specified point

Kind: instance method of Canvas

Param Type Description
controlPoint1 Point The first control point
controlPoint2 Point The second control point
endPoint Point The end point

canvas.clearRect(start, size)

Clears a rectangle at the specified point in the screen

Kind: instance method of Canvas

Param Type Description
start Point The top left corner of the rectangle
size Size The size of the rectangle

canvas.clip(path)

Clears a path out of the current path (like a mask)

Kind: instance method of Canvas

Param Type Description
path Canvas The path to clip to

canvas.close()

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

Kind: instance method of Canvas

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

Draws an ellipse

Kind: instance method of Canvas

Param Type Description
center Point The center of the ellipse
radiusX number The radius of the ellipse on the x axis
radiusY number The radius of the ellipse on the y axis
rotation number The rotation of the ellipse (in radians)
startAngle number The start angle of the ellipse (in radians)
endAngle number The end angle of the ellipse (in radians)

canvas.isPointInPath(point) ⇒ boolean

Checks if the specified point is in the path

Kind: instance method of Canvas
Returns: boolean - Whether or not the point is in the path

Param Type Description
point Point The point to check

canvas.isPointInStroke(point, start, end) ⇒ boolean

Determines if the specified point is in the stroke

Kind: instance method of Canvas
Returns: boolean - Whether or not the point is in the stroke

Param Type Description
point Point The point to check
start Point The start point of the line
end Point The end point of the line

canvas.lineTo(point)

Draws a line from the current point to the specified point

Kind: instance method of Canvas

Param Type Description
point Point The point to draw a line to

canvas.subpathAt(point) ⇒ Canvas

Moves the current point to the specified point

Kind: instance method of Canvas

Param Type Description
point Point The point to move to

canvas.quadraticCurveTo(controlPoint, endPoint)

Draws a quadratic bezier curve from the current point to the specified point

Kind: instance method of Canvas

Param Type Description
controlPoint Point The control point
endPoint Point The end point

canvas.rect(startingPoint, size)

Draws a rectangle

Kind: instance method of Canvas

Param Type Description
startingPoint Point The starting point of the rectangle (top left)
size Size The size of the rectangle

canvas.reset(start)

Resets the path, including all the operations

Kind: instance method of Canvas

Param Type Description
start Point The new starting point

canvas.roundRect(startingPoint, size, radii)

Makes a rounded rectangle

Kind: instance method of Canvas

Param Type Description
startingPoint Point The starting point
size Size The size of the rectangle
radii Array.<number> | number The 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.

canvas.transform(matrix)

Transforms all the points in the path by the specified matrix

Kind: instance method of Canvas

Param Type Description
matrix Matrix The matrix to transform the path by

canvas.translate(x, y)

Translates all the points in the path by the specified amount

Kind: instance method of Canvas

Param Type Description
x number The x value to translate by
y number The y value to translate by

canvas.addPath(path, [transform])

Adds a subpath to the path, and optionally applies a transform to it

Kind: instance method of Canvas

Param Type Description
path Path The subpath to add
[transform] Matrix The optional transform to apply to the subpath

Geometry

Geometry~Point

A point in 2D space

Kind: inner class of Geometry

new Point(x, y)

Creates a new Point

Throws:

  • Error If the arguments are invalid or out of bounds
Param Type Description
x number The x coordinate. (Can be any number from 0 to process.stdout.columns)
y number The y coordinate. (Can be any number from 0 to process.stdout.rows)

Example

// Create a new point at (10, 10)
const point = new Point(10, 10);

point.x : number

The x coordinate

Kind: instance property of Point

point.y : number

The y coordinate

Kind: instance property of Point

point.transform(matrix)

Transforms the point by the given matrix

Kind: instance method of Point

Param Type Description
matrix Matrix The matrix to transform the point by

point.equals(x, [y]) ⇒ boolean

Determines whether or not the point is equal to another point

Kind: instance method of Point
Returns: boolean - Whether or not the points are equal

Param Type Description
x PointLike The point to compare to, or the x coordinate
[y] number The y coordinate

Point.center() ⇒ Point

Creates a new point at the center of the terminal

Kind: static method of Point
Returns: Point - The center point

Point.centerFor(x, [y]) ⇒ Point

Kind: static method of Point

Param Type Description
x PointLike The point or size to center, or the x coordinate
[y] number The y coordinate

Point.zero() ⇒ Point

Creates a new point at (0, 0)

Kind: static method of Point
Returns: Point - A new point at (0, 0)

Point.inBounds(px, [y]) ⇒ boolean

Determines whether or not the given point is within the bounds of the terminal

Kind: static method of Point
Returns: boolean - Whether or not the point is within the bounds of the terminal
Throws:

  • Error If the arguments are invalid
Param Type Description
px PointLike The point or size to check, or the x coordinate
[y] number The y coordinate

Point.of(psx, [y]) ⇒ Point

Creates a new point from the given point, size, array, or coordinates

Kind: static method of Point
Returns: Point - The new point

Param Type Description
psx Point | Size | number | Array.<number> | Object The point or size to create a new point from, or the x coordinate
[y] number The y coordinate

Geometry~Matrix

A matrix for transforming points

Kind: inner class of Geometry

new Matrix(a, b, c, d, e, f)

The identity matrix

Param Type Description
a number The a value
b number The b value
c number The c value
d number The d value
e number The e value
f number The f value

matrix.a : number

The a value

Kind: instance property of Matrix

matrix.b : number

The b value

Kind: instance property of Matrix

matrix.c : number

The c value

Kind: instance property of Matrix

matrix.d : number

The d value

Kind: instance property of Matrix

matrix.e : number

The e value

Kind: instance property of Matrix

matrix.f : number

The f value

Kind: instance property of Matrix

Geometry~Size

A size in 2D space

Kind: inner class of Geometry

new Size(width, height)

Creates a new Size

Param Type Description
width number The width
height number The height

Example

// Create a new size of (10, 10)
const size = new Size(10, 10);

size.width : number

The width

Kind: instance property of Size

size.height : number

The height

Kind: instance property of Size

Geometry~PointLike : Point | Size | number | Array.<number> | Object

A point-like object. Can be a Point, Size, number, array, or object with x and y properties.

Kind: inner typedef of Geometry

Paint

Paint~Paint

A paint object

Kind: inner class of Paint

new Paint(strokeColor, fillColor)

Creates a new paint object

Param Type
strokeColor Color | Gradient
fillColor Color | Gradient

Example

// Create a new paint object with a red stroke and a blue fill
const paint = new Paint(Color.Red, Color.Blue);

paint.strokeColor : Color | Gradient

The stroke color

Kind: instance property of Paint

paint.fillColor : Color | Gradient

The fill color

Kind: instance property of Paint

paint.Mode : enum

Kind: instance enum of Paint
Properties

Name Type
Clear Symbol
Paint Symbol
Gradient Symbol

Paint~Color

A color object

Kind: inner class of Paint

new Color(r, g, b)

Creates a new color object

Param Type Description
r number Red
g number Blue
b number Green

Example

// Create a new color object with the RGB values of (255, 0, 0)
const color = new Color(255, 0, 0);

color.depth : number

Kind: instance property of Color
Read only: true

color.Black : Color

Black

Kind: instance property of Color
Read only: true

color.Red : Color

Red

Kind: instance property of Color
Read only: true

color.Green : Color

Green

Kind: instance property of Color
Read only: true

color.Blue : Color

Blue

Kind: instance property of Color
Read only: true

color.White : Color

White

Kind: instance property of Color
Read only: true

color.None : Color

Do not paint

Kind: instance property of Color
Read only: true

color.r : number

Red

Kind: instance property of Color

color.g : number

Green

Kind: instance property of Color

color.b : number

Blue

Kind: instance property of Color

color.toNumber() ⇒ number

Creates a new color from the given number

Kind: instance method of Color

Color.fromNumber(num) ⇒ Color

Creates a color from a number

Kind: static method of Color

Param Type Description
num number Number to convert

Paint~LinearGradient ⇐ Gradient

A linear gradient

Kind: inner class of Paint
Extends: Gradient

new LinearGradient(angle)

Creates a new linear gradient

Param Type Description
angle number The angle direction of the gradient (Radians)

Example

// Create a new gradient that goes from red to blue
let gradient = new LinearGradient(0 /* The angle of the gradient in radians *\/);
gradient.addColorStop(0, Color.Red);
gradient.addColorStop(1, Color.Blue);

linearGradient.getColorAt(fillStart, point, fillEnd) ⇒ Color

Gets the color for a point in the gradient

Kind: instance method of LinearGradient

Param Type Description
fillStart Point The start point of the fill
point Point The point to get the color for
fillEnd Point The end point of the fill

Paint~RadialGradient ⇐ Gradient

A radial gradient

Kind: inner class of Paint
Extends: Gradient

new RadialGradient()

Creates a new radial gradient

Example

// Create a new gradient that goes from red to blue
let gradient = new RadialGradient();
gradient.addColorStop(0, Color.Red);
gradient.addColorStop(1, Color.Blue);

radialGradient.getColorAt(fillStart, point, fillEnd) ⇒ Color

Gets the color for a point in the gradient

Kind: instance method of RadialGradient

Param Type Description
fillStart Point The start point of the fill
point Point The point to get the color for
fillEnd Point The end point of the fill

Paint~ConicGradient ⇐ Gradient

A conic gradient

Kind: inner class of Paint
Extends: Gradient

new ConicGradient(angle)

Creates a new conic gradient

Param Type Description
angle number The angle direction of the gradient (Radians)

Example

// Create a new gradient that goes from red to blue
let gradient = new ConicGradient(0 /* The angle of the gradient in radians *\/);
gradient.addColorStop(0, Color.Red);
gradient.addColorStop(1, Color.Blue);

conicGradient.getColorAt(fillStart, point, fillEnd) ⇒ Color

Gets the color for a point in the gradient

Kind: instance method of ConicGradient

Param Type Description
fillStart Point The start point of the fill
point Point The point to get the color for
fillEnd Point The end point of the fill