Python Resources

Updated on Aug 4 2024

Python Resources

Deborah R. Fowler



Turtle Note

Posted on Sept 2  2018

While making examples for class I ran across an interesting note. Typically in computer graphics you can save the transformation "state" by pushing/popping the current state in a stack (OpenGL for example). The following problem resulted from generalizing the square to a rectangle and then creating a hat. Simple enough. But what if you wanted the hat tilted?

A better hat is show along with the original problem with lead to a really nice website on transformation matrices called academo.org

https://academo.org/demos/rotation-about-point/

First, let's set up the problem and then we will see how rotation about a point comes into play.

Suppose we take the square function and generalize it to rectangles:

MISSING IMAGE

We could make a hat by calling this function twice:

MISSING IMAGE

Now what if we wanted to tilt the hat? The problem show below is because our point needs to be rotated.

MISSING IMAGE

If we rotate the point using the formulas. Be sure to import math

MISSING IMAGE

Now we have a hat that is tilted. This is a good example of having some knowledge of mathematics.

We could also have draw the hat in a more brute force way. Since it is one continuous object, we do not head to worry about the orientation of the turtle.

MISSING IMAGE

Better to allow parameter controls
MISSING IMAGE

However, what if we wanted a colored band on our hat? We are back to the rotating a point. Perhaps not the most efficient, but an interesting example. Go ahead and create your own hat function.

MISSING IMAGE