#include "type_image.h"
#include <iostream>
using namespace std;
#include <cassert>
#include <complex>

void afficher(type_image&);


#define LX 512
#define LY 512
#define N 256
#define M 4*4
#define Irmin -2
#define Irmax 1
#define Iimin -1.1f
#define Iimax 1.1f


complex<float> Orbite(complex<float> z, float Ir, float Ii)
{
	return (z*z+complex<float>(Ir, Ii));
}

int main()
{
	type_image ImageTest(LX, LY);

	complex<float> Tampon;

	int i, j, k;
	float Ir, Ii;

	for (i = 0; i < LX; i++)
		for (j = 0; j < LY; j++)
		{
			Tampon = 0;
			Ir = Irmin + (Irmax - Irmin) * ((float)(i))/((float)(LX));
			Ii = Iimin + (Iimax - Iimin) * ((float)(j))/((float)(LY));

			for (k = 0; k < N; k++)
			{
				Tampon = Orbite(Tampon, Ir, Ii);

				if (Tampon.real()*Tampon.real()+Tampon.imag()*Tampon.imag() > M)
				{
					ImageTest(i, j, BLEU) = ((float) k)/255.0f;
					ImageTest(i, j, ROUGE) = ((float) k)/255.0f;
					ImageTest(i, j, VERT) = ((float) k)/255.0f;
					break;
				}
			}

			if (k == N)
			{
				ImageTest(i, j, BLEU) = 1;
				ImageTest(i, j, ROUGE) = 1;
				ImageTest(i, j, VERT) = 1;
			}
		}

	ImageTest.SauveBMP(string("mandelbrot.bmp"));
		
	afficher(ImageTest);

	return 0;
}
