Skip to content

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 ​

ParameterTypeDefault valueDescription
actionInstructionCallbackundefinedFunction to execute
targetPositionDefinitionundefinedPosition to go to
type?string | nullnullName of the instruction (needed for serialization)
args?unknown[][]Additional arguments passed to the action

Returns ​

Instruction

Properties ​

PropertyTypeDescriptionDefined in
actionInstructionCallbackFunction to executepath.ts:34
argsunknown[]Additional argumentspath.ts:43
targetPositionPosition to go topath.ts:37
typestring | nullName 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 ​

ParameterTypeDescription
pathPath2DCurrent drawing path
previousPositionPositionPosition from where the instruction start

Returns ​

Position

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 ​

InstructionJSON


from() ​

ts
static from(definition): Instruction;

Defined in: path.ts:89

Return an instance from a generic object

Parameters ​

ParameterTypeDescription
definitionInstructionJSON | InstructionInstruction definition

Returns ​

Instruction

Released under the MIT License.