JavaScript must be enabled in order for you to use JSXGraph and JSXGraph reference. However, it seems JavaScript is either disabled or not supported by your browser.

Class Index | File Index

Elements
Classes

Class JXG.Turtle


      ↳ JXG.Turtle

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

Defined in: turtle.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
JXG.Turtle(board, parents, attributes)
Constructs a new Turtle object.
Method Summary
Method Attributes Method Name and Description
 
back(len)
Move the turtle backwards.
 
bk(len)
Alias for JXG.Turtle#back
 
Removes the turtle curve from the board.
 
Removes the turtle completely and resets it to its initial position and direction.
<private>  
copyAttr(key, val)
Set a future attribute of the turtle.
 
cs()
 
evalAt(t)
The "co"-coordinate of the turtle curve at position t is returned.
 
fd(len)
 
forward(len)
Move the turtle forward.
 
Get most recently set turtle color.
<private>  
Get attribute of the last turtle curve object.
 
Get most recently set turtle color.
 
Get most recently set turtle size (in pixel).
 
hasPoint(x, y)
Checks whether (x,y) is near the curve.
 
Sets the visibility of the turtle head to false,
 
home()
Moves the turtle to position [0,0].
 
ht()
<private>  
init(x, y, dir)
Initialize a new turtle or reinitialize a turtle after JXG.Turtle#clearScreen.
 
left(angle)
Rotate the turtle direction to the right.
 
lookTo(target)
Rotates the turtle into a new direction.
 
lt(angle)
Alias for JXG.Turtle#left
 
maxX()
Gives the upper bound of the parameter if the turtle is treated as parametric curve.
 
minX()
Gives the lower bound of the parameter if the turtle is treated as parametric curve.
 
moveTo(target)
Moves the turtle to a given coordinate pair.
 
pd()
 
Pen down, continues visible drawing
 
Pen up, stops visible drawing
 
pop()
 
Gets the last position of the turtle on the stack, sets the turtle to this position and removes this position from the stack.
 
pu()
 
push()
 
Pushes the position of the turtle on the stack.
 
right(angle)
Rotate the turtle direction to the right
 
rt(angle)
 
setAttribute(attributes)
Sets properties of the turtle, see also JXG.GeometryElement#setAttribute.
 
Sets the highlight pen color.
 
setPenColor(color)
Sets the pen color.
 
setPenSize(size)
Sets the pen size.
 
setPos(x, y)
Moves the turtle without drawing to a new position
 
Sets the visibility of the turtle head to true,
 
st()
 
X(t)
if t is not supplied the x-coordinate of the turtle is returned.
 
Y(t)
if t is not supplied the y-coordinate of the turtle is returned.
 
Z(t)
Class Detail
JXG.Turtle(board, parents, attributes)
Constructs a new Turtle object.
Parameters:
{JXG.Board} board
The board the new turtle is drawn on.


{Array} parents
Start position and start direction of the turtle. Possible values are [x, y, angle] [[x, y], angle] [x, y] [[x, y]]


{Object} attributes
Attributes to change the visual properties of the turtle object All angles are in degrees.


Examples:
//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();


				
                
Method Detail
{JXG.Turtle} back(len)
Move the turtle backwards.
Parameters:
{Number} len
of backwards move in user coordinates
Returns:
{JXG.Turtle} pointer to the turtle object

bk(len)
Alias for JXG.Turtle#back
Parameters:
len

{JXG.Turtle} clean()
Removes the turtle curve from the board. The turtle stays in its position.
Returns:
{JXG.Turtle} pointer to the turtle object

{JXG.Turtle} clearScreen()
Removes the turtle completely and resets it to its initial position and direction.
Returns:
{JXG.Turtle} pointer to the turtle object

<private> {Object} copyAttr(key, val)
Set a future attribute of the turtle.
Parameters:
{String} key
{Number|String} val
Returns:
{Object} pointer to the attributes object

cs()
Alias for JXG.Turtle#clearScreen

{Number} evalAt(t)
The "co"-coordinate of the turtle curve at position t is returned.
Parameters:
{Number} t
parameter
{String} co.
Either 'X' or 'Y'.
Returns:
{Number} x-coordinate of the turtle position or x-coordinate of turtle at position t

fd(len)
Alias for JXG.Turtle#forward
Parameters:
len

{JXG.Turtle} forward(len)
Move the turtle forward.
Parameters:
{Number} len
of forward move in user coordinates
Returns:
{JXG.Turtle} pointer to the turtle object

getHighlightPenColor()
Get most recently set turtle color.
Returns:
String RGB highlight color value of the last turtle segment.

<private> getPenAttribute(key)
Get attribute of the last turtle curve object.
Parameters:
{String} key
Returns:
attribute value

getPenColor()
Get most recently set turtle color.
Returns:
String RGB color value of the last turtle segment.

getPenSize()
Get most recently set turtle size (in pixel).
Returns:
Number Size of the last turtle segment in pixel.

{Boolean} hasPoint(x, y)
Checks whether (x,y) is near the curve.
Parameters:
{Number} x
Coordinate in x direction, screen coordinates.
{Number} y
Coordinate in y direction, screen coordinates.
Returns:
{Boolean} True if (x,y) is near the curve, False otherwise.

{JXG.Turtle} hideTurtle()
Sets the visibility of the turtle head to false,
Returns:
{JXG.Turtle} pointer to the turtle object

{JXG.Turtle} home()
Moves the turtle to position [0,0].
Returns:
{JXG.Turtle} pointer to the turtle object

ht()
Alias for JXG.Turtle#hideTurtle

<private> init(x, y, dir)
Initialize a new turtle or reinitialize a turtle after JXG.Turtle#clearScreen.
Parameters:
x
y
dir

{JXG.Turtle} left(angle)
Rotate the turtle direction to the right.
Parameters:
{Number} angle
of the rotation in degrees
Returns:
{JXG.Turtle} pointer to the turtle object

{JXG.Turtle} lookTo(target)
Rotates the turtle into a new direction. There are two possibilities:
Parameters:
{Number|Array} target
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:
{JXG.Turtle} pointer to the turtle object

lt(angle)
Alias for JXG.Turtle#left
Parameters:
angle

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

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

{JXG.Turtle} moveTo(target)
Moves the turtle to a given coordinate pair. The direction is not changed.
Parameters:
{Array} target
Coordinates of the point where the turtle looks to.
Returns:
{JXG.Turtle} pointer to the turtle object

pd()
Alias for JXG.Turtle#penDown

{JXG.Turtle} penDown()
Pen down, continues visible drawing
Returns:
{JXG.Turtle} pointer to the turtle object

{JXG.Turtle} penUp()
Pen up, stops visible drawing
Returns:
{JXG.Turtle} pointer to the turtle object

pop()
Alias for JXG.Turtle#popTurtle

{JXG.Turtle} popTurtle()
Gets the last position of the turtle on the stack, sets the turtle to this position and removes this position from the stack.
Returns:
{JXG.Turtle} pointer to the turtle object

pu()
Alias for JXG.Turtle#penUp

push()
Alias for JXG.Turtle#pushTurtle

{JXG.Turtle} pushTurtle()
Pushes the position of the turtle on the stack.
Returns:
{JXG.Turtle} pointer to the turtle object

{JXG.Turtle} right(angle)
Rotate the turtle direction to the right
Parameters:
{Number} angle
of the rotation in degrees
Returns:
{JXG.Turtle} pointer to the turtle object

rt(angle)
Alias for JXG.Turtle#right
Parameters:
angle

{JXG.Turtle} setAttribute(attributes)
Sets properties 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:
{Object} attributes
key:value pairs
Returns:
{JXG.Turtle} pointer to the turtle object

{JXG.Turtle} setHighlightPenColor(color)
Sets the highlight pen color. Equivalent to setAttribute({highlightStrokeColor:color}) but affects only the future turtle.
Parameters:
{String} color
Returns:
{JXG.Turtle} pointer to the turtle object

{JXG.Turtle} setPenColor(color)
Sets the pen color. Equivalent to setAttribute({strokeColor:color}) but affects only the future turtle.
Parameters:
{String} color
Returns:
{JXG.Turtle} pointer to the turtle object

{JXG.Turtle} setPenSize(size)
Sets the pen size. Equivalent to setAttribute({strokeWidth:size}) but affects only the future turtle.
Parameters:
{Number} size
Returns:
{JXG.Turtle} pointer to the turtle object

{JXG.Turtle} setPos(x, y)
Moves the turtle without drawing to a new position
Parameters:
{Number} x
new x- coordinate
{Number} y
new y- coordinate
Returns:
{JXG.Turtle} pointer to the turtle object

{JXG.Turtle} showTurtle()
Sets the visibility of the turtle head to true,
Returns:
{JXG.Turtle} pointer to the turtle object

st()
Alias for JXG.Turtle#showTurtle

{Number} X(t)
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:
{Number} t
parameter
Returns:
{Number} x-coordinate of the turtle position or x-coordinate of turtle at position t

{Number} Y(t)
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:
{Number} t
parameter
Returns:
{Number} x-coordinate of the turtle position or x-coordinate of turtle at position t

{Number} Z(t)
Parameters:
t
Returns:
{Number} z-coordinate of the turtle position

Documentation generated by JsDoc Toolkit 2.4.0 on Wed Oct 23 2024 15:44:14 GMT+0200 (Mitteleuropäische Sommerzeit)