-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolygonFlower.java
More file actions
37 lines (30 loc) · 838 Bytes
/
PolygonFlower.java
File metadata and controls
37 lines (30 loc) · 838 Bytes
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
public class PolygonFlower {
public static void main(String[] args) {
Turtle dan = new Turtle();
dan.penup();
dan.left(90);
dan.forward(200);
dan.right(90);
dan.pendown();
dan.delay(10); // make the turtle faster (0 = fastest)
flower(dan, 7, 15, 50);
}
public static void polygon(Turtle t, int numSides, double length) {
for (int i = 0; i < numSides; i++) {
t.forward(length);
t.left(360.0 / numSides);
}
}
public static void petal(Turtle t, int numLayers, double length) {
for (int i = 0; i < numLayers; i++) {
polygon(t, i + 3, length);
}
}
public static void flower(Turtle t, int numPetals, int numLayers, double length) {
for (int i = 0; i < numPetals; i++) {
petal(t, numLayers, length);
t.forward(length);
t.right(360.0 / numPetals);
}
}
}