Due Date:
Work should be submitted via WISE Monday, April 12, 2010 before the beginning of class.
While Loops: The while-loop is a more general type of loop than the for-loop (a for-loop can always be replaced by a while-loop but not vice versa). There are actually two versions: "while" and the "do-while":
"while": the condition is checked at the beginning. The statements in the body execute 0 or more times.
|
|
Any for-loop can be written as a while-loop. For example: the following for-loop
|
|
While loops are useful when one doesn't know ahead of time how many times the loop will execute, e.g.
|
The code below prints a list of increasingly larger positive numbers until 1000 is reached.
|
In class, we will go over how the Mandebrot set is generated by iterating on the complex numbers z = z2 + c, starting at z=0. If the length of z goes above 2, the iteration is stopped, otherwise it is continued until 100 iterations have been executed. The color of a pixel is based on the number of iterations.
The code structure is given below:
|
Finish implementing the above code. The setColor function given above will generate the mandelbrot in black and white, as shown here:
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 interation 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:
![]() |
|
Once can also use the final length of z to set the color. Experiment with changing colors and regions as was done here:
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
Monday, April 12, before class:
You are to turn in via Wise a single zipped file containing your Processing sketch for the mandelbrot set. Include 3 images, each using a different region and/or coloring mapping.
Before turning in any of your code, make sure that you have cleaned it up!