Lecture 6 (Sherriff) - Turtles Part 2

Lecture Date: Monday, January 26

First, let’s make sure you have the code we ended with on Friday:

TurtleDrawing.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.awt.Color;

public class TurtleDrawing {

  public static void main(String[] args) {

      World myWorld = new World();
      Turtle bob = new Turtle(myWorld);

      drawShape(bob, 20, 20, 40, Color.BLUE, 5);
      drawShape(bob, 100, 100, 150, Color.GREEN, 3);
      drawShape(bob, 100, 100, 150, Color.RED, 8);

  }

  public static void drawShape(Turtle bob, int x, int y, int size, Color c, int sides) {
      bob.pickPenUp();
      bob.goTo(x, y);
      bob.putPenDown();
      bob.setColor(c);
      for (int i = 0; i < sides; i++) {
          bob.forward(size);
          bob.right(360/sides);
          System.out.println("i = " + i);
      }

  }

}

Now, today, we’re going to add a bit more excitement!

We’ll add:

  • random colors
  • user input
  • how to draw a circle
  • saving our pictures
  • how to draw a tree

Code from today: * TurtleDrawing.java * Tree.java * AdvancedTree.java