Turtlegraphics for Smartphones and Tablets |
|
Bern University of Teacher Education |
In the first example, two steps of a staircase are drawn.
|
package app.tu1 | An Android-Application has to receive a Package-name with at least one point. It serves as identification of our app for smartphone or table |
import turtle.* |
Imports the class library JTurtleLib |
public | Makes the class "visible", so that it can be executed with the Android-operation-system |
class Tu1 | Defines a program unit. Tu1 is the class name |
extends Playground | Creates a playground (400x400 steps) and gives acces to all methods |
void main() { } |
By using the methodmain() Android-operation-system starts the program's cycle |
showTurtle() oder kurz st() | Shows the global, at the beginning hidden turtle, that appears in the middle of the playground |
forward (100) oder kurz fd(100) | The turtle moves 100 steps forward |
right(90) oder kurz rt(90) | The turtle turns in a 90° angle to the right |
left(90) oder kurz lt(90) | The turtle turns in a 90° angle to the left |
|
Turtle john = new Turtle(); | Creates an object of the class Turtle |
john.fd(50) | The method fd(50) is executed by the turtle john |
luka.lt(90).fd(50).lt(90).fd(50); | The methods can be written in succession with a full-stop separator but without vertical spacing |
Syntax: