<?xml version="1.0"?>
<!-- 
COPYRIGHT AND LICENSE
If you find this code useful, consider placing a link to http://code.mincus.com on your site.

Copyright 2006, Allen Holman.  All rights reserved.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
         "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     onload="screen=init();"
     style="background:black">

<script type="text/javascript"><![CDATA[
    var SVG_NS ="http://www.w3.org/2000/svg";

    function convert_color( color ) {
        if ( color > 9 ) {
            if ( color == 10 ) {
                return( "A" );
            } else if ( color == 10 ) {
                return( "A" );
            } else if ( color == 11 ) {
                return( "B" );
            } else if ( color == 12 ) {
                return( "C" );
            } else if ( color == 13 ) {
                return( "D" );
            } else if ( color == 14 ) {
                return( "E" );
            } else if ( color == 15 ) {
                return( "F" );
            }
        } else {
            return( color );
        }
    }

    function color_encode( color ) {
        var color_1 = Math.floor( color / 16 );
        var color_2 = color - ( color_1 * 16 );
        return( convert_color( color_1 ) + "" + convert_color( color_2 ) );
    }

    function make_gradient( colors, start_index, red_s, green_s, blue_s,
                            end_index, red_e, green_e, blue_e ) {
        // Concept based off of - http://membres.lycos.fr/darki/tutorials/drkitut1.txt
        var max = end_index - start_index;
        colors[start_index] = "#" + color_encode( red_s ) + "" + color_encode( green_s ) + "" + color_encode( blue_s );
        colors[end_index] = "#" + color_encode( red_e ) + "" + color_encode( green_e ) + "" + color_encode( blue_e );

        var red_inc = ( red_e - red_s ) / max
        var green_inc = ( green_e - green_s ) / max
        var blue_inc = ( blue_e - blue_s ) / max

        for ( i = 0; i < max; ++i ) {
            colors[i + start_index] = "#" + color_encode( ( red_s + ( red_inc * i ) ).toFixed(0) ) + "" +
                              color_encode( ( green_s + ( green_inc * i ) ).toFixed(0) ) + "" +
                              color_encode( ( blue_s + ( blue_inc * i ) ).toFixed(0) );
        }
        return( colors );
    }

    function get_pallet() {
        // Pallet based off of - http://everything2.com/index.pl?node_id=1127452
        var colors = new Array( 256 );
        colors = make_gradient( colors, 0, 0, 0, 0, 84, 252, 0, 0 );
        colors = make_gradient( colors, 85, 255, 0, 0, 107, 255, 66, 0 );
        colors = make_gradient( colors, 108, 255, 69, 0, 126, 255, 123, 0 );
        colors = make_gradient( colors, 127, 255, 126, 0, 131, 255, 137, 0 );
        colors = make_gradient( colors, 132, 255, 141, 0, 139, 255, 162, 0 );
        colors = make_gradient( colors, 140, 255, 165, 0, 156, 255, 213, 0 );
        colors = make_gradient( colors, 157, 255, 216, 0, 169, 255, 253, 0 );
        colors = make_gradient( colors, 170, 255, 255, 0, 244, 255, 255, 222 );
        colors = make_gradient( colors, 245, 255, 255, 225, 249, 255, 255, 237 );
        colors = make_gradient( colors, 250, 255, 255, 240, 255, 255, 255, 255 );
        return( colors );
    }

    function make_rect( args ) {
        var rect = document.createElementNS( SVG_NS, "polygon" );
        rect.setAttribute( "points", args.tl.x + ',' + args.tl.y + ' ' + args.tr.x + ',' + args.tr.y + ' ' +
                                     args.br.x + ',' + args.br.y + ' ' + args.bl.x + ',' + args.bl.y );
        return( rect );
    }

    function init() {
        var color = get_pallet();
        var height = 5;
        var width = 5;
        var x_seperation = width * 1.5;
        var y_seperation = width * 1.5;
        var canvas_height = 20;
        var canvas_width = 50;

        var x = 0;
        var real_x = 0;
        var screen = new Array( canvas_height );
        var screen_cp1 = new Array( canvas_height );
        var screen_blobs = new Array( canvas_height );
        for ( var i = 0; i < screen.length; i++ ) {
            screen[i] = new Array( canvas_width );
            screen_cp1[i] = new Array( canvas_width );
            screen_blobs[i] = new Array( canvas_width );
        }

        for ( var iy = 0; iy < screen_blobs.length; iy++ ) {
            for ( var ix = 0; ix < screen_blobs[0].length; ix++ ) {
                screen_blobs[iy][ix] = Math.round( 40 * Math.random() - 20 );
            }
        }

        while ( x <= ( x_seperation * ( canvas_width - 1 ) ) ) {
            var y = 0;
            var real_y = 0;
            while ( y <= ( y_seperation * ( canvas_height - 1 ) ) ) {
                if ( height != 0 ) {
                    var wrapper = make_rect( { tl: { x: x, y: y }, tr: { x: ( x + width ), y: y }, br: { x: ( x + width), y: ( y + height ) }, bl: { x: x, y: ( y + height ) }, real_x: real_x, real_y: real_y } );
                    screen[real_y][real_x] = wrapper;
                    document.getElementById( "top_level" ).appendChild( wrapper );
                }
                y += y_seperation;
                real_y++;
            }
            x += x_seperation;
            real_x++;
        }

        var start_fill = function() {
            for ( var x = 0; x < screen[0].length; x++ ) {
                screen_cp1[screen.length-1][x] = Math.round( 196 * Math.random() + 64 );
            }

            var rotate_blobs = screen_blobs[1];
            for ( var y = screen.length - 2; y > 0; y-- ) {
                screen_blobs[screen.length - ( y + 1 )] = screen_blobs[screen.length - ( y )];
                for ( var x = 0; x < screen[0].length; x++ ) {
                    tmp_color = Math.round( ( screen_cp1[y - 1][x - 1] + screen_cp1[y - 1][x] + screen_cp1[y - 1][x + 1] +
                                              screen_cp1[y][x - 1]                            + screen_cp1[y][x + 1] +
                                              screen_cp1[y + 1][x - 1] + screen_cp1[y + 1][x] + screen_cp1[y + 1][x + 1] ) >> 3 );
                    if ( y > ( screen.length - 8 ) ) {
                        tmp_color--;
                    }
                    if ( tmp_color > 30 ) {
                        tmp_color = tmp_color - screen_blobs[y][x];
                    } else if ( tmp_color > 255 ) {
                        tmp_color = 255;
                    }
                    screen_cp1[y][x] = ( tmp_color > 0 ) ? tmp_color : 0;
                    screen[y + 1][x].setAttribute( "fill", color[ screen_cp1[y][x] ] );
                }
            }
            screen_blobs[screen.length - 1] = rotate_blobs;
            setTimeout( start_fill, 0 );
        }
        setTimeout( start_fill, 0 );
    }

]]></script>

<g id="top_level" transform="translate(5, 5)" />
</svg>