# Day 6

## Mini Project 1

Debrief from first half

Due Thursday before class. Don’t hesitate to reach out for help via office hours and Canvas discussion.

## Reading Journal Review

Pair with someone who did at least one of the exercises that you didn’t do from section 4.12. First, discuss your approaches to exercises 1-4 in Chapter 4.3. Make sure to clear up any misconceptions that you may have. Finally, discuss the approaches taken in the book to refactor the code. Make sure that you are clear on the advantages of the refactored code.

Now, turn your attention to the exercises in 4.12. Take turns presenting one partner’s solution to one of the problems that the other partner didn’t attempt. Try to get across both your high-level approach to the problem as well as your specific implementation in Python. If you have any suggestions for code improvements that your partner code make, feel free to suggest them, but be sure to deliver this feedback in a constructive manner.

## More Fun with Turtles

Take your turtles to the next level! There are a bunch of ways you might do this.

### Continue with Think Python

You can continue to work through the exercises in 4.12 of Think Python, there’s a lot of good stuff there.

### Freestyle

Find a cool line drawing and try to replicate it with Python code!

### Draw Parametric Curves

A parametric curve in 2D is defined by two functions, $x(t)$ and $y(t)$ (where $t$ is some parameter, which we can think of as time). If we imagine our turtle traveling along this curve, we can use calculus to compute various properties of our turtle’s motion. For instance, the speed of the turtle can be calculated as follows.

Further you can calculate, your turtle’s heading as follows.

Using these ideas you can program your turtle to draw arbitrary parametric curves. Suppose we want our turtle to draw a sine wave with amplitude of 10 pixels and a period of $20\pi$ pixels. This path can be defined as follows.

Additionally, the heading and speed functions are defined as follows.

Challenge: write a Python program that takes as input a parametric curve and uses the turtle module to draw it.

Hint: the method presented above to compute the turtle’s heading has some numerical issues (e.g., when $y'(t) = 0$). A better way to compute the heading is using the math.atan2 function. Suppose we have computed $x'(t)$ and stored it in a variable dx and we have computed $y'(t)$ and stored it in a variable dy, the heading (in radians) can be computed as math.atan2(dy, dx).

Once you can draw a parametric curve, you can draw some really cool stuff like Spirographs!