#include <stdio.h>
int convdim(char dim[2]){
	int a=dim[0],b=dim[1];
	if (dim[0]<0) a=a+256;
	if (dim[1]<0) b=b+256;
	return b*256+a;
}
int loop(double x, double y, double m, double n, int num){
	double w,z;
	int step;
	if (num>=40){	//this is the number of iterations.feel free to change
		return num;
	}
	else{
		w=x*x-y*y+m+.3; //change the .3 have fun
		z=2*x*y+n+.6;	//likewise change the .6
		if (x*x+y*y>4){
			return num;
		}
		else{
			step=loop(w,z,m,n,num+1);
			return step;
		}
	}
}
int main(){
	int d=0,t=0,c=0,pnt=0;
	double a,b;
	char dim[2]={0,2}; 
/*give the dimentions of the image
values range from 0 to 255
the SECOND value is the 256 place
so for 400, the values are 144,1*/
	char rgb[3]={0,0,0}; /*r,g,b we aren't going to mess with these*/
	FILE *out;
	d=convdim(dim);
	out=fopen("bin.tga","wb");
	fwrite("\x00\x00\x02\x00\x00\x00\x00\x18\x00\x00\x00\x00",12,1,out);
	for (t=0;t<2;t++) fwrite(dim,2,1,out);
	fwrite("\x18\x0",2,1,out);
	for (t=0;t<d;t++) for (c=0;c<d;c++){
		a=-2+4.0*c/d;
		b=-2+4.0*t/d;
		pnt=loop(a,b,a,b,0);
		if (pnt>=40){
			rgb[0]=256.0*a*pnt;	//mess with these
			rgb[1]=256.0*a*b*pnt;	//get creative
			rgb[2]=256.0*b*pnt;	//as long as you have some
		}				//expression after the = and
		else {				//before the ; with pre-defined
			rgb[0]=256;		//variables you should get
			rgb[1]=256*(a+b);	//some interesting images
			rgb[2]=256.0*a/b;	//a,b and pnt help. Enjoy!
		}
		fwrite(rgb,3,1,out);
	}
	fclose(out);
	return 0;
}

