pencil.js / path / Instruction
Class: Instruction
Defined in: path.ts:32
Single drawing step of a Path
Constructors
Constructor
ts
new Instruction(
action,
target,
type?,
args?
): Instruction;Defined in: path.ts:52
Instruction constructor
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
action | InstructionCallback | undefined | Function to execute |
target | PositionDefinition | undefined | Position to go to |
type? | string | null | null | Name of the instruction (needed for serialization) |
args? | unknown[] | [] | Additional arguments passed to the action |
Returns
Instruction
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
action | InstructionCallback | Function to execute | path.ts:34 |
args | unknown[] | Additional arguments | path.ts:43 |
target | Position | Position to go to | path.ts:37 |
type | string | null | Name of the instruction (null for custom instruction) | path.ts:40 |
Methods
execute()
ts
execute(path, previousPosition): Position;Defined in: path.ts:65
Follow the instruction
Parameters
| Parameter | Type | Description |
|---|---|---|
path | Path2D | Current drawing path |
previousPosition | Position | Position from where the instruction start |
Returns
The position reached
toJSON()
ts
toJSON(): InstructionJSON;Defined in: path.ts:73
Return a json ready object (only for instructions created with Path's static methods)
Returns
from()
ts
static from(definition): Instruction;Defined in: path.ts:89
Return an instance from a generic object
Parameters
| Parameter | Type | Description |
|---|---|---|
definition | InstructionJSON | Instruction | Instruction definition |
Returns
Instruction
