/* 
Logan Lambert
10/11/2022
CpSC 101 Fall 2022 Lab 8
adding to the lab from last class to make the flag run more smoothly 
*/
#include <stdio.h>
#include <string.h>
	typedef struct header {
      char type[3];
      int width, height, maxColor;
   }Flag;
    typedef struct pixels {
      unsigned int r;
      unsigned int g;
      unsigned int b;
	   }pixelcolor;
//int getWidth ();
int main (void){ //Making a the Ireland flag

int g, s; 
      Flag fileType;
		fileType.maxColor = 255;
		strcpy(fileType.type, "P3");
		pixelcolor pixels;
		fileType.width = getWidth();
// 1. get the user's input for width
//getwidth
		fprintf(stderr, "\n\nFlag of Ireland");
      fprintf(stderr, "\n\tWhat width do you want the flag to be? ");
// 2. calculate the height based on the proportion stated on Wikipedia
       fileType.height = (fileType.width / 2);
      fprintf(stderr, "\n\nMaking the flag with width %d & height %d ...", fileType.width, fileType.height);
      fprintf(stdout, "\n\n");

// 3. declare an array of type:  unsigned int
	// * it will need to be big enough to hold all the color values:
	// * each pixel is made up of red, green, and blue values
	//   so each pixel has 3 things in it
	// * therefore (HINT):  the width is actually 3 times bigger
		//unsigned int area[fileType.width * fileType.height];
		fprintf(stdout, "%s", fileType.type);
      fprintf(stdout, " %d %d %d\n", fileType.width, fileType.height, fileType.maxColor);

// 4. nested for loops for writing the pixel data:
	// 	a.  outer for loop is for each row
	// 	b.  because the flag of Irelad has 3 equal vertical parts,
	//        there will be 3 equal inner for loops, each one going
	//        1/3 of the way across the row (i.e. 1/3 of the columns)
	// pseudocode:
     //writePixels
	  for (g = 0; g < fileType.height; g++) {  //g is for row
         for (s = 0; s < fileType.width/3; s++) {
            pixels.r = 0;
            pixels.g = 128;
            pixels.b = 0;
			fprintf(stdout, "%i %i %i\n", pixels.r, pixels.g, pixels.b);
			}
         for (; s < (2*fileType.width)/3;  s++) {
            pixels.r = 255;
            pixels.g = 255;
            pixels.b = 255;
         fprintf(stdout, "%i %i %i\n", pixels.r, pixels.g, pixels.b);
			}
         for (; s < fileType.width; s++) {
            pixels.r = 255;
            pixels.g = 165;
            pixels.b = 0;
      	fprintf(stdout, "%i %i %i\n", pixels.r, pixels.g, pixels.b);
			}
   }
	// 5. print the contents of the array to stdout, so with redirection,
	//    the pixels will be written to the .ppm file
	//    * with P3, the unsigned int values must be written so that
	//      the values are 3 to a line (see lab write-up)
	// pseudocode:
   return 0;
}
int getWidth() {
	int w;
	fscanf(stdin, "%d", &w); 
	return w;
	}






