CS 171 & 171L | Introduction to Computer Science I & Lab | Fall 2019 | |
Homework Assignment 6Starting pointDownload the source file Plotter.java. It contains a general 2D plotting function. Open it in jGRASP. It will not work in DrJava.
Using Processing Libraries from JavaYou will need to use jGRASP for this project and tell jGRASP to use the Processing libraries. See the video on how to do this. Once this is done, you should be able to compile and run the program above. Classes and MethodsYou will need your Complex.java class file with working complex addition, multiplication, and modulus. (10 points) Consider the function $f(z,c) = z^2 - c$ where $z$ and $c$ are both complex numbers. Write a java function named f which takes two complex numbers as parameters and returns a new complex number that is the square of the first minus the second. Let $c = 1 = 1 + 0i$ and $z = 0 = 0+0i$, then $f(z, c) = 0^2 - 1 = -1$. Let $c = 1$ and $z = -1 = -1+0i$, then $f(z, c) = (-1)^2 - 1 = 1 - 1 = 0$. Let $c = -1$ and $z = 0$, then $f(z, c) = (0)^2 - (-1) = 0 + 1 = 1$. Let $c = -1$ and $z = 1$, then $f(z, c) = (1)^2 - (-1) = 1 + 1 = 2$. Let $c = -1$ and $z = 2$, then $f(z, c) = (2)^2 - (-1) = 4 + 1 = 5$. (10 points) Write a function escape that takes three parameters, the first two (say $z$ and $c$) are complex and the third (say $m$) is an integer. The escape function, $E(z,c,m)$ computes $$z_0 = 0$$ $$z_1 = f(z_0,c)$$ $$z_2 = f(z_1,c)$$ $$...$$ $$z_n = f(z_{n-1},c)$$ Stop the iteration if either of the following happens:
Let $z=0$ and $c = -1$, then $E(0,c,255) = 255$ because the computed values of $f$ will be 0,-1,0,-1,0,-1,... Let $z=0$ and $c = 1$, then $E(0,c,255) = 3$ because the computed values of $f$ will be 0,1,2,5,...
Loop over a grid of points $c$ in the complex plane. Compute the escape function on each point.
Color the point in the image based on the escape value with the gray level.
Use the point() function to do this.
The resulting image should look similar to the image below.
(10 points extra credit) Consider two colors, C1 and C2, each with RGB compoents. Color the image using linear interpolation between these colors based on the escape function value. Copyright © 2019, David A. Reimann. All rights reserved. |