// Author      : Josh Grant
// Course      : CIS5900, Computer Graphics, Fall 2000
// Assignment  : hw00
// Date        : September 3rd, 2000
// Description : C++ implementation of the class Pixel.


#ifndef _PIXEL_CPP
#define _PIXEL_CPP

#include <pixel.h>
#include <math.h>
#include <iomanip.h>

// When a pixel is created, all the member variables will be set to 0.
Pixel::Pixel() {
  x      = 0.0;
  y      = 0.0;
  z      = 0.0;
  red    = 0.0;
  green  = 0.0;
  blue   = 0.0;
  weight = 0.0;
  total  = 0.0;
}

// Determines the value of the grating for the given pixel.  This value is
// then assigned the red component of the pixel
void Pixel::evaluate(double myX, double myY, double myRadius) {
  double gratingValue;

  gratingValue = sin(2.0*M_PI*sqrt(myX*myX + myY*myY) / myRadius);
  gratingValue = 0.5*(gratingValue + 1.0);

  x      = myX;
  y      = myY;
  z      = 0.0;
  red    = gratingValue;
  green  = 0.8;
  blue   = 0.8;
  weight = 1.0;
}

// Prints out the rgb values for the pixel and scales the colors by a user
// specified int value.
void Pixel::displayScaled(ostream &os, int factor) {
  int sred, sgreen, sblue;
    sred   = (int)(red * (double)factor + 0.5);
    sgreen = (int)(green * (double)factor + 0.5);
    sblue  = (int)(blue * (double)factor + 0.5);
  os.width(4);
  os.fill(' ');
  os << sred << " " << sgreen << " " << sblue;
}

void Pixel::displayScaled(fstream &fs, int factor) {
  int sred   = (int)(red   * (double)factor + 0.5);
  int sgreen = (int)(green * (double)factor + 0.5);
  int sblue  = (int)(blue  * (double)factor + 0.5);
  fs.width(4);
  fs.fill(' ');
  fs << sred << " " << sgreen << " " << sblue;
}

#endif