Pencil Code Reference > movexy


movexy moves the turtle by an xy offset

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

movexy x, y moves by an xy offset 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 and y increasing upward.

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

Drawing while Moving

Unlike jumpxy, movexy will trace lines if a pen is being used. It allows lines to be drawn between any points without worrying about the angle and distance of the turtle. movexy does not affect the turtle rotation, only its position.

pen peru
movexy 50, 50
movexy -75, -25
movexy 0, -50
movexy -125, 100

Limiting Motion

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

The following program will move the turtle towards the last mouse event twice per second, but will move no more than 10 pixels each time.

pen green
forever 2, ->
  movexy lastmouse, 10

In all these uses, movexy moves the turtle without changing its direction (the way it's facing).

Blah blah - let's compare moveto and movexy

moveto versus movexy