//***************************************************************
//** title : Dynamic CSS generation for multiple website colouring schemes.
//**
//** file : style.php
//**
//** story : Ever wanted to provide your user with buttons where from
//** he could change the colour scheme of the page ? Or even
//** provide deferent colour scheme each day, randomly or
//** depending on your mood (??). This script will show you
//** the basic idea of how to provide a php script which
//** will generate CSS on the fly.
//**
//** The idea is that given a single 24bit number representing
//** 3 8bit colour values (RGB) we can generate 10 shades based
//** on that desired colour. Then by using those 10 shades
//** we ensure that the site will have a uniform feel.
//**
//**
//** author : Ioannis Cherouvim
//** e-mail : morales@hack.gr
//** date : 2005-03-22
//***************************************************************
//the 24bit value representing the desired colour
$get_color = (isset($_GET["color"]) ? $_GET["color"] : "");
//some basic algorithm to extract the the RGB values
$r = ($get_color % 256)/2;
$g = (($get_color >> 8) % 256)/2;
$b = ((($get_color >> 8) >> 8) % 256)/2;
//simple algorithm to convert a 16bit dec to hex
function dec2hex16bit($dec) {
$digits = "0123456789ABCDEF";
return ($dec>-1 && $dec<256?$digits[$dec / 16].$digits[$dec % 16]:"XX");
}
//produces 10 shades of a 8bit value
function doGrad($c) {
for ($i = 0; $i < 10; $i++) $grad[$i] = dec2hex16bit(floor($c + ($i*(255-$c)/12)));
return $grad;
}
//concatenates the 8bit RGB hex values into a 24bit one
function appendGrads($r, $g, $b) {
for ($i = 0; $i < 10; $i++) $grad[$i] = $r[$i].$g[$i].$b[$i];
return $grad;
}
//***************************************************************
//** title : Dynamic CSS generation for multiple website colouring schemes.
//**
//** file : index.php. an example use of the style.php above
//**
//** author : Ioannis Cherouvim
//** e-mail : morales@hack.gr
//** date : 2005-03-22
//***************************************************************
$self = $_SERVER['PHP_SELF'];
echo "<html><head><style type='text/css'>";
include "style.php";
echo "</style><title>Dynamic CSS</title></head>";
echo "<body>";
echo "<table class='table1'>";
echo "<tr><th colspan='2'>Dynamic CSS - Click on buttons to change colors</th></tr>";
echo "<tr><td>";