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
| Parameter | Type | Default value | Description |
|---|---|---|---|
x | number | 0 | X component. |
y | number | 0 | Y component. |
z | number | 0 | Z component. |
Returns
TextmodeVector
Properties
x
ts
x: number;X component.
y
ts
y: number;Y component.
z
ts
z: number;Z component.
Methods
| Method | Description |
|---|---|
| add | Add components to this vector. |
| copy | Create a copy of this vector. |
| cross | Calculate the cross product with another vector-like value. |
| dist | Calculate the distance to another vector-like point. |
| div | Divide this vector by a scalar. |
| dot | Calculate the dot product with another vector-like value. |
| heading | Calculate this vector's 2D heading in degrees. |
| limit | Limit this vector's magnitude. |
| mag | Calculate this vector's magnitude. |
| magSq | Calculate this vector's squared magnitude. |
| mult | Multiply this vector by a scalar. |
| normalize | Normalize this vector to length 1. |
| set | Set this vector's components. |
| setMag | Set this vector's magnitude. |
| sub | Subtract components from this vector. |