Due Date:
POSTPONED: Tuesday, Nov 30 at 9am.
The main goals of this lab are to:
Trigonometry: In class, we will do a quick review of trigonometry. An overview is also given online. Open up Processing and paste in the code that is given at the bottom of this link. Run the program, paying close attention to how the animation relates to the sine function.
Program 1: Trig Function Example #1 - Plot angle along x-axis. | |
|
![]() |
Program 2: Trig Function Example #2 - Plot in polar coordinates. | |
| ![]() |
Program 3: Trig Function Example #3 - Setting the color using the amplitude | |
| ![]() |
The program below is similar to Program 3 except that it allows of you to change the frequency interactively (press the 'a' or 's' key).
Program 4: Trig Function Example #4 - Setting the color using the amplitude interactively |
|
Computing Complex Numbers by Hand: In class, we will go over the origin, definition, and operations of complex numbers. Once you are comfortable with the concepts, work through the following problems: Complex Number Problems (pdf).
The solutions can be found here (pdf) but it is important that you try to do these without first looking at the solutions!
Computing Complex Numbers by Computer - using Classes
In class we will go over the notation for creating a complex number using the class defined below. Create a new Processing program, and copy Program 5 into it. Next, create a new tab (see Lab 3 if you forgot how to do this) and copy the code below given in Program 6 in this new tab. Some of the functions are not implemented. We will do these in class.
To test your understanding of the notation, fill in the missing sections and then try to reproduce the results for problem 5 in the written exercises.
Program 5: Setup for using the Complex Class |
|
Program 6: Complex Number Class |
|
The Mandelbrot Set: Below is the code for drawing the Mandelbrot Set. Some sections are missing. You also need to add the tab for the Complex Number class. We will go over in class what needs to be put in these sections. When completed, the code should give the image on the right.
Program 7: The Mandelbrot Set | |
| ![]() |
Changing the region: The region of the complex plane that is drawn is given by minX,maxX, minY, and maxY. You can change these to zoom into specific regions of the plane. Try changing these values.
Setting the color: Remember that k varies from 0 to max=100. If the iteration converges (i.e. the length never exceeds 2), then we will have k=100. This corresponds to the white region. The black region corresponds to where the iteration blows up. The value of k is a measure of how fast it blows up (and so k will be less than 100). To get a range of colors in this region, modify the if-statement to include more values of k. For example, we can get three colors as follows:
|
One can also use the final length of z to set the color. Experiment with changing colors and regions as was done here:
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
Barnsley Fern: Iterated function systems are another approach to using iteration to generate images. We will not go into the mathematical foundations for this, although it is based on a similar idea as for the Mandelbrot set, namely, iterating on some function. The Barnsley Fern is a well known example of this. Try running the code below.
Program 8: The Barnsley Fern | |
| ![]() |
One can use an array to keep track of how many times the iteration lands on a given pixel. This count can then be used to set the stroke color. The result is shown below as the number of iterations is increased.
![]() |
![]() |
![]() |
![]() |
Another example of an iterated function system is shown below. It iterates on complex numbers. Copy the program below into a Processing sketch. You will need to add a new tab for the complex number class from above (Program 6).
Program 9: Iterated Function System using Complex Numbers | |
| ![]() |
Below are sample images as the number of iterations is increased.
![]() |
![]() |
![]() |
![]() |
As in previous labs, zip together your entire sketch folder containing a single Mandelbrot sketch containing multiple setColor functions for setting the color. Include in the folder at least 4 different images (e.g. png files) that you obtained by varying the region and the color function. Add the zip file as an attachment in WISE. Please don't forget to follow the steps below for cleaning up your code. Clean, well commented, and easy to understand code is very important.
Follow the directions from previous labs for preparing the files for submitting to WISE.
By 9am of Tuesday, Nov 30, submit the single zipped file via WISE as an attachment.