Computer Graphics
CAP 4730

 

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

 

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

  1. 0.25 hours
    Create a Web page for this course. Include your name and your email address.

    If you've never created a Web page before, search the Web for "html tutorial".

  2. 0.50 hours
    Create three .ppm images. Find and install pbmplus if you have a machine at home. Find and install xv if you your machine runs linux. Create an image (at least 16x11) called "initials.ppm", editing the text file by hand, with your initials in it. Create a 200x100 image "yellow.ppm" that is pale yellow. Create a 200x150 image "brown.ppm" that is reddish brown. You can display these images using xv. Or you can download the ppm plugin for Netscape.

    If you don't know about the ppm image format, search the web for "ppm image format" to find details.

    If you don't know about xv, search the web for "xv".

  3. 0.50 hours
    Use ppmtogif (on xi.cs.fsu.edu) to convert your images to .gif format.

    Then include them in your Web page.

    If you don't know about using ppmtogif, search the Web for the manual "man ppmtogif" to find details.

  4. 3.00 hours
    Write a program "grating" to create an array xDim*yDim of pixels and write it out in .ppm format. A pixel has the following member variables:
    double x;
    double y;
    double z;
    double weight;
    double red;
    double green;
    double blue;
    
    Your program will fill the array according to the evaluate() method. Use/modify the code below. Note that you will need to define the variable "radius".
    void
    Pixel::
    evaluate(double _x, double _y)
    {
    double gratingValue = sin(2.0*M_PI*sqrt(_x*_x + _y*_y)/radius);
    gratingValue = 0.5*(gratingValue + 1.0);
    
    x      = _x;             // member variables
    y      = _y;
    z      = 0.0;
    red    = gratingValue;
    green  = 0.8;
    blue   = 0.8;
    weight = 1.0;
    }
    
    To fill the array, loop over the pixels and set their values using the evaluate() method. Use/modify the code below. Note that xDim tells how many pixels are in a horizontal row, whereas xMin and xMax determine their locations.
    int   index;
    for (int yi = 0; yi < yDim; yi++)
      {
      double y = yMin + (yMax - yMin)*yi/(yDim-1);
      for (int xi = 0; xi < xDim; xi++)
        {
        double x = xMin + (xMax - xMin)*xi/(xDim-1);
        index    = yi*xDim + xi;
        pixel[index].evaluate(x, y);
        }
      }
    
    When writing out the file, traverse the y-direction in reverse order and scale the colors by 255.

    Parse the command line so that your program can be run by saying
    grating xDim 300 yDim 250 xMin -1.0 xMax 1.0 yMin -1.0 yMax 1.0 radius 0.5 > grating.ppm
    

    If you do not know about parsing program arguments, search the Web for "parsing program arguments".

  5. 0.50 hours
    Create a UNIX Makefile, so you can compile your program on xi.cs.fsu.edu by saying
    make grating
    

    If you do not know about creating a Makefile, search the Web for "makefile tutorial".

  6. 0.25 hours
    Use or modify this shell script "grating.csh" to call your program repeatedly, creating many .gif images.
    #!/bin/csh
    
    # Parse the command line
    set num = $#argv
    if ($num != 1) then
      echo usage: $0 numImages
      exit
    endif
    
    if ( ($1 > 0) && ($1 < 1000) ) then
      echo Making $1 images
    else
      echo Argument out of range.
      exit
    endif
    
    
    # Make a bunch of .gif images
    set flags = "xDim 200 yDim 200 xMin -2.0 xMax 2.0 yMin -2.0 yMax 2.0"
    
    set count = 0
    while ($count < $1)
      set radius = `echo "0.9^$count" | bc -l`
      echo $radius
    
      if ($count <  10) then
        set count = 0$count
      endif
    
      if ($count < 100) then
        set count = 0$count
      endif
    
      echo grating $flags radius $radius '|' ppmtogif > grating.$count.gif
      grating $flags radius $radius | ppmtogif grating.$count.gif
      @ count += 1
    end
    

    If you do not know about csh scripting, search the Web for "csh scripting".

  7. 0.50 hours
    Edit your Makefile so that typing
    make grating.gif
    
    will cause (1) the program to be compiled (if necessary), (2) the script to execute and create 80 images, and (3) gifmerge to convert them into the animation "grating.gif".

    Type "make grating.gif" to create an animated gif. Insert it into your Web page. Make it loop at least twice.

    If you do not know how to use gifmerge, search the Web for "gifmerge".

  8. 0.25 hours
    From the code's parent directory, create a tar file grating.tar and gzip it. Put a link to the .tar.gz file from your Web page.

    If you do not know about using tar, search the Web for "tar tutorial".

  9. 0.25 hours
    Print out your Web page. Put it on the cover of your notebook.
     
    Print another copy of your Web page.
    Print 2 copies of the homework 00 grade sheet.
    Print this page.
    Print the pbmplus home page.

    Print your .ppm files (as text). The first few lines will be enough.
    Print your code and headers.
    Print your shell script.
    Print your Makefile.
    Put them inside your notebook to turn in.

  10. Extra credit (100 points)
    Write a program to draw a bunch of spheres with different colors, different radii, different centers. Convert the ppm file to gif. Put it on your Web page, print it for your notebook, include the source code.

  11. Extra credit (100 points)
    Make your program read the center, radius, color for each sphere from the command line. Drive it with a script so that the spheres move. Make a gif animation. Put it on your Web page.