Skip to content

Commit 2a603f7

Browse files
committed
refactored ConnectTheDots
1 parent a0a3640 commit 2a603f7

2 files changed

Lines changed: 37 additions & 37 deletions

File tree

12 Bytes
Binary file not shown.
Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
11
package org.teachingkidsprogramming.section08events;
22

33
import org.teachingextensions.logo.Tortoise;
4+
import org.teachingextensions.logo.utils.ColorUtils.ColorWheel;
5+
import org.teachingextensions.logo.utils.ColorUtils.PenColors;
46
import org.teachingextensions.logo.utils.EventUtils.MouseLeftClickListener;
57
import org.teachingextensions.logo.utils.EventUtils.MouseRightClickListener;
68

79
public class ConnectTheDots implements MouseRightClickListener, MouseLeftClickListener
810
{
911
public static void main(String[] args)
1012
{
11-
// Create a new 'Connect The Dots' object. --#1.1
13+
new ConnectTheDots();
1214
}
1315
public ConnectTheDots()
1416
{
15-
Tortoise.show();
17+
setUpTheWindow();
18+
prepareColorPalette();
19+
// Listen for left clicks on the window for the tortoise --#1
1620
// 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
3521
}
3622
@Override
37-
public void onRightMouseClick(int x, int y)
23+
public void onLeftMouseClick(int x, int y)
3824
{
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());
4038
}
4139
@Override
42-
public void onLeftMouseClick(int x, int y)
40+
public void onRightMouseClick(int x, int y)
4341
{
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();
5858
}
5959
}

0 commit comments

Comments
 (0)