Goals

  • Create graphics.

  • Learn about recursion.

  • 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.txt
    -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 .ps or .tur 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 reference solution for your operating system 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 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.

  • A very good 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. Here are some more ideas. Check out the exercises in Notes on Recursion for still 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 and run your program with:
    % gcc126 art.c -o art
    % gcc126 turtle.c -o turtle
    % art < input1.txt | turtle
    % art < input2.txt | turtle
    
    Thus, your program should read in input from stdin using scanf(). Be sure to submit two input files that contain the input values with which you want us to run your program. If this doesn't work, you'll lose a substantial number of points. You may include whatever input parameters you like in the input files, you should 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.

  • You are permitted to extend the turtle.c program to support new commands, e.g., drawing circles, gradient filling regions, etc. In this case you will want to check out the the PostScript section of the COS 126 FAQ List to see what types of PostScript drawing commands are available. If you extend turtle.c, then you need to submit it along with the rest of your files.

  • 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. Name your jpg file login.jpg where login is replaced by your arizona login name.

  • 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 turtle graphics output must do the following, or you may receive severe penalties:

  • view and print properly (via turtle and ghostview). 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.txt 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, Fall 2001, and Spring 2002.



  • Kevin Wayne