Skip to content

Commit 6bc2c9e

Browse files
league-workshopperleague-workshopper
authored andcommitted
Finished Robot version of Pentagon Crazy.
1 parent b2f2524 commit 6bc2c9e

2 files changed

Lines changed: 56 additions & 11 deletions

File tree

src/day1/robot/PentagonCrazy.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package day1.robot;
2+
3+
import java.awt.Color;
4+
5+
import org.jointheleague.graphical.robot.Robot;
6+
7+
/* Teacher’s note: before beginning, draw a pentagon and have students work out the angle that the robot will have to turn (360/5) */
8+
9+
public class PentagonCrazy {
10+
11+
private void makePrettyThings() {
12+
// 1. Create a new Robot
13+
14+
// 3. Put the robot's pen down
15+
16+
// 8. Make the robot go at maximum speed (10)
17+
18+
// 9. Set the pen to a color that you like for the shape
19+
20+
// 4. Make a variable for the number of sides you want (can’t test this one)
21+
22+
// 5. Make a variable for the angle you want the robot to turn. Hint: you can divide in Java using "/". Can’t test until step 6.
23+
24+
// 7. Do steps #2 to #11, 200 times. When this is done you should see a pentagon.
25+
26+
// 2. Move the robot 200 pixels
27+
28+
// 10. Make the robot move "i" pixels instead of 200 (don’t need new line of code for this, just change previous one)
29+
30+
// 6. Turn the robot the amount in your angle variable
31+
32+
// 11. Turn the robot one more degree
33+
34+
}
35+
36+
// Variations:
37+
// *12. make the pattern really huge
38+
// *13. randomize the color of the pattern
39+
// *14. experiment with different shapes
40+
41+
public static void main(String[] args) {
42+
new PentagonCrazy().makePrettyThings();
43+
}
44+
}

src/solutions/PentagonCrazySolution.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
package solutions;
22

3+
import java.awt.Color;
4+
35
import org.jointheleague.graphical.robot.Robot;
46

57
/* Teacher’s note: before beginning, draw a pentagon and have students work out the angle that the robot will have to turn (360/5) */
68

79
public class PentagonCrazySolution {
810

911
private void makePrettyThings() {
10-
// 1. create a new Robot
12+
// 1. Create a new Robot
1113
Robot robot = new Robot();
1214
// 3. Put the robot's pen down
1315
robot.penDown();
14-
// 8. make the robot go at maximum speed
16+
// 8. Make the robot go at maximum speed (10)
1517
robot.setSpeed(10);
16-
// 9. choose a color that you like for the shape
17-
robot.setPenColor(30, 130, 30);
18-
// 4. make a variable for the number of sides you want (can’t test this one)
18+
// 9. Set the pen to a color that you like for the shape
19+
robot.setPenColor(Color.CYAN);
20+
// 4. Make a variable for the number of sides you want (can’t test this one)
1921
int sides = 5;
20-
// 5. make a variable for the angle you want the robot to turn. Hint: you can divide in Java using “/”. Can’t test until step 6.
22+
// 5. Make a variable for the angle you want the robot to turn. Hint: you can divide in Java using "/". Can’t test until step 6.
2123
int angle = 360 / sides;
22-
// 7. Do everything below 200 times. When this is done you will see a pentagon.
24+
// 7. Do everything below 200 times. When this is done you should see a pentagon.
2325
for (int i = 0; i < 200; i++) {
2426
// 2. Move the robot 200 pixels
2527
// robot.move(200);
26-
// 9. make the robot move "i" pixels instead of 200 (don’t need new line of code for this, just change previous one)
28+
// 9. Make the robot move "i" pixels instead of 200 (don’t need new line of code for this, just change previous one)
2729
robot.move(i);
28-
// 6. turn the robot the amount in your angle variable
30+
// 6. Turn the robot the amount in your angle variable
2931
robot.turn(angle);
30-
// 10. turn the robot one more degree
32+
// 10. Turn the robot one more degree
3133
robot.turn(1);
3234
}
33-
3435
}
3536

3637
// Variations:

0 commit comments

Comments
 (0)