Testing new psychedelic theme at GimpsterDotCom

Christmas is over, so it’s time to remove the red snowy background from GimpsterDotCom. But instead of using the normal blue color, I’m trying something new: a changing background color!

Each page start out with a blue background, but as people visit the page it slowly turns turquoise, green, yellow, red, purple and finally blue again. In other words, the color moves through the color-circle every time the page receives 360 hits. Funky isn’t it? :-)

To make it easy to change the color I made this little function to convert from the HSB (hue, saturation, brightness) color space to RGB (red, green, blue) which is what browsers understand:

function hsb2rgb($hue, $saturation, $brightness) {
    /* 0: minimum, +: rising, -: falling, 1: maximum. */
    $map = array(0 => array('1', '+', '0'),
                 1 => array('-', '1', '0'),
                 2 => array('0', '1', '+'),
                 3 => array('0', '-', '1'),
                 4 => array('+', '0', '1'),
                 5 => array('1', '0', '-'));

    /* Clip hue at 360: */
    $hue = $hue % 360;

    $i = floor($hue/60);
    $rgb = array();

    $min = 255 * $brightness/100 * (100-$saturation)/100;
    $max = 255 * $brightness/100;

    for ($color = 0; $color < 3; $color++) {
        switch($map[$i][$color]) {
        case ‘0′:
            $rgb[$color] = $min;
            break;
        case ‘1′:
            $rgb[$color] = $max;
            break;
        case ‘+’:
            $rgb[$color] = $min + ($hue % 60)/60 * ($max - $min);
            break;
        case ‘-’:
            $rgb[$color] = $max - ($hue % 60)/60 * ($max - $min);
            break;
        }
    }

    return $rgb;
}

I’ve figured out the conversion by looking at the sliders in the Gimp, so it could be wrong. Please correct it if you find a mistake… Credits go to DAIMI:~aveng (Lars Petersen) who got me started with this idea after showing me his nice PHP Imaging Lib.

Leave a comment