5.13. 🤔 Drawing a Circle with the Turtle

Suppose that we want our turtle to draw a circle, the circle should have a certain radius that the user can supply and then the turtle can draw one from the current location of the turtle.

Drawing a circle may sound like a real challenge, but here is another example of a problem solving exercise where you can start simple work out a few cases with paper and pencil in order to see the pattern. Once you see the pattern then you can generalize your solution.

To begin lets think of a simpler shape we can have the turtle draw such as a triangle, and since a radius doesn’t really make a lot of sense for a triangle lets suppose that the user supplies us with the length of the side for a triangle.

Ask the user for a side length and then draw a triangle.
Ask the user for a side length and then draw a square
Ask the user for a side length and then draw an octagon (8-sided)

Now there are a couple of jumps we need to make:

  1. Although we think of a circle as being perfectly round, we can’t really achieve that on a computer screen. So our circle will be an approximation of a circle. In fact you have probably already noticed that the octagon looks a lot more circle-ish than the triangle did. So we will approximate our turtle by making a polygon with a lot of sides.
  2. How did you figure out how far to make the turtle turn for the triangle, square, and octagon?

to make the leap to drawing our approximate circle we will need to figure out how many sides we need how long those sides should be and how much to turn. Depending on the order you answer the questions, you may get a different final program. Remember that you can always do a little experiementing to see what looks good, you don’t have to have the perfect answer on the first try, and its OK to use an assumption for one of the answers to the three questions.

Ask the user for a radius and then draw a circle with that radius.

Bonus

Ask the user for a radius and then draw a circle with that radius, but make the center of the circle at the current location of the turtle.

Post Project Questions

Next Section - 6. Sequences