Turtlegraphics for Smartphones and Tablets

Bern University of Teacher Education  
HomeStart Online EditorPrintAndroid GamesJava-Online

Serie 8: Use multiple turtles

 

1)
 

Two turtles are alternatively drawing lines of a star figure.
As a rotation angle the angles 144° or 160° for instance are suitable.

As a draft you may use the following example:

 

Edit example with online-compiler

 

2)

Two turtles are alternatively drawing squares. The first turtle is drawing in red, the second one in green. Draw first non-filled and then filled squares.

 

Edit example with online-compiler

 

3)      

 

4)

Two turtles are moving with random routes and angles e.g.: left(-180 + 360 * Math.random()). So that they won't go outside of the playground's borders, a method isForwardValid(s) to check whether the next route the turtle will go is still within the playground, can be used. Otherwise a rotation of 180° for instance can be carried out.

So that the turtle movement keeps going, normally an endless while-loop is used::

 

while (true)
{

}