/* Fall 2022 Lab 9
   * continuing with ppm of flag of Ireland
			green|white|orange
	* introducing multi-module programs
	*		will move each function into a separate file
	*		will create a header file
	* reinforcing loops, arrays, and structs

	PPM images have 2 parts:
		header information
		pixel information

	All of the image contents (header and pixel info) will be written
	to stdout so when we run the program with redirection, those items
	being sent to stdout will be redirected to a file

	For example, to run this program, you will type:
		./a.out > flag.ppm
	and everything that was sent to stdout will be written to the file
	called  flag.ppm

	All the other statements that you want to go to the scrren and not 
	the image will be written to stderr.

*/

#include <stdio.h>
#include "defs.h"


int main (void){
	int theWidth, theHeight;  // k is used for the array

	// get the user's input for width
	theWidth = getWidth();

	// calculate the height based on the proportion stated on Wikipedia
	theHeight = theWidth / 2;
	fprintf(stderr, "\n\nMaking the flag with width %d & height %d ...",
		theWidth, theHeight);
	fprintf(stderr, "\n\n");
	
	// now that we know the width and the height, 
	// create and initiaize the header struct
	header_t imageHeader = (header_t) { "P3", theWidth, theHeight, 255 };

	// declare array big enough to hold all the pixels
	pixel_t flag[theWidth * theHeight];

	// fill flag array
	fillFlagArray(flag, theWidth, theHeight); 

	// write header to stdout
	writeHeader(imageHeader);
	
	// write pixels to stdout
	writePixels(flag, theWidth, theHeight);

	return 0;
}


