- factory :
object
A factory for creating pen-turtles
- pen-turtle :
object
Turtle graphics-like pen tool
A factory for creating pen-turtles
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
});
Turtle graphics-like pen tool
Kind: global namespace
- pen-turtle :
object
- .export() ⇒
object
- .color() ⇒
number
- .fill() ⇒
number
- .width() ⇒
number
- .path() ⇒
array
- .x() ⇒
number
- .y() ⇒
number
- .heading() ⇒
number
- .isDown() ⇒
boolean
- .push() ⇒
object
- .isStackEmpty() ⇒
boolean
- .pop() ⇒
object
- .down() ⇒
object
- .up() ⇒
object
- .turn(degrees) ⇒
object
- .left(degrees) ⇒
object
- .right(degrees) ⇒
object
- .forward(distance) ⇒
object
- .home() ⇒
object
- .export() ⇒
Export
Kind: instance method of pen-turtle
Returns the pen color as a hex value
Kind: instance method of pen-turtle
Returns the fill color as a hex value
Kind: instance method of pen-turtle
Returns the width of the pen
Kind: instance method of pen-turtle
Returns the drawing path as an array of commands
Kind: instance method of pen-turtle
Returns the x-coordinate of the pen
Kind: instance method of pen-turtle
Returns the y-coordinate of the pen
Kind: instance method of pen-turtle
Returns the heading of the pen-turtle
Kind: instance method of pen-turtle
Returns true if the pen is down
Kind: instance method of pen-turtle
Push x, y, head and down state to stack
Kind: instance method of pen-turtle
Returns: object
- return this for chaining
Returns true if stack empty
Kind: instance method of pen-turtle
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
Put the pen down (enables drawing)
Kind: instance method of pen-turtle
Returns: object
- return this for chaining
Put the pen up (disables drawing)
Kind: instance method of pen-turtle
Returns: object
- return this for chaining
Turn the turtle
Kind: instance method of pen-turtle
Returns: object
- return this for chaining
Param | Type | Description |
---|---|---|
degrees | number |
to turn |
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 |
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 |
Move the turtle forward
Kind: instance method of pen-turtle
Returns: object
- return this for chaining
Param | Type | Description |
---|---|---|
distance | number |
to move |
Move the turtle to the home position
Kind: instance method of pen-turtle
Returns: object
- return this for chaining