Monday, September 20, 2010

Recursion

I know, it has been a while since I have posted, but I have been busy and there has not been anything besides classes going on - nothing post-worthy.  Until now.  I have been working on some recursion projects for my Computer Science class which explores the idea of recursion while using turtle (a part of python for drawing).

It has been a good deal of work, but it was also a lot of fun to come up with the successful and enjoyable images.  First, we were supposed to make a recursive tree.  This tree would create forks at the end of each branch until the levels of conversion were complete.  The finished project looked like this:

This image was created by calling svTree(200,4) where 200 is the length of the first trunk and 4 is the number of recursive steps.  The "turtle" is the triangle at the location where it started.


For extra credit, we could take this part of the project a step further, by creating a recursive tree that we chose to "spruce up" and "fir"nish with clear and useful instructions (the puns are those of my teacher, but they were not lost on me).  While my time was completely abundant, I was intrigued by the idea of creating something a little more fun, and in the short amount of time I spent working/thinking about it, I came up with this:

Called using the same parameters: svTreeExtra(200,4,pink) - where pink is choosing a color for the flowers.  Again, you can see the "turtle" at the base of the tree, right where it belongs.
The final recursive turtle project was also one that was pretty interesting.  We were asked to write the code to create a Koch Snowflake, which - depending on the number of recursive calls - has a point for the center third of each side as seen here:

The format for these calls is snowflake(sideLength,levels).  The upper left is snowflake(100,0), the upper right is snowflake(100,1), the lower left is snowflake(100,2), and the lower right is snowflake(100,3) with the "turtle" in the center.

It was a lot of work to get each function running properly, but in the end, the results were very cool and I enjoyed working on all of them.  The unfortunate news is that I spent a good deal of time playing with the extra credit, and still have homework to do.  So, I should maybe do some of it now.  Or tomorrow, we'll see.

1 comment:

  1. Hi Jane, That looked like a fun project, hope all is going well, see you soon. Love, Grandma

    ReplyDelete