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 input1.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.txt
    
    In this example input1.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 KB (thousands of bytes). 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).

  • If you want to convert a PostScript picture into another format like JPEG (e.g., to post on your Web site or email to your parents), you can use the Unix program xv. From an X-Windows session, type the command
    xv art.ps
    
    Next, right-click to bring up a menu. Finally, save the image as a JPEG file.

  • Checking your work and hints

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

  • Use the program htree126.exe in /pub/cs126/htree/ to check your work.

  • Animation hack on arizona: 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. Most students have fun with this part.

  • 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. See also the Famous Fractals in Fractals Unleashed for some ideas. Check out the exercises in Notes on Recursion for more possibilities. 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. Add color.

  • We'll deduct points if your picture is overly boring or too similar to htree.c. You will also lose points if your artwork could easily be created without recursion, e.g., it is tail-recursive: a single recursive call at the very end of the function.

  • You should submit 2 input files named input1.txt and input2.txt. Your program should take at least one input, say n that controls the depth of the recursion. The two input files should use different values of n.
  • We will compile your program with
    gcc126 art.c
    
    as usual. Your program should read in input using scanf(). Submit two input files that contains the input values with which you want us to run your program. You may include whatever input parameters you like, 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 < input1.txt
    a.out < input2.txt
    
    If you do not submit the files input1.txt and input2.txt, your program will not work. These files should contain only the input data: do not include your name or precept number in these files.

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

  • We plan to display some of your creations on the display wall in the Frist Student Center. Follow these display wall instrutions to show off your artwork and earn 2 points of extra credit at the same time.

  • Submission and readme

  • Submit the following files:
    readme.txt htree.c art.c input1.txt input2.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 two companion input files 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.

  • includes the final showpage command.
  • 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

    Although it is not mentioned in the assignment, we'll award extra credit if you follow the above instructions to create an image for the Display Wall. This requires no programming and can be alot of fun!

    The two extra credit opportunities below are intended to challenge the more advanced students. If you are still struggling with the basics of recursion, you will probably benefit more by understanding the recursion examples in the lecture notes and readings 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 in a bottom-up manner. Name your program extra.c.

  • Enrichment Links

  • Here are the display wall submissions from Spring 2001.



  • Kevin Wayne