11package org .teachingkidsprogramming .recipes .completed .section08events ;
22
3- import java .awt .Color ;
4-
53import org .teachingextensions .logo .Tortoise ;
64import org .teachingextensions .logo .utils .ColorUtils .ColorWheel ;
75import org .teachingextensions .logo .utils .ColorUtils .PenColors ;
@@ -14,79 +12,62 @@ public class ConnectTheDots implements MouseRightClickListener, MouseLeftClickLi
1412{
1513 public static void main (String [] args )
1614 {
17- //Create new a 'Connect the Dots' object.
1815 new ConnectTheDots ();
1916 }
2017 public ConnectTheDots ()
2118 {
22- Tortoise .show ();
19+ setUpTheWindow ();
20+ prepareColorPalette ();
21+ // Listen for left clicks on the window for the tortoise
22+ Tortoise .getBackgroundWindow ().addMouseLeftClickListener (this );
2323 // Listen for right clicks on the window for the tortoise
2424 Tortoise .getBackgroundWindow ().addMouseRightClickListener (this );
25- // Listen for left clicks on the window for the tortoise
26- Tortoise .getBackgroundWindow ().addMouseLeftClickListener (this );
27- //Make the Tortoise go as fast as possible.
28- Tortoise .setSpeed (10 );
29- // clearTheScreen (recipe below)
30- clearTheScreen ();
31- // prepareColorPalette (recipe below)
32- prepareColorPalette ();
3325 }
34- private static void prepareColorPalette ()
26+ @ Override
27+ public void onLeftMouseClick (int x , int y )
3528 {
36- // ------------- Recipe for prepareColorPalette
37- //
38- // Add red to the color wheel
39- ColorWheel .addColor (PenColors .Reds .Red );
40- // Add green to the color wheel
41- ColorWheel .addColor (PenColors .Greens .Green );
42- // Add blue to the color wheel
43- ColorWheel .addColor (PenColors .Blues .Blue );
44- // Add purple to the color wheel
45- ColorWheel .addColor (PenColors .Purples .Purple );
46- // Add pink to the color wheel
47- ColorWheel .addColor (PenColors .Pinks .Pink );
48- // Add teal to the color wheel
49- ColorWheel .addColor (PenColors .Greens .Teal );
29+ // addDot at x and y (recipe below)
30+ addDot (x , y );
31+ // Uncomment to write the text "Right click to clear the window" on the screen at position 100, 100
32+ new Text ("Right click to clear the window" ).setTopLeft (100 , 100 ).addTo (Tortoise .getBackgroundWindow ());
5033 }
5134 private void addDot (int x , int y )
5235 {
53- // ------------- Recipe for addDot
54- // addACircle (recipe below)
55- addCircle (x , y );
56- // Move the tortoise to the current position of the mouse # 8
36+ // createCircle at x and y (recipe below)
37+ createCircle (x , y );
38+ // Move the tortoise to the current position of the mouse (x,y)
5739 Tortoise .moveTo (x , y );
5840 }
59- private void addCircle (int x , int y )
41+ private void createCircle (int x , int y )
6042 {
61- // ------------- Recipe for addACircle
62- // The width of the circle is 15
63- int radius = 7 ;
64- // Change the color for the next shape to the next color from the color wheel
65- Color color = ColorWheel .getNextColor ();
66- // Create a circle
67- Circle circle = new Circle (radius , color );
68- // Change the circle to be 40% opaque
69- circle .setTransparency (60 );
70- // Move the center of the circle to the current position of the mouse
43+ // Create a new circle with a radius size of 11 using the next color on the Color wheel
44+ Circle circle = new Circle (11 , ColorWheel .getNextColor ());
45+ // Change the circle to be 60% opaque
46+ circle .setTransparency (40 );
47+ // Move the center of the circle to the current position of the mouse (x,y)
7148 circle .setCenter (x , y );
49+ // Add the circle to the window HINT: Use Tortoise to get the window
7250 circle .addTo (Tortoise .getBackgroundWindow ());
7351 }
74- private static void clearTheScreen ()
52+ @ Override
53+ public void onRightMouseClick (int x , int y )
7554 {
76- // ------------- Recipe for clearTheScreen
77- // Clear the Program Window
55+ // Clear everything from the window HINT: Use Tortoise
7856 Tortoise .clear ();
79- // Write "Right click to clearWindow" on the screen at position 100, 100
80- new Text ("Right click to clearWindow" ).setTopLeft (100 , 100 ).addTo (Tortoise .getBackgroundWindow ());
8157 }
82- @ Override
83- public void onRightMouseClick (int x , int y )
58+ private static void prepareColorPalette ()
8459 {
85- clearTheScreen ();
60+ ColorWheel .addColor (PenColors .Reds .Red );
61+ ColorWheel .addColor (PenColors .Greens .Green );
62+ ColorWheel .addColor (PenColors .Blues .Blue );
63+ ColorWheel .addColor (PenColors .Purples .Purple );
64+ ColorWheel .addColor (PenColors .Pinks .Pink );
65+ ColorWheel .addColor (PenColors .Greens .Teal );
8666 }
87- @ Override
88- public void onLeftMouseClick (int x , int y )
67+ private void setUpTheWindow ()
8968 {
90- addDot (x , y );
69+ Tortoise .show ();
70+ Tortoise .setSpeed (10 );
71+ Tortoise .hide ();
9172 }
9273}
0 commit comments