Table of Contents > Turtles and Worlds

JES provides you with turtles, which you may have heard about before if you know about LOGO. (if not, don't worry!) Here are some functions you can use to work with them and their little worlds.


Turtle Functions in JES

This is a list of functions that you may find useful when you are creating programs to manipulate or create turtles and worlds in JES. Remember, these functions are part of a special library, and are not available in other Jython programming environments.
makeWorld
makeWorld([width, height]):
width: the width for your new world (optional)
height: the height for your new world (optional)
Returns a new world of the specified size, where you can put turtles. Default size is 640x480. For example, these both work:
earth = makeWorld()
mars = makeWorld(500, 500)
makeTurtle
makeTurtle(world):
world: a world to put the turtle in
Makes a turtle and returns it
w = makeWorld(500, 500)
t = makeTurtle(w)
penUp(t)
moveTo(t, int(500/3), 250)
penDown(t)
for i in range(0, 360):
    turn(t, 1)
    forward(t, 3)
forward
forward(turtle, distance):
turtle: the turtle to operate on
distance: how far to go, in pixels
Moves the turtle in the direction it's facing
w = makeWorld(500, 500)
t = makeTurtle(w)
forward(t, 100)
backward
backward(turtle, distance):
turtle: the turtle to operate on
distance: how far back to go
Moves the turtle backwards (relative to where it's facing)
w = makeWorld(500, 500)
t = makeTurtle(w)

backward(t, 40)
turnLeft
turnLeft(turtle):
turtle: the turtle to operate on
Turns the turtle left 90 degrees
w = makeWorld(300, 200)
t = makeTurtle(w)
turnLeft(t)
forward(t, 30)
turnRight
turnRight(turtle):
turtle: the turtle to operate on
Turns the turtle right 90 degrees
w = makeWorld(300, 200)
t = makeTurtle(w)
turnRight(t)
forward(t, 30)
turn
turn(turtle[, degrees]):
turtle: the turtle to operate on
degrees: how many degrees to turn (optional)
Turns the turtle; positive numbers of degrees mean turning to the turtle's right. Default is 90 degrees.
w = makeWorld(500, 500)
t = makeTurtle(w)

turn(t, 30)
forward(t, 100)
moveTo
moveTo(turtle, x, y):
turtle: the turtle to operate on
x: the X coordinate in the world
y: the Y coordinate in the world
Moves the turtle to the specified location. If the turtle's pen is down, it draws a line from its old position to the new one.
w = makeWorld(500, 500)
t = makeTurtle(w)

moveTo(t, 150, 150)
turnToFace
turnToFace(turtle, x[, y]):
turtle: the turtle to operate on
x: the X coordinate in the world (or a turtle in the world)
y: the Y coordinate in the world (optional)
Makes the turtle look towards point (x, y) or towards turtle x if y is unspecified.
w = makeWorld(500, 500)
t = makeTurtle(w)
t2 = makeTurtle(w)
turn(t, 63)
backward(t, 40)
turnToFace(t, 200, 100)
forward(t, 300)
moveTo(t, 150, 150)
turnToFace(t, t2)
penUp
penUp(turtle):
turtle: the turtle to operate on
Makes the turtle pick up its pen, so doesn't leave a trail when it moves.
w = makeWorld(300, 200)
t = makeTurtle(w)
penUp(t)
forward(t, 50)
turnRight(t)
penDown(t)
forward(t, 30)
penDown
penDown(turtle):
turtle: the turtle to operate on
Makes the turtle put its pen on the world, so leaves a trail when it moves.
w = makeWorld(300, 200)
t = makeTurtle(w)
penUp(t)
forward(t, 50)
turnRight(t)
penDown(t)
forward(t, 30)
drop
drop(turtle, picture):
turtle: the turtle who will do the dropping
picture: the picture that the turtle will drop
The turtle drops a picture where it is currently sitting, rotated so that the top of the picture points where the turtle is facing. (this, for example, is one way to flip a picture upside-down)
w = makeWorld()
t = makeTurtle(w)
pic = makePicture("adorable-kitten.jpg")

turn(t, 180)
drop(t, pic)
getHeading
getHeading(turtle):
turtle: the turtle to get the heading of
returns: a floating point number representing the heading of the turtle
Returns the turtle's current heading.
getTurtleList
getTurtleList(world):
world: the world to get the turtles from
Returns a list of all turtles in the specified world. (You could, for example, tell each one to do something)
getXPos
getXPos(turtle):
turtle: the turtle to get the X position of
returns: the X position of the turtle
Returns the X coordinate of the turtle's location.
getYPos
getYPos(turtle):
turtle: the turtle to get the Y position of
returns: the Y position of the turtle
Returns the Y coordinate of the turtle's location.


jump to top