Below you'll find a small Java program which shows a fun graphical effect-- color table animation. This technique was used extensively back when computer memory was expensive and slow. At each pixel, instead of storing a color (using 16 or 32 bits), we store an index (using 4 or 8 bits) into a table of colors. Color tables typically have room for only 16 or 256 entries, so this "indexed" scheme (standard VGA) makes photographs look grainy; the direct method, one color per pixel (called high or true color) looks better.
But indexed color lets you do neat graphical effects like the above. The way it works is: you write some neat, smoothly-varying pattern (like the interfering cosine sources above) onto the screen; then to make the colors change you just have to change the color table.
In the code below, the class Demo implements the "interesting" part of a color-table animation Java program. The initialization routine [init] writes two interfering cosine sources into the byte buffer [pix]. The animation routine [fillBuffer] fills in the breakpoints in the color table. [cm.addBreaks] makes [ColorMap] interpolate the rest of the entries in the table. To animate, the colors of the breakpoints are randomly perturbed.
This technique was quite popular in the late 1980's, when VGA cards were top-of-the-line. Many fun effects are possible-- its especially neat when the color table wraps around.
Link to the source code.