diff --git a/TeachingKidsProgramming/src/org/teachingkidsprogramming/section01forloops/DoubleLoop.java b/TeachingKidsProgramming/src/org/teachingkidsprogramming/section01forloops/DoubleLoop.java index 274c6bd8..d1ffa1b4 100644 --- a/TeachingKidsProgramming/src/org/teachingkidsprogramming/section01forloops/DoubleLoop.java +++ b/TeachingKidsProgramming/src/org/teachingkidsprogramming/section01forloops/DoubleLoop.java @@ -3,6 +3,7 @@ import org.teachingextensions.logo.Tortoise; import org.teachingextensions.logo.utils.ColorUtils.ColorWheel; import org.teachingextensions.logo.utils.ColorUtils.PenColors; +import org.teachingextensions.logo.utils.ColorUtils.PenColors.Grays; public class DoubleLoop { @@ -10,34 +11,57 @@ public static void main(String[] args) { Tortoise.show(); // Set the tortoise x position to 225 --#1.1 + Tortoise.setX(225); // Set the tortoise y position to 150 --#1.2 + Tortoise.setY(150); // UPDATE the tortoise speed to 10 --#8.2 - Tortoise.setSpeed(5); + Tortoise.setSpeed(10); // ColorWheel.addColor(PenColors.Reds.Crimson); ColorWheel.addColor(PenColors.Reds.DarkRed); ColorWheel.addColor(PenColors.Reds.FireBrick); - // Do the following 6 times --#3.1 - // Change the pen color of the line the tortoise draws to the next color on the Color Wheel --#5 - // Move the tortoise 4 times the current line number you are drawing --#4 - // Turn the tortoise 1/6 of 360 degrees to the left --#2 - // - // Do the following 15 times --(HINT: The new line number is j) --#7.1 - // Set the pen width of the line the tortoise draws to 17 --#9 - // Move the tortoise 8 times the current line number you are drawing --#8.1 - // Turn the tortoise 1/5 of 360 degrees to the right --#6 - // Repeat --#7.2 - // - // Hide the Tortoise --#10 - Tortoise.getBackgroundWindow().setBackground(PenColors.Yellows.PeachPuff); - // Repeat --#3.2 + // Do the following 6 times --#3.1 + for (int i = 0; i < 6; i++) + { + // Change the pen color of the line the tortoise draws to the next color on the Color Wheel --#5 + Tortoise.setPenColor(ColorWheel.getNextColor()); + // Move the tortoise 4 times the current line number you are drawing --#4 + Tortoise.move(i * 4); + // Turn the tortoise 1/6 of 360 degrees to the left --#2 + Tortoise.turn(360 / -6); + // + // Do the following 15 times --(HINT: The new line number is j) --#7.1 + for (int j = 0; j < 15; j++) + { + // Set the pen width of the line the tortoise draws to 17 --#9 + Tortoise.setPenWidth(17); + // Move the tortoise 8 times the current line number you are drawing --#8.1 + Tortoise.move(j * 8); + // Turn the tortoise 1/5 of 360 degrees to the right --#6 + Tortoise.turn(360 / 5); + } + // Repeat --#7.2 + // + // Hide the Tortoise --#10 + Tortoise.hide(); + Tortoise.getBackgroundWindow().setBackground(PenColors.Yellows.PeachPuff); + // Repeat --#3.2 + } // Set the tortoise x position to 300 --#15.1 + Tortoise.setX(300); // Set the tortoise y position to 200 --#15.2 + Tortoise.setY(200); // Do the following 5 times --#12.1 - // Change the pen color of the line the tortoise draws to black --#14 - // Move the Tortoise 25 pixels --#11 - // Turn the tortoise 1/5 of 360 degrees to the right --#13 - // Repeat --#12.2 - // + for (int i = 0; i < 5; i++) + { + // Change the pen color of the line the tortoise draws to black --#14 + Tortoise.setPenColor(Grays.Black); + // Move the Tortoise 25 pixels --#11 + Tortoise.move(25); + // Turn the tortoise 1/5 of 360 degrees to the right --#13 + Tortoise.turn(360 / 5); + // Repeat --#12.2 + // + } } } diff --git a/TeachingKidsProgramming/src/org/teachingkidsprogramming/section01forloops/SimpleSquare.java b/TeachingKidsProgramming/src/org/teachingkidsprogramming/section01forloops/SimpleSquare.java index 18c7a261..e999d3f3 100644 --- a/TeachingKidsProgramming/src/org/teachingkidsprogramming/section01forloops/SimpleSquare.java +++ b/TeachingKidsProgramming/src/org/teachingkidsprogramming/section01forloops/SimpleSquare.java @@ -1,17 +1,26 @@ package org.teachingkidsprogramming.section01forloops; +import org.teachingextensions.logo.Tortoise; +import org.teachingextensions.logo.utils.ColorUtils.PenColors; + public class SimpleSquare { public static void main(String[] args) throws Exception { // Show the tortoise --#1 - // Make the tortoise move as fast as possible --#6 - // Do the following 4 times --#5.1 - // Change the pen color of the line the tortoise draws to blue --#4 - // Move the tortoise 50 pixels --#2 - // Turn the tortoise to the right (90 degrees) --#3 + Tortoise.show(); + for (int i = 0; i < 4; i++) + { + // Make the tortoise move as fast as possible --#6 + // Do the following 4 times --#5.1 + // Change the pen color of the line the tortoise draws to blue --#4 + Tortoise.setPenColor(PenColors.Blues.Blue); + // Move the tortoise 50 pixels --#2 + Tortoise.move(50); + // Turn the tortoise to the right (90 degrees) --#3 + Tortoise.turn(90); + } // Repeat --#5.2 - // // (Optional): Sign your work using the Virtual Proctor // See your work at http://virtualproctor.tkpjava.org } diff --git a/TeachingKidsProgramming/src/org/teachingkidsprogramming/section01forloops/SimpleSquareQuiz.java b/TeachingKidsProgramming/src/org/teachingkidsprogramming/section01forloops/SimpleSquareQuiz.java index 53f8972d..77e5173f 100644 --- a/TeachingKidsProgramming/src/org/teachingkidsprogramming/section01forloops/SimpleSquareQuiz.java +++ b/TeachingKidsProgramming/src/org/teachingkidsprogramming/section01forloops/SimpleSquareQuiz.java @@ -1,5 +1,7 @@ package org.teachingkidsprogramming.section01forloops; +import org.teachingextensions.logo.Tortoise; +import org.teachingextensions.logo.utils.ColorUtils.PenColors.Yellows; import org.teachingkidsprogramming.recipes.quizzes.graders.SimpleSquareQuizGrader; import org.teachingkidsprogramming.recipes.quizzes.graders.SquareQuiz; @@ -8,18 +10,22 @@ public class SimpleSquareQuiz implements SquareQuiz public void question1() { // Move the tortoise 110 pixels + Tortoise.move(110); } public void question2() { // Turn the tortoise 1/5 of 360 degrees to the right + Tortoise.turn(360 / 5); } public void question3() { // Change the pen color the tortoise draws to yellow + Tortoise.setPenColor(Yellows.Yellow); } public void question4() { // Change the width of the line the tortoise draws to 5 pixels + Tortoise.setPenWidth(5); } public static void main(String[] args) { diff --git a/TeachingKidsProgramming/src/org/teachingkidsprogramming/section01forloops/Spiral.java b/TeachingKidsProgramming/src/org/teachingkidsprogramming/section01forloops/Spiral.java index 5ff5cb79..74fc0600 100644 --- a/TeachingKidsProgramming/src/org/teachingkidsprogramming/section01forloops/Spiral.java +++ b/TeachingKidsProgramming/src/org/teachingkidsprogramming/section01forloops/Spiral.java @@ -1,5 +1,8 @@ package org.teachingkidsprogramming.section01forloops; +import org.teachingextensions.logo.Tortoise; +import org.teachingextensions.logo.utils.ColorUtils.ColorWheel; +import org.teachingextensions.logo.utils.ColorUtils.PenColors.Purples; import org.teachingextensions.logo.utils.EventUtils.MessageBox; public class Spiral @@ -7,21 +10,32 @@ public class Spiral public static void main(String[] args) { // Show the tortoise --#1 - // Make the tortoise go as fast as possible --#4 - // Add Blue Violet to the Color Wheel --#7 - // Add Violet to the Color Wheel --#8 - // Add Purple to the Color Wheel --#9 - // Do the following 75 times --#3.1 - try + Tortoise.show(); + for (int i = 0; i < 75; i++) { - // Change the pen color of the line the tortoise draws the next color on the Color Wheel --#6 - // Move the tortoise 5 times the current line number you are drawing --#5 - // Turn the tortoise 1/3 of 360 degrees to the right --#2 + // Make the tortoise go as fast as possible --#4 + Tortoise.setSpeed(10); + // Add Blue Violet to the Color Wheel --#7 + ColorWheel.addColor(Purples.BlueViolet); + // Add Violet to the Color Wheel --#8 + ColorWheel.addColor(Purples.Violet); + // Add Purple to the Color Wheel --#9 + ColorWheel.addColor(Purples.Purple); + // Do the following 75 times --#3.1 + try + { + // Change the pen color of the line the tortoise draws the next color on the Color Wheel --#6 + Tortoise.setPenColor(ColorWheel.getNextColor()); + // Move the tortoise 5 times the current line number you are drawing --#5 + Tortoise.move(i * 5); + // Turn the tortoise 1/3 of 360 degrees to the right --#2 + Tortoise.turn(125); + } + catch (RuntimeException re) + { + MessageBox.showMessage("Hold up: " + re); + } + // Repeat --#3.2 } - catch (RuntimeException re) - { - MessageBox.showMessage("Hold up: " + re); - } - // Repeat --#3.2 } } diff --git a/TeachingKidsProgramming/src/org/teachingkidsprogramming/section02methods/Houses.java b/TeachingKidsProgramming/src/org/teachingkidsprogramming/section02methods/Houses.java index 9baabf68..f1dc9df8 100644 --- a/TeachingKidsProgramming/src/org/teachingkidsprogramming/section02methods/Houses.java +++ b/TeachingKidsProgramming/src/org/teachingkidsprogramming/section02methods/Houses.java @@ -1,6 +1,7 @@ package org.teachingkidsprogramming.section02methods; import org.teachingextensions.logo.Tortoise; +import org.teachingextensions.logo.utils.ColorUtils.PenColors.Grays; public class Houses { @@ -8,22 +9,41 @@ public static void main(String[] args) { Tortoise.show(); // Make the tortoise move as fast as possible --#11 + Tortoise.setSpeed(10); // Have the tortoise start at 200 pixels in on the X axis --#14 + Tortoise.setX(200); // The current height is 40 --#1.2 + int currentHeight = 40; // drawHouse (recipe below) --#9.1 + drawHouse(currentHeight); + // drawHouse with height 120 (recipe below) --#10 + drawHouse(120); + // drawHouse with height 90 (recipe below) --#12 + drawHouse(90); + // drawHouse with height 20 (recipe below) --#13 + drawHouse(20); + } + private static void drawHouse(int currentHeight) + { // ------------- Recipe for drawHouse --#9.2 // Change the pen color of the line the tortoise draws to lightGray --#15 + Tortoise.setPenColor(Grays.LightGray); // Move the tortoise the height of a house --#1.1 + Tortoise.move(currentHeight); // Turn the tortoise 90 degrees to the right --#2 + Tortoise.turn(90); // Move the tortoise 30 pixels --#3 + Tortoise.move(30); // Turn the tortoise 90 degrees to the right --#4 + Tortoise.turn(90); // Move the tortoise the height of a house --#5 + Tortoise.move(currentHeight); // Turn the tortoise 90 degrees to the left --#6 + Tortoise.turn(-90); // Move the tortoise 20 pixels --#7 + Tortoise.move(20); // Turn the tortoise 90 degrees to the left --#8 + Tortoise.turn(-90); // ------------- End of drawHouse recipe --#9.3 - // drawHouse with height 120 (recipe below) --#10 - // drawHouse with height 90 (recipe below) --#12 - // drawHouse with height 20 (recipe below) --#13 } } diff --git a/TeachingKidsProgramming/src/org/teachingkidsprogramming/section02methods/HousesQuiz.java b/TeachingKidsProgramming/src/org/teachingkidsprogramming/section02methods/HousesQuiz.java index c7706152..94f3c61b 100644 --- a/TeachingKidsProgramming/src/org/teachingkidsprogramming/section02methods/HousesQuiz.java +++ b/TeachingKidsProgramming/src/org/teachingkidsprogramming/section02methods/HousesQuiz.java @@ -1,5 +1,6 @@ package org.teachingkidsprogramming.section02methods; +import org.teachingextensions.logo.Tortoise; import org.teachingkidsprogramming.recipes.quizzes.graders.HousesQuizAdapter; import org.teachingkidsprogramming.recipes.quizzes.graders.HousesQuizGrader; @@ -10,39 +11,60 @@ public void questions1Thru6() // Question 1 // small (recipe below) // ------------- Recipe for small - length = 7; + small(); // ------------- End of small recipe // // Question2 // medium (recipe below) // ------------- Recipe for medium // set the current length to 21 + medium(); // ------------- End of medium recipe // // Question3 // large (recipe below) // ------------- Recipe for large // set the current length to 63 - // ------------- End of large recipe - // - // Question4 - // moveTheLength (recipe below) - // ------------- Recipe for moveTheLength - // move the Tortoise the current length - // ------------- End of moveTheLength recipe - // - // Question5 - // turnTheCorner (recipe below) - // ------------- Recipe for turnTheCorner - // turn the Tortoise 1/3 of 360 degrees to the left + large(); + drawASide(); // ------------- End of turnTheCorner recipe // // Question6 // drawASide (recipe below) + drawASide(); + } + private void drawASide() + { // ------------- Recipe for drawASide // call moveTheLength and turnTheCorner + moveTheLength(); + turnTheCorner(); // ------------- End of drawASide recipe } + private void turnTheCorner() + { + Tortoise.turn(-120); + } + private void moveTheLength() + { + Tortoise.move(length); + } + private void large() + { + length = 63; + } + private void medium() + { + length = 21; + } + private void medium() + { + medium(); + } + private void small() + { + length = 7; + } public static void main(String[] args) { new HousesQuizGrader().grade(new HousesQuiz()); diff --git a/TeachingKidsProgramming/src/org/teachingkidsprogramming/section02methods/TriangleShell.java b/TeachingKidsProgramming/src/org/teachingkidsprogramming/section02methods/TriangleShell.java index c9fda2ac..7a829998 100644 --- a/TeachingKidsProgramming/src/org/teachingkidsprogramming/section02methods/TriangleShell.java +++ b/TeachingKidsProgramming/src/org/teachingkidsprogramming/section02methods/TriangleShell.java @@ -1,5 +1,7 @@ package org.teachingkidsprogramming.section02methods; +import org.teachingextensions.logo.Tortoise; +import org.teachingextensions.logo.utils.ColorUtils.PenColors; @SuppressWarnings("unused") public class TriangleShell @@ -8,20 +10,38 @@ public class TriangleShell public static void main(String[] args) { // Show the tortoise --#1 + Tortoise.show(); + int currentLength = 50; // Make the tortoise go as fast as possible --#6 + Tortoise.setSpeed(10); // Do the following 60 times --#7.1 - // Change the pen color of the line the tortoise draws to a random color --#9 - // Increase the current length of the side by 4 pixels --#8 - // drawTriangle (recipe below) --#5.1 - // + for (int i = 0; i < 60; i++) + { + // Change the pen color of the line the tortoise draws to a random color --#9 + Tortoise.setPenColor(PenColors.getRandomColor()); + // Increase the current length of the side by 4 pixels --#8 + currentLength = currentLength + 4; + // drawTriangle (recipe below) --#5.1 + // + drawTriangle(currentLength); + // + // Turn the tortoise 1/60th of 360 degrees to the right --#10 + Tortoise.turn(360 / 60); + // Repeat --#7.2 + } + } + private static void drawTriangle(int currentLength) + { // ------------- Recipe for drawTriangle --#5.2 - // Do the following 3 times --#3.1 - // Move the tortoise using the current length --#4 - // Turn the tortoise 1/3rd of 360 degrees --#2 + // Do the following 3 times --#3.1 + for (int i = 0; i < 3; i++) + { + // Move the tortoise using the current length --#4 + Tortoise.move(currentLength); + // Turn the tortoise 1/3rd of 360 degrees --#2 + Tortoise.turn(360 / 3); + } // Repeat --#3.2 // ------------- End of drawTriangle recipe --#5.3 - // - // Turn the tortoise 1/60th of 360 degrees to the right --#10 - // Repeat --#7.2 } } diff --git a/TeachingKidsProgramming/src/org/teachingkidsprogramming/section04mastery/DigiFlower.java b/TeachingKidsProgramming/src/org/teachingkidsprogramming/section04mastery/DigiFlower.java index a8956927..ab1a7cfb 100644 --- a/TeachingKidsProgramming/src/org/teachingkidsprogramming/section04mastery/DigiFlower.java +++ b/TeachingKidsProgramming/src/org/teachingkidsprogramming/section04mastery/DigiFlower.java @@ -2,22 +2,56 @@ import java.awt.Color; +import org.teachingextensions.logo.Tortoise; import org.teachingextensions.logo.utils.ColorUtils.ColorWheel; import org.teachingextensions.logo.utils.ColorUtils.PenColors; +import org.teachingextensions.logo.utils.ColorUtils.PenColors.Grays; public class DigiFlower { public static void main(String[] args) { // Show the tortoise --#1 + Tortoise.show(); // Make the tortoise move as fast as possible --#7 + Tortoise.setSpeed(10); // Make the background silver --#8 + Tortoise.getBackgroundWindow().setBackground(Grays.Silver); // Make the line the tortoise draws 3 pixels wide --#15 - // createColorPalette (recipe below) --#9.1 - // Do the following 15 times --#13.1 - // drawOctogon (recipe below) --#10.1 - // Turn the tortoise 1/15th of 360 degrees to the right --#12 - // Repeat --#14.2 + Tortoise.setPenWidth(3); + // createColorPalette (recipe below) --#9.1 + { + createColorPalette(); + // Do the following 15 times --#13.1 + for (int i = 0; i < 15; i++) + { + // drawOctogon (recipe below) --#10.1 + drawOctagon(); + // Turn the tortoise 1/15th of 360 degrees to the right --#12 + Tortoise.turn(360 / 15); + } + // Repeat --#14.2 + // + } + } + private static void drawOctagon() + { + // ------------- Recipe for drawOctogon --#10.2 + for (int i = 0; i < 8; i++) + { + // Do the following 8 times --#6.1 + // Change the pen color of the line the tortoise draws to the next color on the color wheel --#4 + Tortoise.setPenColor(ColorWheel.getNextColor()); + // Move the tortoise 50 pixels --#2 + Tortoise.move(50); + // Turn the tortoise 1/8th of 360 degrees to the right --#5p + Tortoise.turn(360 / 8.0000000000000000000000000000000000000000000000000000000000001); + } + // Repeat --#6.2 + // ------------- End of drawOctogon recipe --#10.3 + } + private static void createColorPalette() + { // ------------- Recipe for createColorPalette --#9.2 Color color1 = PenColors.Reds.Red; Color color2 = PenColors.Oranges.DarkOrange; @@ -32,13 +66,5 @@ public static void main(String[] args) ColorWheel.addColor(color2); ColorWheel.addColor(color1); // ------------- End of createColorPalette recipe --#9.3 - // - // ------------- Recipe for drawOctogon --#10.2 - // Do the following 8 times --#6.1 - // Change the pen color of the line the tortoise draws to the next color on the color wheel --#4 - // Move the tortoise 50 pixels --#2 - // Turn the tortoise 1/8th of 360 degrees to the right --#5 - // Repeat --#6.2 - // ------------- End of drawOctogon recipe --#10.3 } } diff --git a/TeachingKidsProgramming/src/org/teachingkidsprogramming/section04mastery/PentagonCrazy.java b/TeachingKidsProgramming/src/org/teachingkidsprogramming/section04mastery/PentagonCrazy.java index 9d5b0ae3..f924484a 100644 --- a/TeachingKidsProgramming/src/org/teachingkidsprogramming/section04mastery/PentagonCrazy.java +++ b/TeachingKidsProgramming/src/org/teachingkidsprogramming/section04mastery/PentagonCrazy.java @@ -1,6 +1,9 @@ package org.teachingkidsprogramming.section04mastery; import org.teachingextensions.logo.Tortoise; +import org.teachingextensions.logo.utils.ColorUtils.ColorWheel; +import org.teachingextensions.logo.utils.ColorUtils.PenColors.Blues; +import org.teachingextensions.logo.utils.ColorUtils.PenColors.Purples; public class PentagonCrazy { @@ -8,34 +11,65 @@ public static void main(String[] args) { Tortoise.show(); // Make the tortoise move as fast as possible --#3 - // createColorPalette (recipe below) --#8.1 - // - // ------------- Recipe for createColorPalette --#8.2 - // Add steel blue to the color wheel --#7 - // Add dark orchid to the color wheel --#11 - // Add dark slate blue to the color wheel --#12 - // Add teal to the color wheel --#13 - // Add indigo to the color wheel --#14 - // ------------- End of createColorPalette recipe --#8.3 + Tortoise.setSpeed(10); + createColorPalette(); // // drawPentagon (recipe below) --#10.1 // + drawPentagon(); + } + private static void drawPentagon() + { // ------------- Recipe for drawPentagon --#10.2 // Do the following 200 times --#2.1 - // adjustPen (recipe below) --#9.1 - // + for (int i = 0; i < 200; i++) + { + // adjustPen (recipe below) --#9.1 + // + adjustPen(); + // + // The current length of a side is the same as the number of the side you are about to draw ( 1st side = 1 pixel, 2nd side = 2 pixels, etc) --#4.2 + int lengthOfSide = i; + // Move the tortoise the length of a side --#4.1 + Tortoise.move(lengthOfSide); + // Turn the tortoise 1/5th of 360 degrees --#1 + Tortoise.turn(360 / 5); + // Turn the tortoise 1 more degree --#5 + Tortoise.turn(1); + // Repeat --#2.2 + } + // ------------- End of drawPentagon recipe --#10.3 + } + private static void adjustPen() + { // ------------- Recipe for adjustPen --#9.2 // Change the pen color of the line the tortoise draws to the next color on the color wheel --#6 - // Increase the tortoises pen width by 1 --#15 + Tortoise.setPenColor(ColorWheel.getNextColor()); + // Increase the tortoises pen width by 1 --#15 + Tortoise.setPenWidth(Tortoise.getPenWidth() + 1); // If the tortoises pen width is greater than 4, then --#17 - // Reset it to 1 --#16 + if (Tortoise.getPenWidth() > 4) + { + // Reset it to 1 --#16 + Tortoise.setPenWidth(1); + } // ------------- End of adjustPen recipe --#9.3 + } + private static void createColorPalette() + { + // createColorPalette (recipe below) --#8.1 // - // The current length of a side is the same as the number of the side you are about to draw ( 1st side = 1 pixel, 2nd side = 2 pixels, etc) --#4.2 - // Move the tortoise the length of a side --#4.1 - // Turn the tortoise 1/5th of 360 degrees --#1 - // Turn the tortoise 1 more degree --#5 - // Repeat --#2.2 - // ------------- End of drawPentagon recipe --#10.3 + // ------------- Recipe for createColorPalette --#8.2 + // Add steel blue to the color wheel --#7 + ColorWheel.addColor(Blues.SteelBlue); + // Add dark orchid to the color wheel --#11 + ColorWheel.addColor(Purples.DarkOrchid); + // Add dark slate blue to the color wheel --#12 + ColorWheel.addColor(Blues.DarkSlateBlue); + // Add teal to the color wheel --#13 + ColorWheel.addColor(Blues.Teal); + // Add indigo to the color wheel --#14 + ColorWheel.addColor(Purples.Indigo); + // ------------- End of createColorPalette recipe --#8.3 } }