#include <iostream>
#include <fstream>
#include "Image.h"
#include "Sphere.h"

int main(){
  ofstream outfile("circles.ppm");
  int xres=512, yres=512;
  Image image(xres, yres);
  Sphere sphere1(Point(-1.5, 0.5, 1), 1.2);
  Sphere sphere2(Point(0,0,1.1), 1.7);
  Sphere sphere3(Point(1, -0.5, 1.2), 1.9);
  for(int i=0;i<yres;i++){ 
    for(int j=0;j<xres;j++){ 
      Color result; 
      double x = 2 * (j - xres/2. + 0.5)/xres; 
      double y = 2 * (i - yres/2. + 0.5)/yres; 
      Ray ray(Point(0,0,-2), Vector(x, y, 1)); 
      if(sphere1.intersects(ray)){ 
	result = Color(.2, 1, 1); 
      } else if(sphere2.intersects(ray)) {
	result = Color(1, .1, 1); 
      } else if(sphere3.intersects(ray)) {
	result = Color(1, 1, .2); }
      else {
	result = Color(.2, .2, .5); 
      }
      image.set(j, i, result); 
    } 
  }
  image.write(outfile);
  outfile.close();
  return 0;
}

