Can Computers Think?
Introduction to Computer Science

CSC 106
Union College
Winter 2010

In class exercises for Thursday, 2/18

Purpose:

Helpful Link

The documentation of the turtle module.

Problem 1: A turtle spiral

Write a recursive function that makes the turtle draw a square spiral shape. For example like this:

a turtle spiral

The function should take a number as its parameter that indicates how many layers the spiral should have. For example, spiral(1) should produce this image spiral of degree 1 spiral(2) should produce this image spiral of degree 2 and spiral(7) should produce this image a turtle spiral

Problem 2: The Koch snowflake

A Koch curve is a recursive structure that is built as follows:

Koch curve of degree 0:koch curve of degree 0
Koch curve of degree 1:koch curve of degree 1
Koch curve of degree 2:koch curve of degree 2
Koch curve of degree 3:koch curve of degree 3

You can build a snowflake shape by arranging three Koch curves in a triangle.

Koch snowflake

Step 1: Koch curve

Write a recursive function that draws a Koch curve. The function should take a number as its parameter that indicates the degree of the Koch curve.

Step 2: Koch snowflake

Write a function that makes the turtle draw a Koch snowflake. This function should also take one parameter indicating the degree of the three Koch curves. This function should make use of (i.e., call) the function for drawing a Koch curve that you defined in Step 1.