Skip to content

Commit 0138539

Browse files
committed
last day
1 parent 0b5efde commit 0138539

8 files changed

Lines changed: 108 additions & 77 deletions

File tree

src/day1/robot/PentagonCrazy.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
package day1.robot;
23

34
import java.awt.Color;

src/day5/FlamingNinjaStar.java

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,66 @@
11
package day5;
2+
3+
import java.awt.Color;
4+
25
import org.jointheleague.graphical.robot.Robot;
36

47
/*** Teacher's note ***/
5-
/* Before beginning recipe:
6-
* 1. ask students to find and explain the variable in this recipe.
7-
* 2. ask students what robot commands they think they will use to make picture in the laminated hand-outs. */
8+
/*
9+
* Before beginning recipe: 1. ask students to find and explain the variable in
10+
* this recipe. 2. ask students what robot commands they think they will use to
11+
* make picture in the laminated hand-outs.
12+
*/
813

914
public class FlamingNinjaStar {
1015
public static void main(String[] args) {
1116

12-
int baseSize = 300; //the size of the black part of the star
13-
int flameSize = 200; //the length of the flaming arms
17+
int baseSize = 300; // the size of the black part of the star
18+
int flameSize = 200; // the length of the flaming arms
1419

15-
// *14. Use the methods setX and setY to move the ninja star into the center of the screen
16-
17-
// *15. Make some adjustments to see what other kinds of shapes you can make.
20+
// *14. Use the methods setX and setY to move the ninja star into the
21+
// center of the screen
1822

19-
// 1. Make a new robot, and set it's pen down.
23+
// *15. Make some adjustments to see what other kinds of shapes you can
24+
// make.
2025

26+
// 1. Make a new robot, and set it's pen down.
27+
Robot andrew = new Robot();
2128
// 12. Set the robot speed to 10
22-
29+
andrew.setSpeed(10);
30+
int x = 0;
2331
// 13. Make all the code below repeat 25 times
32+
while (x < 25) {
2433

2534
// 2. Turn the robot 1/8 of a circle
26-
35+
andrew.turn(360 / 8);
2736
// 3. Move the robot 64 pixels
37+
andrew.penDown();
38+
andrew.setPenColor(Color.BLACK);
39+
andrew.move(64);
2840

29-
30-
// 4. Turn the robot 40 degrees to the LEFT. (Negative numbers will turn the robot counter-clockwise.)
31-
41+
// 4. Turn the robot 40 degrees to the LEFT. (Negative numbers will
42+
// turn
43+
// the robot counter-clockwise.)
44+
andrew.turn(-40);
3245
// 5. Move the robot the distance in the variable flameSize
33-
46+
andrew.setPenColor(Color.YELLOW);
47+
andrew.move(flameSize);
3448
// 6. Turn the robot 170 degrees
35-
49+
andrew.turn(170);
3650
// 7. Move the robot the distance in the variable flameSize (again)
37-
51+
andrew.setPenColor(Color.YELLOW);
52+
andrew.move(flameSize);
3853
// 8. Turn the robot 64 degrees to the right
39-
54+
andrew.turn(64);
4055
// 9. Move the robot the distance in the variable baseSize
41-
42-
// 10. Check that your shape is the same as Figure 1. This is one arm of the ninja star.
56+
andrew.setPenColor(Color.BLACK);
57+
andrew.move(baseSize);
58+
// 10. Check that your shape is the same as Figure 1. This is one
59+
// arm of
60+
// the ninja star.
61+
x = x + 1;
4362
// 11. Color your ninja star like Figure 2.
44-
63+
}
4564
}
4665

4766
}
48-
49-

src/day5/ScaryMaze.java

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,64 @@
1212
import javax.imageio.ImageIO;
1313
import javax.swing.JApplet;
1414
import javax.swing.JFrame;
15+
import javax.swing.JOptionPane;
1516
import javax.swing.JPanel;
1617
import javax.swing.SwingUtilities;
1718

1819
public class ScaryMaze extends JPanel implements Runnable, MouseMotionListener {
19-
20+
2021
BufferedImage maze;
21-
final int frameWidth = 600;
22-
final int frameHeight = 400;
22+
final int frameWidth = 800;
23+
final int frameHeight = 600;
2324

2425
ScaryMaze() throws Exception {
25-
//1. Use this online tool to make a maze image and drop it into your day5 package: http://pixlr.com/editor/
26+
// 1. Use this online tool to make a maze image and drop it into your
27+
// day5 package: http://pixlr.com/editor/
2628
maze = ImageIO.read(getClass().getResource("maze.png"));
27-
//2. set the mouse pointer to the start of your maze using:
28-
//new Robot().mouseMove(xPosition, yPosition)
29-
30-
//3. add a mouse motion listener using:
31-
//addMouseMotionListener(this)
32-
29+
// 2. set the mouse pointer to the start of your maze using:
30+
// new Robot().mouseMove(xPosition, yPosition)
31+
new Robot().mouseMove(50, 100);
32+
33+
// 3. add a mouse motion listener using:
34+
// addMouseMotionListener(this)
35+
addMouseMotionListener(this);
3336
}
3437

3538
@Override
3639
public void mouseMoved(MouseEvent e) {
3740
int mouseX = e.getX();
3841
int mouseY = e.getY();
3942
int mouseColor = maze.getRGB(mouseX, mouseY);
40-
//4. print the mouseColor variable to see what color the mouse is touching
41-
42-
//5. make a variable to hold the background color.
43-
44-
//6. if the mouse falls off the path (if it is on the background)
45-
46-
// call the scare method
47-
48-
//10. if the mouse is on the end color
49-
50-
// pop up a message to tell them they won
51-
43+
// 4. print the mouseColor variable to see what color the mouse is
44+
// touching
45+
System.out.println(mouseColor);
46+
// 5. make a variable to hold the background color.
47+
int bc = -12553419;
48+
// 6. if the mouse falls off the path (if it is on the background)
49+
if (bc == mouseColor) {
50+
// call the scare method
51+
scare();
52+
}
53+
// 10. if the mouse is on the end color
54+
if (mouseColor == -4120798) {
55+
JOptionPane.showMessageDialog(null, "YOU WON!");
56+
}
57+
// pop up a message to tell them they won
58+
5259
}
5360

5461
private void scare() {
55-
System.out.println("BOO!");
56-
//7. find a scary sound and put it in the day5 package where you put your maze picture. You can find a sound on freesound.org. Log in as leagueofamazing/code4life.
57-
//AudioClip sound = JApplet.newAudioClip(getClass().getResource("scream.wav"));
58-
59-
//8. play the scary sound. Hint: type "sound" and then a period.
60-
61-
//9. drop an image into your day5 package, and use the showScaryImage method to scare your victim!
62-
62+
//System.out.println("BOO!");
63+
// 7. find a scary sound and put it in the day5 package where you put
64+
// your maze picture. You can find a sound on freesound.org. Log in as
65+
// leagueofamazing/code4life.
66+
AudioClip sound = JApplet.newAudioClip(getClass().getResource("scream.wav"));
67+
68+
// 8. play the scary sound. Hint: type "sound" and then a period.
69+
sound.play();
70+
// 9. drop an image into your day5 package, and use the showScaryImage
71+
// method to scare your victim
72+
showScaryImage("scare.jpg");
6373
}
6474

6575
private void showScaryImage(String imageName) {
@@ -92,9 +102,7 @@ public void paintComponent(Graphics g) {
92102
}
93103

94104
@Override
95-
public void mouseDragged(MouseEvent e) {}
105+
public void mouseDragged(MouseEvent e) {
106+
}
96107

97108
}
98-
99-
100-

src/day5/Scream.ogg

22.4 KB
Binary file not shown.

src/day5/Scream.wav

210 KB
Binary file not shown.

src/day5/StarShow.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,52 @@ public class StarShow {
1313

1414
void makeStars() {
1515

16-
drawStar(150); //5. delete this line. you will draw the star again in step 8.
16+
//5. delete this line. you will draw the star again in step 8.
1717
// 13. Set the speed to 8
18-
18+
robot.setSpeed(8);
1919
// 6. Make a variable to hold the X position of the Robot and set it to 10
20-
20+
int newX = 10;
2121
// 7. Make a variable to hold the Y position of the Robot and set it to 950
22-
22+
int newY = 950;
2323
// 8. Make a variable to hold the star size and set it to 25
24-
24+
int starSize = 25;
2525
// 12. Repeat the steps #19 to #18, 30 times
26+
int x2 = 0;
27+
while(x2<30){
28+
x2 = x2+ 1;
2629

2730
// 19. Set the pen width to i
28-
31+
robot.setPenWidth(x2);
2932
// 10. Set the X position of the robot to your X variable
30-
33+
robot.setX(newX);
3134
// 11. Set the Y position of the robot to your Y variable
32-
35+
robot.setX(newY);
3336
// 9. Call the drawStar() method with your star size variable
34-
37+
drawStar(starSize);
3538
// 14. Increase the X position by star size. See Figure 2.
36-
39+
newX = newX + starSize;
3740
// 15. decrease the Y position by star size. See Figure 3.
38-
41+
newY = newY + starSize;
3942
// 16. Increase the star size by 20
40-
43+
starSize = starSize + 20;
4144
// 17. Turn the robot 12 degrees
42-
45+
robot.turn(12);
4346
// 18. Make each star a different random color like in Figure 4.
44-
45-
}
47+
robot.setRandomPenColor();
48+
}}
4649

4750
private void drawStar(int starSize) {
4851
// 2. Put the robot's pen down
49-
52+
robot.penDown();
5053
// 4. Repeat both commands 5 times. See Figure 1 at http://bit.ly/star-show
51-
54+
int x = 0;
55+
while(x<5){
5256
// 1. Move the robot the distance of the starSize variable
53-
57+
robot.move(starSize);
5458
// 3. Turn the robot 144 degrees
55-
56-
}
59+
robot.turn(144);
60+
x=x+1;
61+
}}
5762

5863
public static void main(String[] args) {
5964
new StarShow().makeStars();

src/day5/maze.png

32.6 KB
Loading

src/day5/scare.jpg

22.4 KB
Loading

0 commit comments

Comments
 (0)