ulrail.gif

Homework 3

  ur-2c.gif urrail.gif
blrail-nonavbar.gif

Home | Resources | Assignments | Exams
Lectures | Course Staff | Submit

br-2a.gif   br-2c.gif brrail.gif
spacer.gif

spacer.gif

Due: 11:59 PM, Tuesday, September 25th

Purpose

The goal of this assignment is to use a simple recursive procedure to create complex graphics.

Before Lab

Read this document carefully, and make sure you have read up to and including chapter 2.3 in your textbook.

In Lab

From the CS101 resources page, download FunctionalAbstraction.java and SimpleRecursion.java and, starting with the first one, follow the directions in the embedded comments. At the end of this lab, submit the modified versions of these files that you produce.

Post Lab

Part 1: Sierpinski triangle

Write a program that plots a Sierpinski triangle, as illustrated below.

Sierpinski triangle of order 9
The Sierpinski triangle is another example of a fractal pattern like the H-tree from Section 2.3. The pattern was described by Polish mathematician Waclaw Sierpinski in 1915, but has appeared in Italian art since the 13th century. Though the Sierpinski triangle looks complex, it can be generated with a short recursive program. Your task is to write a program Sierpinski.java with a recursive function sierpinski() and a main() function that calls the recursive function once, and plots the results using standard draw. Think recursively: your function should draw one black triangle (pointed downwards) and then call itself recursively 3 times (with an appropriate stopping condition). Also, when writing your program, exercise good design: include a (non-recursive) function triangle() that draws an equilateral triangle of a specified size at a specified location.

Your program will read in a command line parameter N to control the depth of the recursion. First, make sure that your program draws a single black triangle when N is set to 1. Then, check that it draws four black triangles when N is set to 2. Your program will be nearly (or completely) debugged when you get to this point. Below are the target Sierpinski triangles with N set to 1, 2, 3, 4, 5 and 6, respectively.

   Sierpinski triangle of order 1 Sierpinski triangle of order 2 Sierpinski triangle of order 3
   Sierpinski triangle of order 4 Sierpinski triangle of order 5 Sierpinski triangle of order 6

Part 2: Be creative

In this part you will design and create your own recursive fractal. Your job is to write a program Art.java that takes a command line parameter N that controls the depth of recursion (typical values between 0 and 7) and produces a recursive pattern of your own choosing. You are free to choose a geometric pattern (like Htree or Sierpinski) or a random construction (like Brownian). Originality and creativity in the design will be a factor in your grade.

Submission

Go to the CS101 submission page and follow the instructions provided.

spacer.gif
spacer.gif footer-middle.gif spacer.gif