Goals

  • Learn about the Mandelbrot set and fractals.

  • Use functions, arrays, and structs.

  • Learn about Unix and PostScript.

  • Write a program that produces another program.

  • Unix tip of the week

  • Emacs has many built-in features especially for writing C code. The file .emacs can be used to customize emacs in many ways. We provide a simple version that adds several useful features. To copy our .emacs file, type
    cp /u/cs126/.emacs ~
    
    Note that you only need to do this one time, not each time you login. This will enable the following 5 features:

  • The line number and time are displayed at the bottom of the emacs window.

  • Emacs will automatically and consistently indent each line of C code. You can also use the Tab key to auto-indent.

  • If you use xemacs, you will be rewarded by pretty colors.

  • You can compile your code from within emacs by typing "Ctrl-c Ctrl-c". At this point you can edit the compilation command, or type Enter to compile. (This will create two window panes, one for the program, and one for the compiler messages. To return to a single pane, type "Ctrl-x 1".) The compilation command uses gcc with several "flags":
    gcc -Wall -W -O -ansi -pedantic
    
    These options turnd on most compiler diagnostic messages. These warnings should be used to help you debug your code.

  • If there are syntax errors, type "Ctrl-c Ctrl-n" to jump to the next error.
  • To see the size of your files use the command ls with the -l flag (long format).
    % ls -l
    -rwx------   1 wayne        6944 Feb 11 13:46 a.out
    -rw-r--r--   1 wayne         134 Feb 10 11:25 input.c
    -rw-------   1 wayne         887 Feb 10 11:25 invest.c
    -rw-------   1 wayne         680 Feb 10 11:28 pattern.c
    -rw-------   1 wayne         215 Feb 10 16:42 plot.c
    -rw-------   1 wayne          17 Feb 10 11:38 readme
    
    In this example input.c is a 134-byte file that was last modified on February 10. It is world readable, but can only be modified by the owner wayne. File invest.c can only be read/written by the owner wayne. File a.out is an executable file.

  • Grading

  • Mandelbrot function: 5 points.

  • Gray-scale image: 5 points.

  • Color image: 5 points.

  • Submission, readme, and style: 5 points.

  • Checking Your Work and Hints

  • Here is the correct sequence of Mandelbrot iterates for the point (0.125, 0.750). Your function should return 6, not 5 or 7.

    # 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

  • You may use the programs /u/cs126/bin/mandcolor and /u/cs126/bin/mandgray to check your program against our reference solutions.

  • Step-by-step instructions for getting started and additional hints are available here. If you are new to program and/or are struggling, this may be the best place to start. If you have some programming experienced you are probably better off my not peaking.

  • Compilation

  • Compile your program with "gcc mandgray.c" or preferably "gcc126 mandgray.c". To redirect the file mand4.txt as input and redirect the output to the file mandgray4.ps, use the command:
    a.out < mand4.txt > mandgray4.ps
    
    Now, you can view the PostScript program with the command:
    gs mandgray4.ps
    
    Note that the gs command will not work from a telnet session.

  • Do not print any PostScript file unless it views properly with gs.

  • Submission and readme

  • If your program doesn't produce valid PostScript (i.e., they don't view or print properly), then rename your files as mandgray-bad.c or mandcolor-bad.c. Otherwise your grader may waste paper and effort trying to print the output. You will receive a grade of 0 on this assignment if you don't follow these instructions.

  • Use the following submit command:
    /u/cs126/bin/submit 2 readme mandgray.c mandcolor.c
    
    Do not use different file names. Do not submit a.out. Do not submit PostScript files.

  • The readme file should contain

  • Name, precept number.

  • High level description of code.

  • Describe any serious problems you encountered. List whatever outside help that you received.

  • Do not include PostScript output in the readme file.

  • Use at most 80 characters per line to ensure that your grader can view it properly.

  • Enrichment Links

  • There is a huge amount of information on the Web about fractals, including a Mandelbrot tutorial, Mandelbrot explorer, and a Mandelbrot generator.

  • Check out the PostScript section of the COS 126 FAQ List for more information on PostScript (although you shouldn't need much more info for this assignment). It includes a link to download a PostScript viewer for your PC or Mac.



  • Kevin Wayne