类似Windows调色板的PHP程序
    本程序可以生成一个类似Windows调色板网页,让客户端选择所需颜色,有很多地方可以用到这样的程序。其中的颜色算法不是很好,仅仅举个例子,各位可以自行设计算法。其中的blank.gif为一个完全透明的图片,随便做一个就可以了。

<?
  $cell_height
=10;
  
$cell_width=10;
  
$cell_height_n=24//3的倍数
  
$cell_width_n=32;
?>
<html>
<head>
<title>调色板</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="javascript"> //设置当前颜色
  function set_color(the_color)
  {
    document.color.current_color.value=the_color;
    return (false);
  }
</script>
</head>
<body bgcolor="#FFFFFF">
<?
  
echo "<table width=".$cell_width*$cell_width_n." border=1 cellspacing=0 cellpadding=0>n";
  for (
$i=0;$i<$cell_height_n;$i++)
  {
    echo 
"<tr height=".$cell_height.">n";
    for (
$j=0;$j<$cell_width_n;$j++)
    {
      if (
floor($i/($cell_height_n/3))==0)
      {
        if (
strlen(dechex($i*$cell_width_n+$j))==1)
        {
          
$back_color="00000".dechex($i*$cell_width_n+$j);
        }
        else
        {
          
$back_color="0000".dechex($i*$cell_width_n+$j);
        }
      }
      if (
floor($i/($cell_height_n/3))==1)
      {
        if (
strlen(dechex((($i-$cell_height_n/3)*$cell_width_n+$j)*256))==3)
        {
          
$back_color="000".dechex((($i-$cell_height_n/3)*$cell_width_n+$j)*256);
        }
        else
        {
          
$back_color="00".dechex((($i-$cell_height_n/3)*$cell_width_n+$j)*256);
        }
      }
      if (
floor($i/($cell_height_n/3))==2)
      {
        if (
strlen(dechex((($i-$cell_height_n*2/3)*$cell_width_n+$j)*256*256))==5)
        {
          
$back_color="0".dechex((($i-$cell_height_n*2/3)*$cell_width_n+$j)*256*256);
        }
        else
        {
          
$back_color=dechex((($i-$cell_height_n*2/3)*$cell_width_n+$j)*256*256);
        }
      }
      echo 
"<td width=".$cell_width." height=".$cell_height." bgcolor=#".$back_color."><a href=# onclick="return set_color('".$back_color."');"><img src=blank.gif border=0 width=".$cell_width." height=".$cell_height."></a></td>n";
    }
    echo 
"</tr>n";
  }
  echo 
"</table>n";
?>
<form name="color" >
当前颜色为<input type="text" name="current_color" size="6" maxlength="6">
</form>
</body>
</html>