|
Computer Graphics |
Fall 2000
|
Computer Graphics
Homework 00
6 hours
Copyright © 2000 David C. Banks
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".double x; double y; double z; double weight; double red; double green; double blue;
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
If you do not know about parsing program arguments, search the Web for "parsing program arguments".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 creating a Makefile, search the Web for "makefile tutorial".make grating
#!/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".
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".make grating.gif