Department of Computer Science | Institute of Theoretical Computer Science | CADMO

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

Reference Manual: Navigation: Up, Table of Contents, Index,

Libturtle - Turtle Graphics

This is a short description of Libturtle, a small turtle graphic library based on Libwindow. If you want to use the library in your program, do not forget the following include directive.

#include <IFM/turtle>

Imagine a turtle walking on the Euclidean plane and leaving a trace behind it. At any time, the turtle has a certain position and a view direction. Initially, it is looking to the right. You can influence these parameters using the following functions.

void ifm::forward ( unsigned int i = 1)
Move the turtle i steps in view direction.

void ifm::left ( int d = 1)
Turn the turtle left by an angle of d degree.

void ifm::right ( int d = 1)
Turn the turtle right by an angle of d degree.

When the drawing is complete, i.e., at the end of the program, it is shown in a window of 512 × 512 pixels, appropriately scaled to use the space available. A mouseclick then destroys the window and ends the program.

Example

The following code draws a regular pentagon. Then it waits for a mouseclick to finish.

#include <IFM/turtle>

int main() 
{
    for (unsigned int i = 0; i < 5; ++i) {
        ifm::forward();
        ifm::left(72);
    }
    return 0;
}


Navigation: Up, Table of Contents, Index,
Michael Hoffmann. Wed, November 17, 2004.