// Cameron Scott
// October 7, 2022
// Lab Section 002
// Lab #6
// This program prints a ppm image of the Irish flag using nested for loops and arrays
//

#include <stdio.h>
#include <math.h>

int main (void){
	int width, height, i, j, k = 0;  // k is used for the array

	fprintf(stderr, "\n\nFlag of Ireland");
	fprintf(stderr, "\n\tWhat width do you want the flag to be? ");
	scanf("%d", &width);

	height = width / 2;
	fprintf(stderr, "\n\nMaking the flag with width %d & height %d ...", width, height);
	fprintf(stderr, "\n\n");
		
	unsigned int colorArray[width * height * 3]; 

	fprintf(stdout, "P3\n");
	fprintf(stdout, "%d %d %d\n", width, height, 255);

	for (i = 0; i < height; i++) {
	   for (j = 0; j < width / 3; j++) {
		colorArray[k++] = 0;
		colorArray[k++] = 128;
		colorArray[k++] = 0;
	   }
	   for (; j < (2*width/3); j++) {
		colorArray[k++] = 255;
		colorArray[k++] = 255;
		colorArray[k++] = 255;
	   }
	   for(; j < width; j++) {
	       colorArray[k++] = 255;
	       colorArray[k++] = 165;
	       colorArray[k++] = 0;
	}
		
}

	
	
	for (k = 0; k < height * width * 3; k+=3) {
		fprintf(stdout, "%i %i %i\n", colorArray[k], colorArray[k+1], colorArray[k+2]);
}


	return 0;
}
