forked from League-Archive/IntroToJavaWorkshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTriangleShell.java
More file actions
executable file
·44 lines (34 loc) · 1.03 KB
/
TriangleShell.java
File metadata and controls
executable file
·44 lines (34 loc) · 1.03 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
package section2;
import org.jointheleague.graphical.robot.Robot;
public class TriangleShell {
// 1. Create a new Robot
Robot hello = new Robot("batman");
void go() {
// 6. Make the robot go as fast as possible
hello.setSpeed(500);
// 4. make a variable to hold the length of the triangle and set it to 50
int length = 50;
// 7. Use a for loop to repeat steps #9 to #10, 60 times
for(int i = 0; i < 60 ; i++){
// 9. Change the color of the pen to a random color
hello.setRandomPenColor();
// 8. Increase the length variable by 10
length +=10;
// 5. call your drawTriangle() method using your length variable
drawTriangle(length);
// 10. Turn the robot 6 degrees to the right
hello.turn(6);
}
}
/* 2. fill in the method below to draw a triangle. Use the length variable when you call move(). */
private void drawTriangle(int length) {
for(int i = 0; i < 3 ; i++) {
hello.penDown();
hello.move(length);
hello.turn(120);
}
}
public static void main(String[] args) {
new TriangleShell().go();
}
}