Goals

  • Learn about the Mandelbrot set and fractals.

  • Use functions and arrays.

  • Learn about Unix and PostScript.

  • Write a program that produces another program.

  • Unix tip of the week

  • emacs and xemacs have many built-in features especially for writing C code.

  • Displays line number in the bottom of the window.

  • Automatically indents each new line of C code. Use the Tab key to indent old lines of code.

  • Syntax highlighting and colors in xemacs.

  • Auto-compile with "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. If you are working from home, you can use Ctrl-x o to switch to the other pane, and "Ctrl-x 1" to return to a single pane.)

  • Find next syntax error with "Ctrl-c Ctrl-n".

  • Input Format

    The input file begins with an integer n, followed by four real values: xmin, ymin, xmax, and ymax in this order. It is followed by a 256-by-3 table of real-valued color gradations. (There is no need to even read in these 768 values for the grayscale image.) For example, the file mand4.txt is:

    4
    -1.5 -1.0 0.5 1.0
    0.000 0.000 0.734
    0.000 0.300 0.734
    . . .
    0.000 0.000 0.000
    


    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

  • Run your program on some of the data files in /u/cs126/files/mandel/.

  • You may use the programs mandgray126 and mandcolor126 to check your programs 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 by not peaking.

  • The file /u/cs126/files/mandel/test.c is an example of a C program that produces a PostScript program. It produces the sample PostScript program in the assignment by a series of printf() statements.

  • 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:
    submit126 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 help that you received (including using the hints link).

  • 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.
  • Here's a readme file template.


  • 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