CS 171 & 171L Introduction to Computer Science I & Lab Fall 2017 

Lab: Fractals

In this lab, you will explore using fractal graphics. We will use Processing for this lab.

1. Introductions

Introduce yourself to your lab partner. Tell your partner about your plans for Thanksgiving break.

Circles

Implement the circles program from Nature of Code: Chapter 8, essentially recreating what we did in class on Friday. Put this in a program called Fractals.

Use two, then four recursive calls.

Customize this in a fun way by Replacing the circles with the either of following: squares, triangles, non-circular ellipises. Use stroke and fill colors; use the radius as a way to set these for additional fun.

Show and demonstrate your code when complete.

2. Sierpinski carpet

Implement code to create the Sierpinski carpet. Do this in the same code, just commenting out the initial call to drawCircles.

Start by drawing a square, then recursively drawing the middle square in a contrasting color. You will need 8 recursive calls! Use the processing translate and scale functions. Don't forget to reset the translation and scaling when done.

Show and demonstrate your code when complete.

3. Fractal Tree

Read over section 8.5 in The Nature of Code. This explains fractal trees and contains code segments. Implement the code in the book to draw a fractal tree. Do this in the same code, just commenting out the initial call to the other functions.

Set the strokeWeight to be based on the length of the line drawn.

Show and demonstrate your tree when complete.

3. Fractal Fern

Read over section 8.5 in The Nature of Code. This explains fractal trees and contains code segments. Implement the code in the book to draw a fractal tree. Do this in the same code, just commenting out the initial call to the other functions.

Starting with the code we worked on in class, implement code to create a fractal fern.

Start by drawing a line, then recursively and drawing ferns as branches along the line and also at the end of the line. Repeat until the line segment is about 2 to 3 pixels. Consider drawing green leaves at the base case. Use the processing translate and scale functions. Don't forget to reset the translation and scaling when done.

Use random values of line lengths, scaling, and rotational angles to create more realistic looking ferns.

Show and demonstrate your code when complete.

3. Wrap-up

Email a copy of the .pde code your instructor and to your lab partner(s).


Copyright © 2017, David A. Reimann. All rights reserved.