-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStarShow.java
More file actions
69 lines (57 loc) · 1.96 KB
/
Copy pathStarShow.java
File metadata and controls
69 lines (57 loc) · 1.96 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
import org.jointheleague.graphical.robot.Robot;
/*** Teacher's note ***/
/* Before beginning recipe:
* 1. ask students to find and explain the method in this recipe.
* 2. ask students how they might use the method to make the picture in the laminated hand-outs. */
public class StarShow {
Robot robot = new Robot("batman");
void makeStars() {
//5. delete this line. you will draw the star again in step 8.
// 13. Set the speed to 8
robot.setSpeed(10);
// 6. Make a variable to hold the X position of the Robot and set it to 10
int Xpos = 10;
// 7. Make a variable to hold the Y position of the Robot and set it to 950
int Ypos = 950;
// 8. Make a variable to hold the star size and set it to 25
int starSize = 25;
// 12. Repeat the steps #19 to #18, 30 times
for (int i=0; i<=30; i++) {
System.out.println(Ypos);
System.out.println(Xpos);
// 19. Set the pen width to i
robot.setPenWidth(i);
// 10. Set the X position of the robot to your X variable
robot.setX(Xpos);
// 11. Set the Y position of the robot to your Y variable
robot.setY(Ypos);
// 9. Call the drawStar() method with your star size variable
drawStar(starSize);
// 14. Increase the X position by star size. See Figure 2.
Xpos=Xpos+starSize;
// 15. decrease the Y position by star size. See Figure 3.
Ypos=Ypos-starSize;
// 16. Increase the star size by 20
starSize=starSize+20;
// 17. Turn the robot 12 degrees
robot.turn(12);
// 18. Make each star a different random color like in Figure 4.
robot.setRandomPenColor();
}
}
private void drawStar(int starSize) {
// 2. Put the robot's pen down
robot.penDown();
// 4. Repeat both commands 5 times. See Figure 1 at http://bit.ly/star-show
for (int i=0; i<5; i++) {
// 1. Move the robot the distance of the starSize variable
robot.move(starSize);
robot.setRandomPenColor();
// 3. Turn the robot 144 degrees
robot.turn(144);
}
}
public static void main(String[] args) {
new StarShow().makeStars();
}
}