This repository has been archived by the owner on Sep 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
John.java
executable file
·68 lines (56 loc) · 1.34 KB
/
John.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.awt.Color;
import ch.aplu.turtle.Turtle;
public class John {
public static void main(String[] args) {
/*
* Fuer dieses Beispiel wird das Java Utility Package for Java von
* Aegidius Pluess benoetigt:
* http://www.aplu.ch/home/apluhomex.jsp?site=65
*/
/*
* Neue Schildkroete erzeugen. Achtung ihr dürft eure Klasse nicht
* Turtle nennen!
*/
Turtle john = new Turtle();
/*
* Schriftgroesse setzten
*/
john.setFontSize(10);
/*
* 7,5 Schritte nach vorne gehen.
*/
john.forward(7.5);
/*
* For-Schleife für die Seiten.
*/
for (int i = 1; i <= 21; i++) {
/*
* Die Farbe wird für jede Seite gesetzt. Dazu wird i durch 4
* dividiert und der Restwert mit einer If-Abfrage ueberprueft. i %
* 4 kann 0, 1, 2 oder 3 als Ergebnis annehmen.
*/
if (i % 4 == 1) {
john.setPenColor(Color.BLACK);
} else if (i % 4 == 2) {
john.setPenColor(Color.RED);
} else if (i % 4 == 3) {
john.setPenColor(Color.GREEN);
} else {
john.setPenColor(Color.BLUE);
}
/*
* Schritt vorwaerts gehen. Die Schritte werden berechnet indem i
* mit 15 mulitpliziert wird.
*/
john.forward(i * 15);
/*
* Um 90 Grad nach rechts drehen.
*/
john.left(90);
/*
* Label ausgeben.
*/
john.label((int) john.getX() + "/" + (int) john.getY());
}
}
}