makeWorld
|
makeWorld([width, height]):
width: the width for your new world (optional)
height: the height for your new world (optional)
returns: the new world
Returns a new world of the specified size, where you can put turtles. Default size is 640x480.
Example:
def makeDefaultWorld():
earth = makeWorld()
This creates a world with the default size (640x480).
def makeSmallerWorld():
mars = makeWorld(500, 500)
This creates a smaller world of size 500x500.
|
makeTurtle
|
makeTurtle(world):
world: a world to put the turtle in
returns: the new turtle
Makes a turtle and returns it
Example:
def turtleForward():
w = makeWorld()
t = makeTurtle(w)
forward(t)
This creates a new turtle and moves it forward 100 pixels.
|
forward
|
forward(turtle[, distance]):
turtle: the turtle to operate on
distance: how far to go, in pixels (optional)
Moves the turtle in the direction it's facing. Default distance is 100 pixels.
Example
def moveTurtleForward50():
w = makeWorld()
t = makeTurtle(w)
forward(t, 50)
This creates a new turtle and moves it forward 50 pixels.
def moveTurtleForward100():
w = makeWorld()
t = makeTurtle(w)
forward(t)
This creates a new turtle and moves it forward the default number of pixels (100).
|
backward
|
backward(turtle[, distance]):
turtle: the turtle to operate on
distance: how far to go, in pixels (optional)
Moves the turtle opposite to the direction it's facing. Default distance is 100 pixels.
Example
def moveTurtleBackward50():
w = makeWorld()
t = makeTurtle(w)
backward(t, 50)
This creates a new turtle and moves it backward 50 pixels.
def moveTurtleBackward100():
w = makeWorld()
t = makeTurtle(w)
backward(t)
This creates a new turtle and moves it backward the default number of pixels (100).
|
turnLeft
|
turnLeft(turtle):
turtle: the turtle to operate on
Turns the turtle left 90 degrees.
Example:
def makeLeftSquare():
w = makeWorld()
t = makeTurtle(w)
for x in range(0,4):
forward(t)
turnLeft(t)
This will create a turtle and draw a 100x100 square to the upper-left of the middle of the world.
|
turnRight
|
turnRight(turtle):
turtle: the turtle to operate on
Turns the turtle right 90 degrees.
Example:
def makeRightSquare():
w = makeWorld()
t = makeTurtle(w)
for x in range(0,4):
forward(t)
turnRight(t)
This will create a turtle and draw a 100x100 square to the upper-right of the middle of the world.
|
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, negative numbers of degrees mean turning to the turtle's left. Default is 90 degrees.
Example:
def turnTurtleRight():
w = makeWorld()
t = makeTurtle(w)
turn(t)
This will create a turtle and turn it right 90 degrees.
def turnTurtleAround():
w = makeWorld()
t = makeTurtle(w)
turn(t, 180)
This will create a turtle and turn it 180 degrees.
|
moveTo
|
moveTo(turtle, x, y):
turtle: the turtle to operate on
x: the x coordinate in the world to move to
y: the y coordinate in the world to move to
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.
Example:
def moveTurtleTo():
w = makeWorld()
t = makeTurtle(w)
moveTo(t, 150, 150)
This will create a new turtle and move it to the coordinates (150,150) in the world.
|
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.
Example:
def turtleEscape():
w = makeWorld()
t = makeTurtle(w)
turnToFace(t, 0, 0)
forward(t, 400)
This creates a turtles which then faces the origin (0,0) and moves forward 400 pixels.
def turtleDuel():
w = makeWorld()
t = makeTurtle(w)
turn(t)
t2 = makeTurtle(w)
turn(t2, 180)
for turtle in getTurtleList(w):
forward(turtle, 50)
turnToFace(t, t2)
turnToFace(t2, t)
This creates a world with two turtles. The first turtle turns 90 degrees and the second turtle turns around 180 degrees. Then both turtles move forward 50 pixels and turn to face each other.
|
penUp
|
penUp(turtle):
turtle: the turtle to operate on
Makes it so the turtle does not leave a trail when it moves. Default is down.
Example:
def turtleSquare():
w = makeWorld()
t = makeTurtle(w)
for x in range(0,4):
penUp(t)
forward(t)
turnRight(t)
penDown(t)
forward(t)
This will create a turtle and draw a 200x200 square with only half of each edge showing.
|
penDown
|
penDown(turtle):
turtle: the turtle to operate on
Makes it so the turtle leaves a trail when it moves. Default is down.
Example:
def turtleSquare():
w = makeWorld()
t = makeTurtle(w)
for x in range(0,4):
penUp(t)
forward(t)
turnRight(t)
penDown(t)
forward(t)
This will create a turtle and draw a 200x200 square with only half of each edge showing.
|
drop
|
drop(turtle, picture):
turtle: the turtle that 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.
Example:
def dropUpsidedownPic():
w = makeWorld()
t = makeTurtle(w)
moveTo(t, 640, 480)
pic = makePicture(pickAFile())
turn(t, 180)
drop(t, pic)
This allows the user to select a picture file, moves the turtle and drops the picture upside-down. The upper-left corner of the picture will be placed in the lower-right corner of the world.
|
getHeading
|
getHeading(turtle):
turtle: the turtle to get the heading of
returns: a floating point number representing the heading of the turtle
Returns the degrees of the direction the turtle is facing. (0 degrees is straight up, and heading increases clockwise)
Example:
def turtleRightTriangleAngle():
w = makeWorld()
t = makeTurtle(w)
t2 = makeTurtle(w)
turnRight(t2)
forward(t2)
turnLeft(t2)
forward(t2, 50)
turnToFace(t, t2)
return getHeading(t)
This will calculate the larger of the two acute angles in the right triangle with side lengths 50 and 100 using turtles. (~63.43 degrees)
|
getTurtleList
|
getTurtleList(world):
world: the world to get the turtles from
returns: the list of turtles in the world
Returns a list of all turtles in the specified world. (You could, for example, tell each one to do something)
Example:
def turtleDuel():
w = makeWorld()
t = makeTurtle(w)
t2 = makeTurtle(w)
turn(t2, 180)
for turtle in getTurtleList(w):
forward(turtle, 50)
turn(turtle, 180)
This creates a world with two turtles. The second turtle turns around 180 degrees, then both turtles move forward 50 pixels and turn to face each other.
|
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.
Example:
def getDefaultTurtleXPos():
w = makeWorld()
todd = makeTurtle(w)
return getXPos(todd)
This will create a world of default size (640x480), place a turtle in the center, and return its x position (320).
|
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.
Example:
def getDefaultTurtleYPos():
w = makeWorld()
timmy = makeTurtle(w)
return getYPos(timmy)
This will create a world of default size (640x480), place a turtle in the center, and return its y position (240).
|