Sunday, 2 February 2014

Week 4: Turtle Recursion

This week in class, we delve into Turtles. Not per-say the animal known as a turtles, but the python library known as turtle. With turtle we talk about recursion, the act of calling itself, possibly creating an infinite amount of calls. We use turtles to represent lines or vectors on a window and use recursion to create new paths and split offs from eachother on each call of the turtle to move. On each call, the turtles moves a shorter distance and a new angle. Eventually, with all the paths of the turtles, we start to create a shape that represents a Sierpinski triangle, a fractal shape. With this turtle introduction, we finally reach the topic of recursion.

Ahh yes, recursion. A call within a call within a call, etc. What a tricky topic. Even though I learned recursion a few years ago, I still have trouble with it to this very day. Making sure you don't have infinite recursion is something you always need to do. A way to do this is with a base case. A base case is a circumstance in which the function doesn't call itself. Such as having it call itself if a variable known as X is above a certain value, and on each repeated call, we decrease the value of X by one, so eventually X reaches below that threshold and it stops calling itself.

Because in class we speak of recursion, I can only imagine the upcoming topic of trees. While i can lie and say I'm excited for trees, I won't. I'll simply say in a sarcastic tone," Oh boy.... trees."

No comments:

Post a Comment