CMP 160 -- Programming Assignment 1
Due date:
10:00am, THUR, 4/5/01
Objectives:
Warm up program to take care of any technical
difficulties, administrative issues, etc. that
you might run into. Also introduces OpenGL and fltk.
Understand coordinate system of OpenGL,
and how to draw colored points.
To Do:
-
Write a program that draws ``Mandelbrot Sets'' using OpenGL
and with an fltk interface.
You can do this task in stages.
-
Stage 1:
Experiment with the Sierpinski code in chapter 2 of our text.
Copy, compile, run it on your favorite platform.
-
Stage 2:
Modify the interface of this program.
That is, remove the glut portion and replace with fltk.
For this, study the
simple
example.
You may want to add a "quit" button,
or other program interfaces (see Stage 3).
If you're using the machines in 105BE,
they should already be set up.
Note that you will probably need to change the makefile
from the simple directory.
If you're using a home pc,
there's a PC.README file detailing how
to download, install, write/run code using fltk.
-
Stage 3:
Modify the graphics portion of this program
so that it draws mandelbrot sets instead of Sierpinski curves.
-
Mandelbrot Set.
Generate 2D sets and map each point to a color value.
Here is an example:
Here's how you calculate them
(from The Beauty of Fractals, Peitgen & Richter, page. 191):
-
Input consists of the domain of the Mandelbrot set
to be investigated:
left, right, bottom, and top
-
Assume that the viewport (the OpenGL where the drawing
will go to) has
xdimension by ydimension pixels.
-
Your program will calculate a color value for
each of the xdimension by ydimension points.
A color value is represented as an integer index to
a color table.
Assume that there are K color values ranging from 0 .. K-1.
Let K = 256.
All calculations are done with floats and then
converted to integer.
-
Consider the complex feedback process z => z*z + c.
Decompose the complex numbers z and c into their real and imaginary parts,
z = x + iy, c = p + iq.
The process is then described by a law of the form:
x(k+1) = x(k) * x(k) - y(k) * y(k) + p(k),
y(k+1) = 2 * x(k) * y(k) + q(k).
This means that the x and y values at the (k+1)st iteration
are obtained from the x, y, p, and q values at the (k)th iteration.
-
Set pmin = left, pmax = right, qmin = bottom, qmax = top, M = 100.
pmin, pmax, qmin, and qmax specify a rectangular region of the
Mandelbrot set to be explored.
These are also the range of values to be used for the p and q term used
in the iteration equation above.
M is used as a variable to decide termination.
Also set delta_p = (pmax-pmin)/(xdimension-1),
delta_q = (qmax-qmin)/(ydimension-1).
If you map the rectangular region specified by pmin, pmax, qmin, qmax
to the xdimension x ydimension image, then
delta_p and delta_q specify how p and q are incremented
as you fill in each point of the image.
-
For all points (np, nq) of the viewport
(np = 0, .., xdimension-1), (nq = 0, .., ydimension-1)
go through the following routine:
-
Set p0 = pmin + np * delta_p, q0 = qmin + nq * delta_q,
k = 0, x0 = y0 = 0
(i.e. when k = 0,
x(k) = x0 = 0, y(k) = y0 = 0, p(0) = p0, q(0) = q0).
-
Calculate the new values, x(k+1) and y(k+1), using the equation above.
Note that both p and q remain the same throughout, while x and y
change in each iteration.
Set k = k+1.
-
Calculate r = x(k)*x(k) + y(k)*y(k).
Note that these are with the new, updated values of x and y.
Variable r is like a square-distance term for the point x+iy
from the origin of the complex plane.
-
if r>M, then assign color k to point (np, nq)
and go on to the next point.
-
if k=K, then assign color 0 to point (np, nq)
and go on to the next point.
-
if r <= M and k < K, repeat step 2 in this routine
(i.e. recalculate x(k+1), y(k+1)).
-
Color.
The ``color'' value that you calculated is actually an
index to a color table. You'll have to create your
own K-entry color table.
Each entry of the color table will specify some mix
of red, green and blue (RGB) components.
If you don't know any better, assign the color values to
gray shades from black to while as the index goes up.
Gray shades have equal RGB components.
Alternatively, you can try random colors,
though they don't look too good in general.
Experiment with different variations.
-
Here are some other interesting parameters.
Try the following coordinates, and experiment with your own too!
Left |
Right |
Bottom |
Top |
-2.25 |
0.75 |
-1.5 |
1.5 |
-0.19920 |
-0.12954 |
1.0148 |
1.06707 |
-0.95 |
-0.88333 |
0.23333 |
0.3 |
-0.713 |
-0.4082 |
0.49216 |
0.71429 |
-1.781 |
-1.764 |
0.0 |
0.013 |
-0.75104 |
-0.7408 |
0.10511 |
0.11536 |
-0.746541 |
-0.746378 |
0.107574 |
0.0107678 |
-0.74591 |
-0.74448 |
0.11196 |
0.11339 |
-0.745538 |
-0.745054 |
0.112881 |
0.113236 |
-0.745468 |
-0.745385 |
0.112979 |
0.113039 |
-0.7454356 |
-0.7454215 |
0.1130037 |
0.1130139 |
-0.7454301 |
-0.7454289 |
0.1130076 |
0.1130085 |
-
Extra Stuff.
Here are some things that you may want to add to your program.
-
Allow image to be saved.
-
Allow different color tables to be used
(perhaps from pre-generated options).
-
Allow user to specify the Mandelbrot domain graphically
rather than entering the bounds numerically.
Imagine a rubber band bounding box that the user places
over the current viewport -- this is like a ``zooming'' effect.
-
Grading.
We must be able to compile/test your code.
Currently, the most convenient setup is to do this on the Suns.
(We may be able to expand the platforms in the future
if we get additional manpower.)
So, before you submit your program,
make sure that it compiles and runs fine on the Suns.
-
Submission.
Submission must be done using the submit or xsubmit utility from CATS.
Run "quickhelp submit" on a CATS machine to find out more info.
Create and submit a subdirectory called "prog1". It should
contain all the files you have in make your program compile/run.
Remember that 20% of the grade is towards documentation/readability/style.
Last modified
Wednesday, 28-Mar-2001 22:30:12 PST.