Computer Graphics
CAP 4730

 

Fall 2000
Tuesday/Thursday 9:30am
103 Love Building
Dr. David C. Banks

 

Computer Graphics
Homework 04
6 hours
 
Copyright © 2000 David C. Banks

  1. 1.25 hours
    Postscript by hand.

    Take a look at a short postscript tutorial (here's another). Create a postscript image. Note that the document begins with %! and ends with showpage. View the image under UNIX with showps, xpsview, or ghostview. For windows, search the Web for '"postscript viewer" windowsNT'. Save this file and send it to a printer. Put the raw postscript text and also its output into your notebook.

    %!
    newpath
    100 200 moveto
    200 250 lineto
    100 300 lineto
    2 setlinewidth
    stroke
    showpage
    


    Create your own postscript file using lines and circles (arcs). Create a viewpoint (small disk) and label it "viewpoint". Create a light source (small disk) and label it "light". Create a thick line and label it "object". Pick at least 3 points on the line; highlight each one (small disk) and draw a ray (thin line) from it to the viewpoint and from it to the light source. I've created an example, which is shown at left. Do not re-use my example. Set the viewpoint, light, and segment endpoints to be your own choice. Print both the raw postscript text and its ouput, and put them in your notebook.

  2. 4.00 hours
    Postscript by code.

    Write a program "reflection" that outputs postscript to produce an image like the one you made by hand. The program reads the command line for the 2D location of the light, the viewpoint, the endpoints of a segment, and the number of samples along the segment. Assume that the coordinate system goes from 0 to 1 in the x and y directions.

    reflection view 0.2 0.3 light 0.1 0.2 line 0.8 0.5 0.6 0.4 samples 10 > reflection.ps
    

    You might output a segment in postscript like this.

    segment(float x1, float y1, float x2, float y2, float grayLevel)
      {
      printf("%f setgray\n", grayLevel);
      printf("%f %f moveto \n%f %f lineto \nstroke\n",
        x1, y1, x2, y2);
      }
    

  3. Extra credit (100 points): at each sample point on the object (the segment), compute the cosine of the angle between the ray to the light and the normal vector. Color the background black. Color the ray from the light white. Make the color of the ray to the viewpoint be the cosine you computed. Distribute the rays around a circle centered at the viewpoint. Find the ray intersection with the object (if it exists).

  4. Extra credit (050 points): draw little arcs to indicate the angles between the light rays and the segment normals.

  5. Extra credit (050 points): make a shell script to repeatedly call your program with different command-line arguments. Convert the images to an animated gif. Put it on your Web page.

  6. 0.50 hours
    Link the postscript files to your Web page. Convert them to pdf and link them. Use /usr/local/bin/convert on the SGI's to produce gif images of your postscript. Convert to the SGI format, then use /usr/sbin/izoom to resize it.

  7. 0.25 hours

    Print this page.
    Print your code, headers, and Makefile.
    Print your Web page for this assignment.
    Put them inside your notebook to turn in.