// draw1.cpp   A main program that uses my drawing library
// P. Conrad   Fall 2004, CISC181


#include <iostream>
#include <fstream>
#include "drawings.h"
#include <string>
#include <new>
using namespace std;

int main(void)
{

  const int numFiles = 3;

  // Declare an array of C++ strings, allocated from the heap
  // good programming practice says we MUST pay back the memory we borrowed!

  // Note: we could have done this with an array on the stack, since the
  // size of the array is actually hard coded as a constant---but I 
  // chose to use the heap to illustrate the technique---and to make the
  // example more general.   You could, for example, read in the list of
  // colors from a file (so that the number of colors isn't known until run 
  // time).

  string *fileList = new string[numFiles]; 
  string *colorList = new string[numFiles];

  fileList[0] = "drawRedHouses.dat";
  fileList[1] = "drawGreenHouses.dat";
  fileList[2] = "drawBlueHouses.dat";

  colorList[0] = "red";
  colorList[1] = "green";
  colorList[2] = "blue";

  writeGnuplotFileWithMultipleColors("drawMultiColoredHouses.gnuplot", 
				     3,
				     fileList,
				     colorList,
				     "drawMultiColoredHouses.png",
				     20.0, 20.0);

  // pay back the storage we borrowed from the heap
  delete [] fileList;
  delete [] colorList; 
  
  ofstream redfile("drawRedHouses.dat",ios::out); 

  if (!redfile)
    {
      cerr << "Couldn't open drawRedHouses.dat file; sorry!" << endl;
      exit(4);
    }

  ofstream greenfile("drawGreenHouses.dat",ios::out); 

  if (!greenfile)
    {
      cerr << "Couldn't open drawGreenHouses.dat file; sorry!" << endl;
      exit(-1);
    }

  ofstream bluefile("drawBlueHouses.dat",ios::out); 

  if (!bluefile)
    {
      cerr << "Couldn't open drawBlueHouses.dat file; sorry!" << endl;
      exit(-1);
    }


  redfile << "# Draw a neighborhood of houses... " << endl;
  greenfile << "# Draw a neighborhood of houses... " << endl;
  bluefile << "# Draw a neighborhood of houses... " << endl;

  for(int x=1; x<10; x+=3)
    { 
      drawHouse(redfile,x,2,3,2);
      drawHouse(bluefile,x,6,3,2);
      drawHouse(greenfile,x,10,3,2);      
    }

  redfile.close();
  bluefile.close();
  greenfile.close();

  return 0;
  
}



