In this tutorial we want to use the Simple Turtle and draw a square and a triangle. For working with the Simple Turtle you need the "simpleturtle.h" header file. The Simple Turtle has no structure so it is the same in C and C++. You will only have to use these functions: simpleturtle.h
So lets start and create the new file "tut1.c" in your project:
#include "grubc/turtle/simpleturtle.h" int main(int argc, char *argv[]) { int i = 0; /* First initialize the Simple Turtle with the path and name of the library jar file, the window name and the width and height of the window. */ initSimpleTurtle("./grubc.jar", "Tutorial 1", 500, 300); /* Move away from top left. */ penUp(); /* Switch drawing off. */ right(45); /* Turn 45 degrees right. */ forward(100); /* Move 100 forward. */ left(45); /* Turn 45 degrees back. */ penDown(); /* Switch drawing on. */ setColor(BLUE); /* Set drawing color to blue. */ /* Draw a square with side length 100. */ for (i = 0; i <= 3; i++) { forward(100); /* Move 100 forward. */ right(90); /* Turn 90 degrees right. */ } penUp(); /* Switch drawing off. */ forward(200);/* Move 200 forward. */ penDown(); /* Switch drawing on. */ setColor(RED); /* Set drawing color to red. */ /* Draw an equilateral triangle with side length 100. */ for (i = 0; i <= 2; i++) { forward(100); /* Move 100 forward. */ right(120); /* Turn 120 degrees right. */ } /* Wait until the user closes the frame. */ waitForClosingFrame(); return 0; }
When you execute this program you will get a window which looks like this:
The Simple Turtle provides more functions. Have look at the documentation simpleturtle.h and test these functions.