JXG.Turtle

Class

This is the Turtle class. Constructs a new Turtle object. It is derived from JXG.GeometryElement. It stores all properties required to move a turtle.

Attributes

Own

none

Inherited

Members

Own

none

Inherited

Methods

Own

X(t) → {Number}

if t is not supplied the x-coordinate of the turtle is returned. Otherwise the x-coordinate of the turtle curve at position t is returned.

Parameters

Name Type Description
t Number

parameter

Returns

x-coordinate of the turtle position or x-coordinate of turtle at position t

Type
Number

Details

Source
base/turtle.js, line 842

Y(t) → {Number}

if t is not supplied the y-coordinate of the turtle is returned. Otherwise the y-coordinate of the turtle curve at position t is returned.

Parameters

Name Type Description
t Number

parameter

Returns

x-coordinate of the turtle position or x-coordinate of turtle at position t

Type
Number

Details

Source
base/turtle.js, line 856

Z() → {Number}

Returns

z-coordinate of the turtle position

Type
Number

Details

Source
base/turtle.js, line 866

back(len) → {JXG.Turtle}

Move the turtle backwards.

Parameters

Name Type Description
len Number

of backwards move in user coordinates

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Source
base/turtle.js, line 331

bk()

Alias for JXG.Turtle#back

Details

Source
base/turtle.js, line 749

clean() → {JXG.Turtle}

Removes the turtle curve from the board. The turtle stays in its position.

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Source
base/turtle.js, line 395

clearScreen() → {JXG.Turtle}

Removes the turtle completely and resets it to its initial position and direction.

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Source
base/turtle.js, line 421

(private) copyAttr(key, val) → {Object}

Set a future attribute of the turtle.

Parameters

Name Type Description
key String
val Number | String

Returns

pointer to the attributes object

Type
Object

Details

Source
base/turtle.js, line 603

cs()

Alias for JXG.Turtle#clearScreen

Details

Source
base/turtle.js, line 791

evalAt(t) → {Number}

The "co"-coordinate of the turtle curve at position t is returned.

Parameters

Name Type Description
t Number

parameter

co. String

Either 'X' or 'Y'.

Returns

x-coordinate of the turtle position or x-coordinate of turtle at position t

Type
Number

Details

Source
base/turtle.js, line 814

fd()

Alias for JXG.Turtle#forward

Details

Source
base/turtle.js, line 743

forward(len) → {JXG.Turtle}

Move the turtle forward.

Parameters

Name Type Description
len Number

of forward move in user coordinates

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Source
base/turtle.js, line 286

getHighlightPenColor()

Get most recently set turtle color.

Returns

String RGB highlight color value of the last turtle segment.

Details

Source
base/turtle.js, line 546

(private) getPenAttribute(key)

Get attribute of the last turtle curve object.

Parameters

Name Type Description
key String

Returns

attribute value

Details

Source
base/turtle.js, line 515

getPenColor()

Get most recently set turtle color.

Returns

String RGB color value of the last turtle segment.

Details

Source
base/turtle.js, line 538

getPenSize()

Get most recently set turtle size (in pixel).

Returns

Number Size of the last turtle segment in pixel.

Details

Source
base/turtle.js, line 530

hasPoint(x, y) → {Boolean}

Checks whether (x,y) is near the curve.

Parameters

Name Type Description
x Number

Coordinate in x direction, screen coordinates.

y Number

Coordinate in y direction, screen coordinates.

Returns

True if (x,y) is near the curve, False otherwise.

Type
Boolean

Details

Overrides
JXG.GeometryElement#hasPoint
Source
base/turtle.js, line 902

hideTurtle() → {JXG.Turtle}

Sets the visibility of the turtle head to false,

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Source
base/turtle.js, line 626

home() → {JXG.Turtle}

Moves the turtle to position [0,0].

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Source
base/turtle.js, line 639

ht()

Alias for JXG.Turtle#hideTurtle

Details

Source
base/turtle.js, line 779

(private) init()

Initialize a new turtle or reinitialize a turtle after JXG.Turtle#clearScreen.

Details

Source
base/turtle.js, line 229

left(angle) → {JXG.Turtle}

Rotate the turtle direction to the right.

Parameters

Name Type Description
angle Number

of the rotation in degrees

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Source
base/turtle.js, line 362

lookTo(target) → {JXG.Turtle}

Rotates the turtle into a new direction. There are two possibilities:

Parameters

Name Type Description
target Number | Array

If a number is given, it is interpreted as the new direction to look to; If an array consisting of two Numbers is given targeted is used as a pair coordinates.

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Source
base/turtle.js, line 678

lt()

Alias for JXG.Turtle#left

Details

Source
base/turtle.js, line 755

maxX()

Gives the upper bound of the parameter if the turtle is treated as parametric curve. May be overwritten in @see generateTerm.

Details

Source
base/turtle.js, line 881

minX()

Gives the lower bound of the parameter if the turtle is treated as parametric curve.

Details

Source
base/turtle.js, line 873

moveTo(target) → {JXG.Turtle}

Moves the turtle to a given coordinate pair. The direction is not changed.

Parameters

Name Type Description
target Array

Coordinates of the point where the turtle looks to.

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Source
base/turtle.js, line 702

pd()

Alias for JXG.Turtle#penDown

Details

Source
base/turtle.js, line 773

penDown() → {JXG.Turtle}

Pen down, continues visible drawing

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Source
base/turtle.js, line 379

penUp() → {JXG.Turtle}

Pen up, stops visible drawing

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Source
base/turtle.js, line 370

pop()

Alias for JXG.Turtle#popTurtle

Details

Source
base/turtle.js, line 803

popTurtle() → {JXG.Turtle}

Gets the last position of the turtle on the stack, sets the turtle to this position and removes this position from the stack.

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Source
base/turtle.js, line 661

pu()

Alias for JXG.Turtle#penUp

Details

Source
base/turtle.js, line 767

push()

Alias for JXG.Turtle#pushTurtle

Details

Source
base/turtle.js, line 797

pushTurtle() → {JXG.Turtle}

Pushes the position of the turtle on the stack.

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Source
base/turtle.js, line 650

Rotate the turtle direction to the right

Parameters

Name Type Description
angle Number

of the rotation in degrees

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Source
base/turtle.js, line 340

rt()

Alias for JXG.Turtle#right

Details

Source
base/turtle.js, line 761

setAttribute(attributes) → {JXG.Turtle}

Sets attributes of the turtle, see also JXG.GeometryElement#setAttribute. Sets the property for all curves of the turtle in the past and in the future.

Parameters

Name Type Description
attributes Object

key:value pairs

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Overrides
JXG.GeometryElement#setAttribute
Source
base/turtle.js, line 573

setHighlightPenColor(color) → {JXG.Turtle}

Sets the highlight pen color. Equivalent to setAttribute({highlightStrokeColor:color}) but affects only the future turtle.

Parameters

Name Type Description
color String

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Source
base/turtle.js, line 556

setPenColor(color) → {JXG.Turtle}

Sets the pen color. Equivalent to setAttribute({strokeColor:color}) but affects only the future turtle.

Parameters

Name Type Description
color String

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Source
base/turtle.js, line 497

setPenSize(size) → {JXG.Turtle}

Sets the pen size. Equivalent to setAttribute({strokeWidth:size}) but affects only the future turtle.

Parameters

Name Type Description
size Number

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Source
base/turtle.js, line 480

setPos(x, y) → {JXG.Turtle}

Moves the turtle without drawing to a new position

Parameters

Name Type Description
x Number

new x- coordinate

y Number

new y- coordinate

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Source
base/turtle.js, line 443

showTurtle() → {JXG.Turtle}

Sets the visibility of the turtle head to true,

Returns

pointer to the turtle object

Type
JXG.Turtle

Details

Source
base/turtle.js, line 612

st()

Alias for JXG.Turtle#showTurtle

Details

Source
base/turtle.js, line 785

Inherited

Events

Own

none

Inherited

Example

Creates a figure 8 animation

var board = JXG.JSXGraph.initBoard('jxgbox',{boundingbox: [-250, 250, 250, -250]});
var t = board.create('turtle',[0, 0], {strokeOpacity:0.5});
t.setPenSize(3);
t.right(90);
var alpha = 0;

var run = function() {
 t.forward(2);
 if (Math.floor(alpha / 360) % 2 === 0) {
  t.left(1);        // turn left by 1 degree
 } else {
  t.right(1);       // turn right by 1 degree
 }
 alpha += 1;

 if (alpha < 1440) {  // stop after two rounds
  setTimeout(run, 20);
 }
}

run();

Parameters

Name Type Description
board JXG.Board

The board the new turtle is drawn on.

parents Array

Start position and start direction of the turtle. Possible values are

[x, y, angle]
[[x, y], angle]
[x, y]
[[x, y]]
attributes Object

Attributes to change the visual properties of the turtle object All angles are in degrees.

Details

Source
base/turtle.js, line 119

Extends