Skip to content

textmode.js / TextmodeVector

Class: TextmodeVector

Mutable two- or three-dimensional vector for creative-coding math.

TextmodeVector stores public x, y, and z components and uses chainable mutating methods for common motion, steering, and force operations.

Use Textmodifier.createVector to create vectors inside a sketch.

Example

Constructors

Constructor

ts
new TextmodeVector(
   x?, 
   y?, 
   z?): TextmodeVector;

Create a new vector with the given components.

Parameters

ParameterTypeDefault valueDescription
xnumber0X component.
ynumber0Y component.
znumber0Z component.

Returns

TextmodeVector

Properties

x

ts
x: number;

X component.


y

ts
y: number;

Y component.


z

ts
z: number;

Z component.

Methods

MethodDescription
addAdd components to this vector.
copyCreate a copy of this vector.
crossCalculate the cross product with another vector-like value.
distCalculate the distance to another vector-like point.
divDivide this vector by a scalar.
dotCalculate the dot product with another vector-like value.
headingCalculate this vector's 2D heading in degrees.
limitLimit this vector's magnitude.
magCalculate this vector's magnitude.
magSqCalculate this vector's squared magnitude.
multMultiply this vector by a scalar.
normalizeNormalize this vector to length 1.
setSet this vector's components.
setMagSet this vector's magnitude.
subSubtract components from this vector.