Terrapin Resources
Coordinates

SETPOS or SETXY     SETX     SETY     GETX or XCOR     GETY or YCOR     POS
HOME     DISTANCE     TOWARDS     DOT     DOT?     DOTCOLOR

In this section, you will learn about Logo commands that use the built-in coordinate system. Each dot in the drawing canvas has a unique location, based on its distance, horizontally and vertically, from the center of the screen. Numbers along the invisible X-axis (horizontal) and Y-axis (vertical) identify locations on the screen.

X-axis values in the bottom half of the screen are negative numbers, less than zero.
X-axis values in the top half of the screen are positive numbers, greater than zero
Y-axis values in the left half of the screen are negative numbers.
Y-axis values in the right half of the screen are positive numbers.

The center of the screen, the turtle’s Home, is [0 0]. In math, you would use parentheses and a comma to identify a point, as in (0,0), but in Logo you use a list of two numbers with no comma. The X value is first in the list; the Y value is second.

In the image above, the location labeled (x,y) would be referred to in Logo as [3 4]. It is located at 3 on the X-axis and 4 on the Y-axis.

The screen is divided into 4 quadrants.

  • in the upper right quadrant, both the X and Y values are positive numbers, as in [50 100]
  • in the lower right quadrant, the X value is positive number and the Y value is a negative number (less than zero), as in [50 -100]
  • in the lower left quadrant, both the X and Y values are negative numbers, as in [-50 -100]
  • in the upper left quadrant, the X value is negative and the Y value is positive, as in [-50 100]

SETPOS [x-coordinate y-coordinate]
SETXY [x-coordinate y-coordinate]


SETPOS and SETXY do the exact same job. They have both been commands in different versions of Logo over time. We’ll use SETPOS, but you can use either one.

SETPOS takes a list of two numbers as input: the X-axis value and the Y-axis value. The turtle’s heading does not change.

For example, SETPOS [50 100] moves the turtle to a location that is 50 to the right of Home and 100 up.

Here are the Logo commands you would use to draw this design:

SETPOS [25 50]
SETPOS [25 -50]
SETPOS [-25 50]
SETPOS [-25 -50]
SETPOS [0 0] or HOME

» Things to Try

Try creating other designs using SETPOS.
Remember to use PENUP and PENDOWN when using this command.

Use graph paper will help you plan your design before you start.

Can you draw the sailboat in this Turtle Tuesday challenge using only SETPOS commands?


SETX number


SETX allows you to move the turtle horizontally along the X-axis. Its position on the Y-axis will not change.

» Things to Try

Here’s a game to play with dice.
Roll one die.
If the number is even, the number you will choose next is a positive number. If the number is odd, you will use a negative number.
Roll the other die. Multiply that number by 10 (just add a zero after the number).
Now use SETX to move the turtle to that position on the X-axis.

For example, if you rolled a 2 and then a 5, you would move the turtle to the right to location 50 on the X-axis: SETX 50

If you rolled a 1 and then a 6, you would move the turtle to the left to location -60 on the X-axis: SETX -60

Can you ever get back to the turtle’s home?


SETY number


SETY allows you to move the turtle vertically along the Y-axis. Its position on the X-axis will not change.

» Things to Try

Here’s a game to play with dice.
Roll one die.
If the number is even, the number you will choose next is a positive number. If the number is odd, you will use a negative number.
Roll the other die. Multiply that number by 10 (just add a zero after the number).
Now use SETY to move the turtle to that position on the X-axis.

For example, if you rolled a 2 and then a 5, you would move the turtle up to location 50 on the Y-axis: SETY 50

If you rolled a 1 and then a 6, you would move the turtle down to location -60 on the Y-axis: SETY -60

Can you ever get back to the turtle’s home?

Can you think of a way to use 3 dice to set the turtle’s location in both directions?

Click the dice to roll them in this online activity.


GETX
XCOR


GETX is a reporter that tells you the X-coordinate of the turtle’s location. You can also use XCOR.

SETPOS [40 50]
GETX
Result: 40

» Things to Know

Because GETX is a reporter, you can use it in programs you write. You would use IF or TEST to check the result. See the section on Program Flow to learn how.


GETY
YCOR


GETY is a reporter that tells you the X-coordinate of the turtle’s location. You can also use YCOR.

SETPOS [100 -60]
GETY
`Result: -60

» Things to Know

Because GETY is a reporter, you can use it in programs you write. You would use IF or TEST to check the result. See the section on Program Flow to learn how.


POS


POS is a reporter. It tells you the turtle’s current location in coordinates.

SETPOS [-200 75]
POS
Result: [-200 75]

» Things to Try

Because POS is a reporter, you can use it in programs you write. See the section on Program Flow to learn how.


HOME


HOME is the same as using SETXY [0 0].

» Things to Try

Use SETXY with different inputs and then type HOME. You’ll likely get some interesting designs!


DISTANCE [x-coordinate y-coordinate]


DISTANCE reports how far the turtle is from a specified coordinate location.

You can use it to determine how far the turtle is, in a straight line, from another turtle (see Multiple Turtle commands), the mouse (see Mouse and Keyboard commands), or any other spot on the screen.

When the turtle is in its Home position, try this:

DISTANCE [60 -110]
Result: 125.3

DISTANCE is often used with TOWARDS (see next command).

» Things to Try

To see how far the turtle is from the mouse pointer, try this:

PR DISTANCE MOUSE

Move the mouse and give the command again.


TOWARDS [x-coordinate y-coordinate]


TOWARDS reports the heading (a number) that will point the turtle to the specified location.

DISTANCE reports the distance to a point. With these two commands — DISTANCE and TOWARDS — you can get the turtle to any spot on the screen with two instructions. Can you figure out how?

» Things to Try

Suppose you want to get to where the mouse pointer is on the screen.

First, move your mouse to anywhere in the Graphics panel. Then type PU SETPOS MOUSE and press the RETURN or ENTER key.

Then, to get the turtle back to its home, you could use:

SETH TOWARDS [0 0] FD DISTANCE [0 0]

Did it work? How can you check to be sure? Can you use POS?


DOT [x-coordinate y-coordinate]
(DOT)


DOT puts a dot in the current pen color at the coordinate location you specify.

(DOT) in parentheses with no inputs places a dot at the turtle’s current location.

The dot is as wide as the current penwidth (use SETWIDTH to adjust the width of the pen, and WIDTH to find out the width).

The pen must be down to make the dot.

» Things to Try

Try putting some dots around the screen. Use (DOT) and also DOT [xcor ycor].

Experiment with different penwidths. Try the activities in the January 2025 Turtle Tuesday challenges:, which are all about the DOT and SETWIDTH commmands.


DOT?
(DOT? [x-coordinate y-coordinate])


DOT? tells you if there is a dot at the turtle’s location that is not the same color as the background.

If you want to look at a different spot on the screen, give DOT? a list of its coordinate values. Put the entire instruction in parentheses, like this:

PR (DOT? [0 0])
This would tell you if there is a dot at the turtle’s location.

The pen can be either up or down to detect a dot.

» Things to Try

Draw some designs on the screen and use DOT? to tell if a dot is present.


(DOTCOLOR)
DOTCOLOR [x-coordinate y-coordinate]


DOTCOLOR tells you the color of the dot.
Use (DOTCOLOR) to look at the turtle’s current location.
Use DOTCOLOR [x-coordinate y-coordinate] to check a different location.

DOTCOLOR reports the color as a list of four numbers: [red green blue alpha]. Read about these numbers in the Colors section.

» Things to Try

You can check the color at the mouse pointer’s location using this command:
DOTCOLOR MOUSE

This works because MOUSE reports the coordinate location of the mouse pointer.