|
1 | 1 | package org.teachingkidsprogramming.section08events; |
2 | 2 |
|
3 | 3 | import org.teachingextensions.logo.Tortoise; |
| 4 | +import org.teachingextensions.logo.utils.ColorUtils.ColorWheel; |
| 5 | +import org.teachingextensions.logo.utils.ColorUtils.PenColors; |
4 | 6 | import org.teachingextensions.logo.utils.EventUtils.MouseLeftClickListener; |
5 | 7 | import org.teachingextensions.logo.utils.EventUtils.MouseRightClickListener; |
6 | 8 |
|
7 | 9 | public class ConnectTheDots implements MouseRightClickListener, MouseLeftClickListener |
8 | 10 | { |
9 | 11 | public static void main(String[] args) |
10 | 12 | { |
11 | | - // Create a new 'Connect The Dots' object. --#1.1 |
| 13 | + new ConnectTheDots(); |
12 | 14 | } |
13 | 15 | public ConnectTheDots() |
14 | 16 | { |
15 | | - Tortoise.show(); |
| 17 | + setUpTheWindow(); |
| 18 | + prepareColorPalette(); |
| 19 | + // Listen for left clicks on the window for the tortoise --#1 |
16 | 20 | // Listen for right clicks on the window for the tortoise --#20.2 |
17 | | - // Listen for left clicks on the window for the tortoise --#1.2 |
18 | | - // Make the Tortoise go as fast as possible. --#4 |
19 | | - // clearTheScreen (recipe below) --#19.1 |
20 | | - // |
21 | | - // ------------- Recipe for clearTheScreen --#19.2 |
22 | | - // Clear the Tortoise --#20.1 |
23 | | - // Write "Right click to clearWindow" on the screen at position 100, 100 --#18 |
24 | | - // ------------- End of clearTheScreen Recipe --#19.3 |
25 | | - // |
26 | | - // prepareColorPalette (recipe below) --#17.1 |
27 | | - // ------------- Recipe for prepareColorPalette --#17.2 |
28 | | - // Add red to the color wheel --#6 |
29 | | - // Add green to the color wheel --#12 |
30 | | - // Add blue to the color wheel --#13 |
31 | | - // Add purple to the color wheel --#14 |
32 | | - // Add pink to the color wheel --#15 |
33 | | - // Add teal to the color wheel --#16 |
34 | | - // ------------- End of prepareColorPalette Recipe --#17.3 |
35 | 21 | } |
36 | 22 | @Override |
37 | | - public void onRightMouseClick(int x, int y) |
| 23 | + public void onLeftMouseClick(int x, int y) |
38 | 24 | { |
39 | | - // clearTheScreen (recipe above) --#20.3 |
| 25 | + // addDot at x and y (recipe below) --#5 |
| 26 | + // ------------- Recipe for addDot --#6 |
| 27 | + // createCircle at x and y (recipe below) --#2 |
| 28 | + // ------------- Recipe for createCircle --#3.0 (everything in this recipe) |
| 29 | + // Create a new circle with a radius of 11 using the next color on the color wheel |
| 30 | + // Change the circle to be 60% opaque |
| 31 | + // Move the circle so that it's center is at the current position of the mouse (x,y) |
| 32 | + // Place the circle on the tortoise's window |
| 33 | + // ------------- End of createCircle Recipe --#3.1 |
| 34 | + // Move the tortoise to the current position of the mouse (x,y) --#4 |
| 35 | + // ------------- End of addDot Recipe |
| 36 | + // Uncomment to write the text "Right click to clear the window" on the screen at position 100, 100 --#8 |
| 37 | + // new Text("Right click to clear the window").setTopLeft(100, 100).addTo(Tortoise.getBackgroundWindow()); |
40 | 38 | } |
41 | 39 | @Override |
42 | | - public void onLeftMouseClick(int x, int y) |
| 40 | + public void onRightMouseClick(int x, int y) |
43 | 41 | { |
44 | | - // addDot (recipe below) --#11.1 |
45 | | - // |
46 | | - // ------------- Recipe for addDot --#11.2 |
47 | | - // addACircle (recipe below) --#10.1 |
48 | | - // |
49 | | - // ------------- Recipe for addACircle --#10.2 |
50 | | - // Create a circle with a radius of 7 which is the same color as the next color on the color wheel --#5 |
51 | | - // Change the circle to be 40% opaque --#9 |
52 | | - // Move the circle so that it's center is at the current position of the mouse --#8 |
53 | | - // Place the circle on the tortoise's window. --#7 |
54 | | - // ------------- End of addACircle Recipe --#10.3 |
55 | | - // |
56 | | - // Move the tortoise to the current position of the mouse --#2 |
57 | | - // ------------- End of addDot Recipe --#11.3 |
| 42 | + // Clear everything from the window HINT: Use Tortoise --#7 |
| 43 | + } |
| 44 | + private static void prepareColorPalette() |
| 45 | + { |
| 46 | + ColorWheel.addColor(PenColors.Reds.Red); |
| 47 | + ColorWheel.addColor(PenColors.Greens.Green); |
| 48 | + ColorWheel.addColor(PenColors.Blues.Blue); |
| 49 | + ColorWheel.addColor(PenColors.Purples.Purple); |
| 50 | + ColorWheel.addColor(PenColors.Pinks.Pink); |
| 51 | + ColorWheel.addColor(PenColors.Greens.Teal); |
| 52 | + } |
| 53 | + private void setUpTheWindow() |
| 54 | + { |
| 55 | + Tortoise.show(); |
| 56 | + Tortoise.setSpeed(10); |
| 57 | + Tortoise.hide(); |
58 | 58 | } |
59 | 59 | } |
0 commit comments