#include "functions.h"

void make_pixel(struct pixel color)
{
	fprintf(stdout, "%c%c%c", color.r, color.g, color.b);
}

void make_ppm_header(struct size header)
{
	fprintf(stdout, "P6\n");
	fprintf(stdout, "%d %d %d\n", header.width, header.height, 255);
}

void circle(struct size header)
{
	make_ppm_header(header);
	
	struct pixel color1 = {.r = 255, .g = 255, .b = 255}, color2 = {.r = 0, .g = 0, .b = 0};
	//color1 is in circle, color2 is out of circle
	
	int row, column;
	
	for(row = 1; row <= header.height; row ++) //loop through the rows
	{
		for(column = 1; column <= header.width; column ++) //loop through the columns
		{
			float result1 = sqrt(pow((column - 150), 2) + pow((row - 200), 2));
			float result2 = sqrt(pow((column - 350), 2) + pow((row - 200), 2));
			float result3 = sqrt(pow((column - 500), 2) + pow((row - 200), 2));
			/* first circle centered at (200,150) with radius 100 (result1)
			 second circle centered at (200,300) with raidus 75 (result2)
			 third circle centered at (200,500) with raidus 50 (resutl3)
			 within circle is if the square root of ((x - xcenter)squared + (y - ycenter)squared) is less than the radius */
			
			if(result1 < 100 || result2 < 75 || result3 < 50) //in a circle
			{
				make_pixel(color1);
			}
			else //not in a circle
			{
				make_pixel(color2);
			}
		}
	}
}

void diagonal(struct size header)
{
	make_ppm_header(header);
	
	struct pixel color1 = {.r = 255, .g = 0, .b = 0}, color2 = {.r = 0, .g = 0, .b = 255};
	//color1 is the left/top side, color2 is the right/bottom side
	
	int row, column;
	
	for(row = 1; row <= header.height; row++) //loop through the rows
	{
		for(column = 1; column <= header.width; column++) //loop through the columns
		{
			if(400 - column > row) //left/top side
			{
				make_pixel(color1);
			}
			else //right/bottom side
			{
				make_pixel(color2);
			}
		}
	}
}

void gradient(struct size header)
{
	make_ppm_header(header);
	
	struct pixel color1 = {.r = 0, .g = 255, .b = 0}, color2 = {.r = 0, .g = 0, .b = 255};
	//color 1 is left extreme, color2 is right extreme
	
	int row, column;
	
	for(row = 1; row <= header.height; row++) //loop through the rows
	{
		for(column = 1; column <= header.width; column++) //loop through the columns
		{
			if(column < 250) //left side
			{
				make_pixel(color1);
				color1.b += 1;
				color1.g -= 1;
			}
			else
			{
				make_pixel(color2);
				color2.r +=1;
				color2.b -=1;
			}
		}
		color1.g = 255;
		color1.b = 0;
		color2.r = 0;
		color2.b = 255;
	}
	
}