Goals

  • Create graphics.

  • Learn about recursion.

  • Learn about the PostScript programming language (a stack-based language).

  • Unix tip of the week

    To see the sizes of your files, use the command ls with the -l flag (long format).

    phoenix.Princeton.EDU% 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     4000000 Feb 10 16:42 tooBigToSubmit.ps   
    -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.

    To check how much space you've used on arizona (and whether you're close to the CIT quota) type

    phoenix.Princeton.EDU% quota -v
    
    It will give you your usage and quota limit in MB. If you exceed the limit, you will experience significant problems, so be sure to delete useless files (especially files named core and large PostScript files).


    Grading

  • htree.c:   8 points.

  • art.c:   7 points.

  • Submission, readme, and style: 5  points.

  • Checking your work and hints

  • Step-by-step instructions for getting started and additional hints are available here.

  • Use the program htree126 to check your work.

  • Animation hack: to see an animation of your H-pattern as it is being drawn, have your program draw each H 1000 times in-a-row (in the same place). Then, view with gs as usual. This will slow down the PostScript rendering, and you'll be able to visualize the order in which your pattern gets drawn. Be sure to remove this before you submit your assignment.

  • Your artistic creation

  • Here are some guidelines for receiving full credit on this part of the assignment.

  • One approach is to choose a self-referential pattern as a target output. Here are some possibilities: Sierpinski triangle, Sierpinski curve, Hilbert curve, Dragon curve, Gosper island. Check out the exercises in Notes on Recursion for more possibilities. See also the Famous Fractals in Fractals Unleashed. Then try to figure out a recursive scheme that will generate it. Some pictures are harder to generate than others; consult a preceptor for advice if you're unsure.

  • Another way to create interesting results is to vary the number of recursive calls made within the function depending on the input. You might consider using some randomness or mathematical functions like gcd() to create fantastic effects.

  • We'll deduct if you're picture is overly boring and too similar to htree.c. Most students have fun with this part.
  • We will compile your program with
    gcc126 art.c
    
    as usual. Your program should read in input using scanf(). Submit an input file input.txt that contains the input values with which you want us to run your program. You may include whatever input parameters you like in input.txt, but be sure to have at least one parameter n that control the depth of the recursion. You might also consider storing the color palette input values from the Mandelbrot assignment data files.

    Important: we will run your program with the command

    a.out < input.txt
    
    If you do not submit the file input.txt, your program will not work.

  • Check out the the PostScript section of the COS 126 FAQ List for more information on PostScript.

  • We hope to display some of your creations on the display wall in the Frist Student Center.

  • Submission and readme
  • Use the following submit command:
    submit126 4 readme htree.c art.c input.txt
    
    Do not use different file names or capitalization, even for your artistic creation. Be sure that your htree.c reads in the single integer n from stdin. Be sure that you submitted the companion input file input.txt for your art.c program.

  • Your PostScript output must do the following, or you may receive severe penalties:

  • view and print properly (with gs and lpr). If it doesn't, name your C programs htree-bad.c or art-bad.c so that we do not waste paper and time trying to print them.

  • stay within the 512 x 512 box.

  • be less than 3MB in size.
  • The readme file should contain the following information. Here is a template readme file:

  • Name, precept number, high level description of code, any problems encountered, and whatever help (if any) your received.

  • Description of your artistic creation and how you went about creating it.

  • Extra credit

    The extra credit is intended to challenge the more advanced students, and is strongly recommended for students aiming for an A or A+ in the course. If you are still struggling with the basics of recursion, you will probably benefit more by understanding the recursion examples in the lecture notes than by attempting the extra credit.

  • Combine the two main concepts you have been using and write a recursive PostScript program (not for the squeamish)! Name your PostScript program extra.ps.

  • Or "un-recursify" your program. Name your program extra.c.



  • Kevin Wayne