Distance to a point or a turtle

distance point
(distance p1 p2)

Returns distance from the current turtle to a point. Point can be 2-element array or list of (x, y) coordinates. Another turtle is also accepted as the argument; in this case instruction will return distance to the turtle. Optionally, points or turtles can be used as arguments p1 and p2 to calculate distance between these positions.

Example:

repeat 10 [
  setxy
    100 * cos 40 * (repcount - 1)
    100 * sin 40 * (repcount - 1)
  print distance {0 0}
]

Output:
(also a drawing)

100
100
100
100
100
100
100
100
100
100

See also:

Table of Content