Pencil Code Reference > jumpto

 

jumpto moves the turtle to a new location without drawing

The turtle starts in the middle of the window, at (x, y) coordinates (0, 0).

jumpto x, y jumps to an absolute location in traditional Cartesian coordinates. In this coordinate system, Each unit is one pixel, and each graph paper grid square is 25 units. The mathematical coordinate axes are used, placing (0, 0) at the middle with x increasing to the right (horizontally) and y increasing upward (vertically).

A vector represented as an array of two numbers can be used. jumpto [x, y] is treated the same as jumpto x, y.

Drawing while Jumping

jumpto will jump to a location without drawing. You can use the function moveto with a pen to draw lines between points.

jumpto does not affect the turtle rotation, only its position.

dot yellow, 20
jumpto 50, 50
dot blue, 20
jumpto -75, -25
dot pink, 20
jumpto 0, -50
dot purple, 20
jumpto -125, 80
dot green, 20
jumpto -125, 100

Using HTML Coordinates

The native coordinate system supported by HTML follows a different convention: it places the (pageX, pageY) origin at the upper-left corner of the page. pageX increases to the right, but pageY is inverted: pageY increases going down.

jumpto supports native HTML coordinates if they are passed with the pageX and pageY properties. Note that HTML mouse events all have pageX and pageY properties, so jumpto lastclick will jump to the location of the last mouse click.

Replay the demo to see how jumpto lastclick works.

jumpto pageX: 50, pageY: 100
dot blue, 20
jumpto pageX: 150, pageY: 200
dot green, 20
jumpto pageX: 250, pageY: 100
dot yellow, 20
jump to lastclick
dot purple, 20
fd 20

Other Locations

jumpto will also jump to any element or jQuery object or any other object that supports a pagexy() method that returns page coordinates. For example jumpto otherturtle will jump to the location of another turtle.

Here is a summary of some types of locations that jumpto understands.

example motion
jumpto x, y jump to (x, y) in traditional mathematical y-up coordinates.
jumpto [x, y] same as jumpto x, y
jumpto pageX: px, pageY: py jump using HTML page coordinates.
jumpto lastmouse jump to the location of the last mouse event.
jumpto otherturtle jump to another turtle.
jumpto $('#spot') jump to the element with id spot.
jumpto document jump to the center of the document.
jumpto window jump to the center of the visible window.

Limiting Motion

When passing a single location object to jumpto, it supports an optional second argument limiting the distance of the motion. When the second argument is given, the turtle will jump towards the location, but no farther than the limiting distance in pixels.

In the following program the turtle will jump towards the last mouse event twice per second, but will jump a distance of no more than 10 pixels each time.

This function is useful to emulate gait.

pen green
tick 2, ->
  jumpto lastmouse, 10

In all these uses, jumpto moves the turtle without changing its direction.

If you want to draw lines between points, use jumpto with a pen.