unsigned char RD(int i,int j){
// *2 expand the spiral
// DIM- reverse the gradient
return DIM - BL(2*i, 2*j);
}
unsigned char GR(int i,int j){
// notice swapped parameters
// 128 changes phase of the spiral
return BL(j,i)+128;
}
unsigned char BL(int i,int j){
// center it
i -= DIM / 2;
j -= DIM / 2;
double theta = atan2(j,i); //angle that point is from center
double prc = theta / 3.14f / 2.0f; // percent around the circle
int dist = sqrt(i*i + j*j); // distance from center
// EDIT: if you change this to something like "prc * n * 256" where n
// is an integer, the spirals will line up for any arbitrarily sized
// DIM value, or if you make separate DIMX and DIMY values!
int makeSpiral = prc * DIM / 2;
// makes pattern on edge of the spiral
int waves = sin(_cr(dist * dist)) * 32 + sin(theta * 10) * 64;
return dist + makeSpiral + waves;
}