Skip to content

Latest commit

 

History

History
238 lines (180 loc) · 7.91 KB

PEN-TURTLE-DOC.md

File metadata and controls

238 lines (180 loc) · 7.91 KB

Objects

factory : object

A factory for creating pen-turtles

pen-turtle : object

Turtle graphics-like pen tool

factory : object

A factory for creating pen-turtles

Kind: global namespace

factory.create(options) ⇒ object

Create and return new pen-turtle

Kind: static method of factory

Param Type Description
options object options
options.x number initial x-coordinate of turtle
options.y number initial y-coordinate of turtle
options.heading number initial heading of turtle
options.color number hex color value of line drawn
options.fill number hex fill color value
options.width number width of line drawn
options.precision number floating point precision of numbers stored in path
options.homeX number home x-coordinate for turtle
options.homeY number home y-coordinate for turtle
options.homeHeading number home heading for turtle
options.down boolean initial state of pen being up (false) or down true
options.path array initial path
options.constrain function given x, y, returns true if okay to set new x, y

Example (init with defaults)

const factory = require('@mitchallen/pen-turtle');
let p1 = factory.create();
let p2 = factory.create();

Example (init with values)

let width = 1024,
    height = 1024,
    cx = width / 2,
    cy = height / 2,
let constrain = function( tx, ty ) {
     // only draw if within margin
     let margin = 10.0
     return( tx >= margin && ty >= margin && tx <= (width - margin) && ty <= (height - margin))
}
let pen1 = factory.create({
     x: cx * 1.5,
     y: cy * 1.5,
     color: 0xFF0000,    // red pen
     width: 4,           // pen width 
     alpha: 0.8,         // pen alpha value
     constrain,  // assign constrain function
});

pen-turtle : object

Turtle graphics-like pen tool

Kind: global namespace

pen-turtle.export() ⇒ object

Export

Kind: instance method of pen-turtle

pen-turtle.color() ⇒ number

Returns the pen color as a hex value

Kind: instance method of pen-turtle

pen-turtle.fill() ⇒ number

Returns the fill color as a hex value

Kind: instance method of pen-turtle

pen-turtle.width() ⇒ number

Returns the width of the pen

Kind: instance method of pen-turtle

pen-turtle.path() ⇒ array

Returns the drawing path as an array of commands

Kind: instance method of pen-turtle

pen-turtle.x() ⇒ number

Returns the x-coordinate of the pen

Kind: instance method of pen-turtle

pen-turtle.y() ⇒ number

Returns the y-coordinate of the pen

Kind: instance method of pen-turtle

pen-turtle.heading() ⇒ number

Returns the heading of the pen-turtle

Kind: instance method of pen-turtle

pen-turtle.isDown() ⇒ boolean

Returns true if the pen is down

Kind: instance method of pen-turtle

pen-turtle.push() ⇒ object

Push x, y, head and down state to stack

Kind: instance method of pen-turtle
Returns: object - return this for chaining

pen-turtle.isStackEmpty() ⇒ boolean

Returns true if stack empty

Kind: instance method of pen-turtle

pen-turtle.pop() ⇒ object

Pops x, y, head and down off stack and moves to x, y

Kind: instance method of pen-turtle
Returns: object - return this for chaining

pen-turtle.down() ⇒ object

Put the pen down (enables drawing)

Kind: instance method of pen-turtle
Returns: object - return this for chaining

pen-turtle.up() ⇒ object

Put the pen up (disables drawing)

Kind: instance method of pen-turtle
Returns: object - return this for chaining

pen-turtle.turn(degrees) ⇒ object

Turn the turtle

Kind: instance method of pen-turtle
Returns: object - return this for chaining

Param Type Description
degrees number to turn

pen-turtle.left(degrees) ⇒ object

Turn the turtle to the left

Kind: instance method of pen-turtle
Returns: object - return this for chaining

Param Type Description
degrees number to turn

pen-turtle.right(degrees) ⇒ object

Turn the turtle to the right

Kind: instance method of pen-turtle
Returns: object - return this for chaining

Param Type Description
degrees number to turn

pen-turtle.forward(distance) ⇒ object

Move the turtle forward

Kind: instance method of pen-turtle
Returns: object - return this for chaining

Param Type Description
distance number to move

pen-turtle.home() ⇒ object

Move the turtle to the home position

Kind: instance method of pen-turtle
Returns: object - return this for chaining