/* Coloring scheme for multiple attractors */
/* cmap can be COLOR, GRAY or BW. */
/* COLOR:  Use hue to name attractors, shade to show rate; */
/* shading controlled by "spread". */
/* GRAY:  Use grayscale to name attractors, minor variations */
/* in shade to show rate. */
/* BW: Julia set black, rest white. */

/*0- in Julia set;
  1+nit*i+n -converged to ith attractor in n iterations;
  nit = (COLORS-1)/(number of attractors).

  Program must set 
  	mit=range of iterations actually used,
	na =number of attractors,
	RESERVED, FREE and JULIA.
*/

/* 0-100 looks black; adjust g accordingly */
double gray_adjust(g)
	double g;

{	if(g==0) return(g);
	g = (100+155*g)/255;
	return(g);
}

set_map()
{
	if(cmap == COLOR) set_colors();
	if(cmap == GRAY) set_grays();
	if(cmap == BW) set_bw();
}

set_bw()
{
        int i, j, k;
	double g;

        scan_gray(JULIA,0.0);
	for(i=0; i<FREE; i++)
        	scan_gray(RESERVED+i,1.0);
}

set_grays()
{
        int i, j, k;
	double g;

        scan_gray(JULIA,0.0);
	if(na == 1)
	{	for(i=0; i<mit; i++)
		{	k = RESERVED+i;
			g = i;
			g = g/mit;
			g=gray_adjust(g);
			scan_gray(k,g);
		}
		return;
	}
	for(i=0; i<na; i++)
	for(j=0; j<mit; j++)
	{	g = (((i+rotate)%na)*mit + spread*j)/
		((na-1+spread)*mit);
		k = RESERVED+i*nit+j;
		g=gray_adjust(g);
		scan_gray(k,g);
	}
}

set_colors()
{
        int i, j, k;
	double h, l, s;

        scan_rgb(JULIA,0,0,0);
        scan_rgb(PC_SET,0,0,0);
	if(na == 1)
	{	for(i=0; i<mit; i++)
		{	k = RESERVED+i;
			h = i*360.0/mit;
			l = 50.0;
			s = 100.0;
			scan_hls(k,h,l,s);
		}
		return;
	}
	for(i=0; i<na; i++)
	{	h = (i+rotate)%na;
		h = h*360.0/na;	
		for(j=0; j<mit; j++)
		{	k = RESERVED+nit*i+j;
			l = 50.0+40*spread-80*spread*j/mit;
			s = 100.0;
			scan_hls(k,h,l,s);
		}
	}
}
