8.6. Advanced Features

Turtles are a large tool, and thus have a lot of options dictating how they function. Some features and functionality are more complicated than others, relating to the inner workings of turtles themselves. A few of these include the tracer and undo methods, and also screen modes.

Screen modes dictate the direction of angle measurements. This means that, depending on which mode a TurtleScreen object is in, positive angles could represent clockwise rotations or counterclockwise rotations. The mode method for TurtleScreen allows you to set which mode a screen is in.


Default Rotation

Positive Angles







Regarding angles, Turtles can use both degrees and radians for their rotations. You can choose between the two using the radians and degrees methods for the Turtle object. By default, all angles are measured in degrees. This option only effects methods regarding rotation, such as left and right.

turtle.right(90);//90-degree turn to the right
turtle.left(1.5708f);//Equivalent rotation in radians to the left.

The tracer(N) method is used to control how many times the Turtle is actually drawn on the screen. This method belongs to the TurtleScreen object, and effects all turtles that are on the screen. The N in the method represents the input, only allowing the TurtleScreen to display one frame out every N.

This can be combined with the speed method available to turtles to achieve very quickly drawn images. The maximum speed a Turtle can have, TS_FASTEST, completely disables animation for Turtles between movements and rotations. This allows the tracer setting to directly relate to the total number of actions the turtle makes. The actions the turtle takes happen regardless of whether or not they are actually shown on the screen.

screen.tracer(3); //Show one out of every 3 frames of animation.
turtle.speed(ct::TS_FASTEST);  //Disables Turtle animation

turtle.forward(50);//This is not shown on-screen...
turtle.right(90);//Neither is this...
turtle.forward(50);//But this action is, because it is third out of three.

A frame of animation is added for almost every action a turtle takes, regardless of whether or not the turtle is moving or adding something to the screen. This includes methods like begin_fill and end_fill, which don’t do anything visually but do tell the turtle to start or stop tracking its own movements.

Consider the following example and related questions.

#include <CTurtle.hpp>
namespace ct = cturtle;

int main(){
    ct::TurtleScreen screen;
    ct::Turtle turtle(screen);


    for(int i = 0; i < 3; i++){


    return 0;

    Q-1: How many frames of animation does the above code create?

  • 3
  • Incorrect! Consider how many actions the turtle takes in the for loop.
  • 6
  • Incorrect! Consider the tracer setting for the screen.
  • 1
  • Correct!
  • 12
  • Incorrect! Consider how many actions the turtle takes in the for loop.

Similarly to tracer settings, every action a turtle takes is also added to the undo queue. This allows it to keep track of actions it is performing over a period of time. The queue is only allowed to grow to a certain size, starting at 100 actions total. This is modifiable through the setundobuffer method that belongs to turtles. Every action is added, even if the action doesn’t change anything visually. This feature is comparable to the “undo” tool available in most text editors. Turtles can “undo” their progress with the undo method.

    Q-2: How many actions will be in the turtle’s undo queue for the code above?

  • 3
  • Incorrect! Consider how many actions the turtle takes in the for loop.
  • 6
  • Correct!
  • 1
  • Incorrect! Consider how many actions the turtle takes in the for loop.
  • 12
  • Incorrect! Consider how many actions the turtle takes in the for loop.
You have attempted of activities on this page