-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathholidaytree.java
More file actions
66 lines (58 loc) · 2.07 KB
/
Copy pathholidaytree.java
File metadata and controls
66 lines (58 loc) · 2.07 KB
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
import org.teachingextensions.logo.Colors;
import org.teachingextensions.logo.Tortoise;
public class holidaytree {
public static void main(String[] args) {
holidaytree ohChristmasTree = new holidaytree();
ohChristmasTree.drawStar();
ohChristmasTree.drawTreeBody();
ohChristmasTree.drawTreeTrunk();
}
double treeWidth = 15;
double scale = 1.1; //This is how much the width of the tree increases with each layer down
void drawTreeBody() {
// 8. Change the color of the line the tortoise draws to forest green
Tortoise.setSpeed(10);
Tortoise.setPenColor(Colors.Greens.Chartreuse);
// 1. Make a variable for turnAmount and set it to 175
int turnAmount = 175;
// 2. Start the Tortoise facing to the right
Tortoise.turn(90);
// 5. Repeat steps 3 through 11, 11 times
for (int i=0; i<11; i++) {
// 3. Move the tortoise the width of the tree
Tortoise.move(treeWidth);
// 4. Turn the tortoise the current turnAmount to the right
Tortoise.turn(turnAmount);
// 6. Set the treeWidth to the current treeWidth times the scale
treeWidth=treeWidth*scale;
// 7. Move the tortoise the width of a tree again
Tortoise.move(treeWidth);
// 9. Turn the tortoise the current turn amount to the LEFT
Tortoise.turn(-turnAmount);
// 10. Set the treeWidth to the current treeWidth times the scale again
treeWidth=treeWidth*scale;
// 11. Decrease turnAmount by 1
turnAmount--;
}
}
void drawTreeTrunk() {
// 1. Move the tortoise half the width of the tree
Tortoise.move(treeWidth/2);
// 2. Change the tortoise so that it is pointing straight down
Tortoise.turn(90);
// 4. Set the pen width to the tree width divided by 10
Tortoise.setPenWidth(treeWidth/10);
// 5. Change the color of the line the tortoise draws to brown
Tortoise.setPenColor(Colors.Browns.Chocolate);
// 3. Move the tortoise a quarter the tree width
Tortoise.move(treeWidth/4);
}
void drawStar() {
// * Optional: Draw a red star on top of the tree. Hint: 144 degrees makes a star.
Tortoise.setPenColor(Colors.Reds.IndianRed);
for (int i=0; i<5; i++) {
Tortoise.move(15);
Tortoise.turn(144);
}
}
}