Goals
Write a program that produces another program.
Learn about the Mandelbrot set.
Use functions and arrays.
Learn about Unix and PostScript.
Checklist
You should use the following submit command:
/u/cs126/bin/submit 2 readme mandgray.c mandcolor.c mandgray32.ps mandcolor32.ps
. Do not use different file names. (Put each assignment in a different directory; that way you won't overwrite your old readme file. Ask a lab TA for assistance if you don't know how.) Do not submit
a.out
.
In precept we will discuss the Mandelbrot set and arrays.
If you haven't done so already, please fill out the
COS 126 student survey
. It will only take a minute. Otherwise your name will not get entered in our database, and you will not receive a grade in this course.
readme
Name, precept number.
Give high level description of code and indicate any problems you encountered.
Describe how much and what help (if any) you received from the lab TA's - be specific.
Do not include PostScript code in any readme file.
mandgray.c
Update the variables
r
and
s
simultaneously, using the
old
values of
r
and
s
- otherwise, your plot will look like a "squished" Mandelbrot set. As a check, the point (0.125, 0.75) is not in the set, since after the 6th iteration, r*r + s*s > 4.
#
0
1
2
3
4
5
6
r
0.125000
-0.421875
-0.575928
0.455010
-0.303564
-1.959975
3.945239
s
0.750000
0.937500
-0.041016
0.797244
1.475509
-0.145822
1.321613
Do not hardwire 32 into code. Use
#define N 32
and be sure that your code works properly if you change the value of N.
Rescale x and y coordinates appropriately, so that they are between 0 and 512.
Choose radius of circle as a function of N to display nicely.
To print a
%
sign, use
printf("%%");
executing
Redirect output into a file with "
a.out > picture.ps
".
View using "
gs picture.ps
". This will not work from a telnet session.
Do not print
any PostScript file unless it views properly with
gs
.
Experiment with a bigger value of
N
for more resolution, but if
N
is too big your output can easily grow to several gigabytes; be sure that the PostScript files you submit use N = 32.
mandcolor.c
The file
/u/cs126/data/color.map
contains a table of 256 color values, corresponding to iteration counts of 0-255.
Use an array of 256 3-float structures as indicated in the assignment to gain practice with compound data structures. (If using structs wasn't specifically asked for in the assignment you could use a 2-dimensional array instead.)
mandgray32.ps, mandcolor32.ps
The file you submit should have N = 32.
Under no circumstances should you ever submit or email us any file exceeding 1MB.
Enrichment Links
There is a huge amount of information on the Web about fractals, including a
Mandelbrot tutorial
and a
Mandelbrot explorer
.
Check out the course
Frequently Asked Questions
link. Many common questions are addressed here.
Kevin Wayne