Goals

  • Learn about the Mandelbrot set and fractals.

  • Use functions and arrays.

  • Learn about PostScript.

  • Write a program that produces another program.

  • OS Tip of the Week

    Use the more command to view the contents of a file.

  • To quickly see the contents of a file from the command line one screenful at a time, type:
    more mand16.txt
    

  • The more command is extremely useful in conjunction with piping to view the output of your program one screenful at a time:
    a.out | more
    
    Piping can also be combined with redirection of standard input:
    mandcolor < mand16.txt | more
    
  • This works on all of the supported operating systems (Unix, OS X, Windows). If your system does not have the more command, try the less command instead.
    Input Format

    The input file begins with an integer n, followed by four real values: xmin, ymin, width, and height 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 the last 768 values for the part of the assignment that deals with the grayscale image.) For example, the file mand4.txt is:

    4
    -1.5
    -1.0
     2.0
     2.0
    0.000 0.000 0.734
    0.000 0.300 0.734
    . . .
    0.000 0.000 0.000
    
    If you use scanf() it won't matter whether the numbers are on the same line or not.


    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 ftp://ftp.cs.princeton.edu/pub/cs126/mandel/.

  • On arizona, you may use the programs mandgray126 and mandcolor126 to check your programs against our reference solutions. For Windows, you may use mandgray126.exe and mandcolor126.exe.

  • 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 peeking.

  • The file 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. This may be a useful starting point.

  • Compilation

  • Compile your program with "gcc126 mandgray.c" or "lcc126 mandgray.c". To read input from the file mand4.txt and send the output to the file mandgray4.ps, use the command:
    Unix:   a.out < mand4.txt > mandgray4.ps
    DOS:    mandgray.exe < mand4.txt > mandgray4.ps
    
    Do not use C file functoins like fopen().

  • Now, you can view the PostScript program with the command:
    gs mandgray4.ps
    
    Well, that works from a Unix or Linux machine (unless you're in a telnet session). Windows and OS X users need to download a PostScript viewer. Then to view the PostScript file, launch the application, and use File -> Open.

  • Do not print any PostScript file unless it views properly. You could get an endless stream of gibberish.

  • Submission and readme

  • If your program doesn't produce valid PostScript (e.g., it doesn't view and print properly), then rename your files to mandgray-bad.c or mandcolor-bad.c. Otherwise your grader may waste paper and effort trying to print the output. You will receive a deduction of up to 20 points if you don't follow these instructions.

  • Submit the files mandgray.c, mandcolor.c, and readme.txt using
    http://courseinfo.cs.princeton.edu
    
    as usual. Do not use different file names. Do not submit a.out. Do not submit PostScript files.

  • If you choose to submit the extra credit, submit only the input file, and give it a suggestive name, e.g., purple-seahorse256.txt.

  • The readme file should contain

  • Name, precept number.

  • High level description of code as specified in the readme.txt template.

  • 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, a Mandelbrot applet, 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