Spiral (140 exactly)
========================================

![final product](https://i.sstatic.net/Ii8jM.jpg)

This is 140 characters exactly if you don't include the function headers and brackets. It's as much spiral complexity I could fit in the character limit.

    unsigned char RD(int i,int j){
        return DIM-BL(2*i,2*j);
    }
    unsigned char GR(int i,int j){
        return BL(j,i)+128;
    }
    unsigned char BL(int i,int j){
        i-=512;j-=512;int d=sqrt(i*i+j*j);return d+atan2(j,i)*82+sin(_cr(d*d))*32+sin(atan2(j,i)*10)*64;
    }

I gradually built on a simple spiral, adding patterns to the spiral edges and experimenting with how different spirals could be combined to look cool. Here is an ungolfed version with comments explaining what each piece does. Messing with parameters can produce some interesting results.

    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;
    }

Messing with parameters:

Here, the spirals are lined up but have different edge patterns. Instead of the blocky edges in the main example, this has edges entirely comprised of sin waves.

![edges](https://i.sstatic.net/65mDZ.jpg)

Here, the gradient has been removed:

![no gradient](https://i.sstatic.net/0TzSP.png)

An animation (<strike>which for some reason doesn't appear to be looping after I uploaded it, sorry. Also, I had to shrink it. Just open it in a new tab if you missed the animation</strike>):

![animation](https://i.sstatic.net/f3AAU.gif)

And, here's the [imgur album](https://i.sstatic.net/tph5o.jpg) with all images in it. I'd love to see if anyone can find other cool spiral patterns. Also, I must say, this is by far one of the coolest challenges on here I have ever seen. Enjoy!

EDIT: Here are some [backgrounds](https://i.sstatic.net/8Uw23.jpg) made from these spirals with altered parameters.

Also, by combining my spiral edge patterns with some of the fractals I've seen on here through the use of xor/and/or operations, here is a final spiral:

![fractal spiral](https://i.sstatic.net/BMuOA.jpg)