|
| 1 | +package org.teachingkidsprogramming.recipes.completed.section04mastery; |
| 2 | + |
| 3 | +import java.awt.Color; |
| 4 | + |
| 5 | +import org.teachingextensions.logo.Tortoise; |
| 6 | +import org.teachingextensions.logo.utils.ColorUtils.ColorWheel; |
| 7 | +import org.teachingextensions.logo.utils.ColorUtils.PenColors; |
| 8 | + |
| 9 | +public class DigiFlower |
| 10 | +{ |
| 11 | + public static void main(String[] args) |
| 12 | + { |
| 13 | + // Show the tortoise --#1 |
| 14 | + Tortoise.show(); |
| 15 | + // Make the tortoise move as fast as possible --#7 |
| 16 | + Tortoise.setSpeed(10); |
| 17 | + // Make the background silver (use PenColors) --#8 |
| 18 | + Tortoise.getBackgroundWindow().setBackground(PenColors.Grays.Silver); |
| 19 | + // Make the line the tortoise draws 3 pixels wide --#15 |
| 20 | + Tortoise.setPenWidth(3); |
| 21 | + // CreateColorPalette (recipe below) --#9 |
| 22 | + createColorPalette(); |
| 23 | + // Do the following 15 times --#13 |
| 24 | + for (int i = 0; i < 15; i++) |
| 25 | + { |
| 26 | + // DrawOctogon (recipe below) --#10 |
| 27 | + drawOctogon(); |
| 28 | + // Turn the tortoise 1/15th of 360 degrees to the right --#12 |
| 29 | + Tortoise.turn(360.0 / 15); |
| 30 | + } |
| 31 | + } |
| 32 | + // ------------- Recipe for CreateColorPalette --#9 |
| 33 | + private static void createColorPalette() |
| 34 | + { |
| 35 | + Color color1 = PenColors.Reds.Red; |
| 36 | + Color color2 = PenColors.Oranges.DarkOrange; |
| 37 | + Color color3 = PenColors.Yellows.Gold; |
| 38 | + Color color4 = PenColors.Yellows.Yellow; |
| 39 | + ColorWheel.addColor(color1); |
| 40 | + ColorWheel.addColor(color2); |
| 41 | + ColorWheel.addColor(color3); |
| 42 | + ColorWheel.addColor(color4); |
| 43 | + ColorWheel.addColor(color4); |
| 44 | + ColorWheel.addColor(color3); |
| 45 | + ColorWheel.addColor(color2); |
| 46 | + ColorWheel.addColor(color1); |
| 47 | + // |
| 48 | + } |
| 49 | + // ------------- Recipe for DrawOctogon --#10 |
| 50 | + private static void drawOctogon() |
| 51 | + { |
| 52 | + // Do the following 8 times --#6 |
| 53 | + for (int i = 0; i < 8; i++) |
| 54 | + { |
| 55 | + // Change the pen color of the line the tortoise draws to the next color on the color wheel --#4 |
| 56 | + Tortoise.setPenColor(ColorWheel.getNextColor()); |
| 57 | + // Move the tortoise 50 pixels --#2 |
| 58 | + Tortoise.move(50); |
| 59 | + // Turn the tortoise 1/8th of 360 degrees to the right --#5 |
| 60 | + Tortoise.turn(360.0 / 8); |
| 61 | + } |
| 62 | + } |
| 63 | +} |
0 commit comments