// C/C++ File
// AUTHOR:   foton
// FILE:     main.c
// ROLE:     to rule them all
// CREATED:  2017-01-30 21:51:28
// MODIFIED: 2017-03-09 20:51:10

#include "fdf.h"

void	circle(t_FDF *FDF)
{
	t_pnt	p1;
	t_pnt	p2;
	double angle;


	for (int i = 0; i < 360; i += 1)
	{
		p1.x = 250;
		p1.y = 250;
		angle = i * M_PI / 180;
		p2.x = p1.x + 250 * sin(angle);
		p2.y = p1.y + 250 * cos(angle);
		line(p1, p2, FDF);
	}
}

void	test_line(t_FDF *FDF)
{
	t_pnt p1;
	t_pnt p2;

	p1.x = 0;
	p1.y = 0;
	p2.x = 500;
	for (p2.y = 0; p2.y <= 500; p2.y += 4)
	{
		line(p1, p2, FDF);
		mlx_put_image_to_window(FDF->mw->mlx, FDF->mw->win, FDF->image, 0, 0);
	}
	for (p2.x = 500; p2.x >= 0; p2.x -= 4)
	{
		line(p1, p2, FDF);
		mlx_put_image_to_window(FDF->mw->mlx, FDF->mw->win, FDF->image, 0, 0);
	}
	p1.x = 500;
	p1.y = 0;
	p2.x = 0;
	for (p2.y = 0; p2.y <= 500; p2.y += 4)
	{
		line(p1, p2, FDF);
		mlx_put_image_to_window(FDF->mw->mlx, FDF->mw->win, FDF->image, 0, 0);
	}
	for (p2.x = 0; p2.x <= 500; p2.x += 4)
	{
		line(p1, p2, FDF);
		mlx_put_image_to_window(FDF->mw->mlx, FDF->mw->win, FDF->image, 0, 0);
	}
	p1.x = 500;
	p1.y = 500;
	p2.x = 500;
	p2.y = 0;
	for (p2.x = 500; p2.x >= 0; p2.x -= 4)
	{
		line(p1, p2, FDF);
		mlx_put_image_to_window(FDF->mw->mlx, FDF->mw->win, FDF->image, 0, 0);
	}
	for (p2.y = 0; p2.y <= 500; p2.y += 4)
	{
		line(p1, p2, FDF);
		mlx_put_image_to_window(FDF->mw->mlx, FDF->mw->win, FDF->image, 0, 0);
	}
	p1.x = 0;
	p1.y = 500;
	p2.x = 500;
	p2.y = 500;
	for (p2.y = 500; p2.y >= 0; p2.y -= 4)
	{
		line(p1, p2, FDF);
		mlx_put_image_to_window(FDF->mw->mlx, FDF->mw->win, FDF->image, 0, 0);
	}
	for (p2.x = 500; p2.x >= 0; p2.x -= 4)
	{
		line(p1, p2, FDF);
		mlx_put_image_to_window(FDF->mw->mlx, FDF->mw->win, FDF->image, 0, 0);
	}
	mlx_clear_window(FDF->mw->mlx, FDF->mw->win);
	p1.x = 0;
	p1.y = 0;
	p2.y = 500;
	for (p2.x = 0; p2.x <= 500; p2.x += 1)
	{
		line(p1, p2, FDF);
		mlx_put_image_to_window(FDF->mw->mlx, FDF->mw->win, FDF->image, 0, 0);
		p1.x += 1;
	}
	mlx_clear_window(FDF->mw->mlx, FDF->mw->win);
	p1.x = 0;
	p1.y = 0;
	p2.x = 500;
	for (p2.y = 0; p2.y <= 500; p2.y += 1)
	{
		line(p1, p2, FDF);
		mlx_put_image_to_window(FDF->mw->mlx, FDF->mw->win, FDF->image, 0, 0);
		p1.y += 1;
	}
	mlx_clear_window(FDF->mw->mlx, FDF->mw->win);
	p1.x = 500;
	p1.y = 0;
	p2.x = 500;
	for (; p2.x >= 0; p2.x -= 1)
	{
		line(p1, p2, FDF);
		mlx_put_image_to_window(FDF->mw->mlx, FDF->mw->win, FDF->image, 0, 0);
		p1.x -= 1;
	}
	mlx_clear_window(FDF->mw->mlx, FDF->mw->win);
	p1.x = 0;
	p1.y = 500;
	p2.x = 500;
	for (p2.y = 500; p2.y >= 0; p2.y -= 1)
	{
		line(p1, p2, FDF);
		mlx_put_image_to_window(FDF->mw->mlx, FDF->mw->win, FDF->image, 0, 0);
		p1.y -= 1;
	}
}

int		main(int argc, char **argv)
{
	t_FDF	*FDF;
//	int 	i;
//	int 	j;
//	int		rgb;
//	t_color c1;
//	t_color c2;
//	t_color c3;
	if (argc != 2)
		return (0);
	FDF = FDF_init(argv[1]);
//	i = 0;
//	c1 = color_init(225, 13, 14);
//	c2 = color_init(20, 177, 4);
//	c3 = c1;
//	while (i < FDF->w_height)
//	{
//		j = 0;
//		rgb = color_to_int(c3);
//		while (j < FDF->w_width)
//		{
//			*((int *)FDF->image_data + j + i * FDF->w_width) = rgb;
//			j++;
//		}
//		c3 = color_lerp(c1, c2, (float)i / FDF->w_height);
//		i++;
//	}
//	mlx_put_image_to_window(FDF->mw->mlx, FDF->mw->win, FDF->image, 0, 0);
	render(FDF);
	mlx_key_hook(FDF->mw->win, key_hook, FDF);
	mlx_loop(FDF->mw->mlx);
	return (0);
}
