Computer Graphics
CAP 4730

 

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

 

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

  1. 0.25 hours
    Box filter

  2. 0.50 hours
    Tent filter

  3. 0.50 hours
    Quadratic filter

  4. 0.75 hours
    Cubic filter

  5. 1.25 hours
    Quartic filter

  6. 2.00 hours
    Create an image class. An image contains xDim*yDim pixels and contains a function filter() and a radius (measured in pixels). It also supports a method setPixel().

    To set a pixel's color, use the filter function as a weight for the pixel's neighborhood of the desired radius. Use/modify the code below to draw a fat dot at location (x,y).
    void
    Image::setPixel(double _x, double _y, double _z,
    		double _r, double _g, double _b)
      {
      int xiMin, xiMax, yiMin, yiMax; // integer valued locations
      double xCenter, yCenter;        // (_x, _y) in array coords
      double distance;                // distance between points
    
      xCenter = (_x - xMin)*(xDim - 1.0)/(xMax - xMin);
      yCenter = (_y - yMin)*(yDim - 1.0)/(yMax - yMin);
    
      xiMin = ceil (xCenter - radius);
      xiMax = floor(xCenter + radius);
      yiMin = ceil (yCenter - radius);
      yiMax = floor(yCenter + radius);
    
      // Clamp xiMin to the interval [0, xDim-1], etc.
      //
      // You implement the clamp() routine.
    
      clamp(xiMin, 0, xDim-1);        
      clamp(xiMax, 0, xDim-1);
      clamp(yiMin, 0, yDim-1);
      clamp(yiMax, 0, yDim-1);
    
      double w;                       // weight from filter
      int index;                      // array index
      for (int yi = yiMin; yi <= yiMax; yi++)
        {
        for (int xi = xiMin; xi <= xiMax; xi++)
          {
          distance = sqrt((xCenter-xi)*(xCenter-xi) + 
    		      (yCenter-yi)*(yCenter-yi) );
          w        = filter(distance);
    
          index    = yi*xDim + xi;
    
          pixel[index].x      += w*_x;
          pixel[index].y      += w*_y;
          pixel[index].z      += w*_z;
          pixel[index].red    += w*_r;
          pixel[index].green  += w*_g;
          pixel[index].blue   += w*_b;
          pixel[index].weight += w;
          }
        }
      }
    

  7. 0.50 hours
    Use your Image class to create a .ppm file that is 300x200 pixels. Choose xMin = -1, xMax = 1, yMin = -1, yMax = 1. Choose radius = 27 pixels. Use the non-normalized tent filter. Draw
    a pale green dot in the upper right part of the image
    a gray dot in the upper left part of the image
    a brown dot in the lower left part of the image
    a red dot in the lower right part of the image
    a green dot in the middle of the image
    a blue dot slightly offscreen.

    Convert the image to gif. Insert into your Web page.
    Link your code, headers, and Makefile from your Web page.
    Create a tar.gz file for the directory for this assignment.

  8. 0.25 hours
    Print two copies of the homework 01 grade sheet.
    Print this page.
    Print your code, headers, and Makefile.
    Print your Web page for this assignment.
    Put them inside your notebook to turn in.

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

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