Sketch 91: Simulating the Aurora

This is sketch 91 adapted for the web.
Among objects that are difficult to render on a computer, the northern lights or aurora is near the top of the list. They flicker and roll, the colors change, the shape changes at various speeds, and they generally have no one specific shape. There have been efforts to draw them with more or less success; this sketch is one of those attempts.

There are many shapes that the aurora can take, and this sketch will only attempt to draw one of those: the typical curtain type, one example of with appears in the figure to the right.
The sketch will make the color change slowly as a function of Y position. Starting with a red value at the bottom of the auroral curtain, the hue will increase in pixels above. Starting at a hue value of h=15, the hue increases according to:
h = h + random(.87)
At the very top of the curtain the brightness will decease, fading the color away. This is the first aspect of the sketch.
Next, notice that the aurora appears to concist of vertical strokes and is banded horizontally. This is accomplished in the program by changing the saturation of the pixels periodically as a function of X coordinate. The code is:
if (i%3 == 0) s=220+random(20)-10;
else if (i%2 == 0) s = 210+random(20)-10;
else s = 200+random(20)-10;
where i is the horizontal position and s is the saturation. I%3 is the remainder when i is divided by 3, so there is a somewhat random variation in the saturation, giving darker bands.
The curtain effect is accomplished using a sine function to locate the pixels vertically. For a basic coordinate (i,j) the actual pixel will be at (i,j-bb*sin(a*i)) where the parameters a and bb change by a small and random amount during each iteration. This makes the curtain move.