Turtlegraphics for Smartphones and Tablets

Bern University of Teacher Education  
HomeStart Online EditorPrintAndroid GamesJava-Online

Serie 4: if-else-structure, colours

Draw the following figures


Edit source with online-compiler



Use the methods:

setPos(x, y) to set the beginning point of each line and

moveTo(x, y) to set the end point of each line


Edit source with online-compiler



  The areas can be coloured with the aid of fillToHorizontal(y).
See example Tu5a.java under use colours.

Use the switch-structure to draw the adjoining figure with different colours. For the colouring out of the squares you may use the method fillToPoint(x, y). By using getX() and getY() the current position of the turtle can be requested.  

As a draft you can use the following example:

Edit source with online-compiler