CSCI 250
Project 3
For this project, you are to
produce the image of a Julia set. We are
going to iterate f(z) = z2 + c where c is a constant that determines
which Julia set we are producing. We take the output of the function and feed
it back as input and see if the function values are bounded or not. The color chosen indicates the boundedness
after iterating 1000 times. Black goes
to infinity, green indicates bounded.
Now the value z is a complex
number, so we need to use complex arithmetic.
C++ has complex arithmetic in the library, but for practice, I want you
to implement your own complex arithmetic class.
It should include the four basic operations, +, -, *, and /. In case you forgot, a complex number has 2
parts, the real and the imaginary.
Arithmetic is done as follows:
You should also have a default
constructor and one that takes a real and converts it to a complex number, and
one that takes two reals and creates a complex number, as well as I/O routines
for complex numbers.
Your program should scan across
the screen and for every pixel (x,y),
should construct the corresponding complex number z = x+yi. You should iterate
where c is a predefined
constant. I used 0.244325 – 0.0602826i. Do this for 1000 times or until the magnitude
squared (x2 + y2) is bigger than 4. If you get 1000 iterations, color it your
favorite color: otherwise color it black. Do a glFlush() to get the image to the screen and enjoy!
Below is a sample I created:
Since the points were so small they didn’t show
up, I drew a polygon for each point (glBegin(GL_POLYGONS)), going in counterclockwise order (x,y), (x+0.001, y), (x+0.001, y+0.001), (x, y+0.001). This made a “point” big enough to see.
Also, the default screen coordinates run from
(-1, -1) to (1,1), so your loop should be restricted to that range.
Try different values of c and see how the shape
changes.