Skip to content

Commit cda6492

Browse files
committed
Added demo recipe w/Jim
drawShape
1 parent 3fcfe93 commit cda6492

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

src/main/java/org/teachingextensions/logo/Tortoise.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import org.teachingextensions.logo.Turtle.Animals;
66
import org.teachingextensions.logo.utils.TortoiseUtils;
7+
import org.teachingextensions.virtualproctor.VirtualProctor;
78

89
/**
910
* <img src="https://lh5.googleusercontent.com/-B3Q59gpYW8o/T4tA2k_TYUI/AAAAAAAAAjo/WiqdoXjbkb0/s65/Tortoise.png" style="text-align: left" alt="A tortoise drawing a line" >
@@ -288,4 +289,31 @@ public void likesTopping(Topping topping)
288289
{
289290
this.topping = topping;
290291
}
292+
/**
293+
* Makes a cool shape fast
294+
* <div><b>Example: </b> {@code tortoise.drawShape(6,PenColors.Reds.Red, 50, 20)}</div>
295+
* @param sides
296+
* the number of sides
297+
* @param color
298+
* a snazzy line color
299+
* @param length
300+
* the bigger the better
301+
* @param width
302+
* make a thick line - it's cool
303+
*/
304+
public static void drawShape(int sides, Color color, int length, int width)
305+
{
306+
Tortoise.show();
307+
Tortoise.setSpeed(10);
308+
Tortoise.getBackgroundWindow().setBackground(PenColors.Yellows.Goldenrod);
309+
for (int i = 0; i < sides; i++)
310+
{
311+
Tortoise.setPenColor(color);
312+
Tortoise.setPenWidth(width);
313+
Tortoise.move(length);
314+
Tortoise.turn(360 / sides);
315+
}
316+
VirtualProctor.setClassName("Snape's class");
317+
VirtualProctor.setName("Harry Potter");
318+
}
291319
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.teachingkidsprogramming.recipes.completed.section00demos;
2+
3+
import java.awt.Color;
4+
import java.util.Random;
5+
6+
import org.teachingextensions.logo.PenColors;
7+
import org.teachingextensions.logo.Tortoise;
8+
9+
public class QuickSquare
10+
{
11+
public static void main(String[] args) throws Exception
12+
{
13+
Random r = new Random();
14+
int sides = r.nextInt(10) + 1;
15+
Color color = PenColors.Reds.Red;
16+
int length = 50;
17+
int width = 20;
18+
Tortoise.drawShape(sides, color, length, width);
19+
}
20+
}

0 commit comments

Comments
 (0)