<?php

/*
 * PHP Colour Picker Table Generator
 * Version 1.0 - February 2003
 * (c) 2002, Paul Gregg <pgregg@pgregg.com>
 * http://www.pgregg.com
 *
 * Function: Generate a HTML colour picker table
 *
 * Open Source Code:   If you use this code on your site for public
 * access (i.e. on the Internet) then you must attribute the author and
 * source web site: http://www.pgregg.com/projects/
 * You must also make this original source code available for download
 * unmodified or provide a link to the source.  Additionally you must provide
 * the source to any modified or translated versions or derivatives.
 *
 * Donations gratefully accepted at: http://www.pgregg.com/donate/
 *
 */


include $_SERVER['DOCUMENT_ROOT'] . "/inc/generatecolorrange.inc.php";

$Range 32//How many "steps" should we use to get from one colour to another

// Sanity check any supplied range - too large and your browser will suck
// all the memory you have.
if (isset($_GET['range']) && is_numeric($_GET['range'])) {
  
$Range $_GET['range'];
  if (
$Range 2$Range 2;
  if (
$Range 128$Range 128;
}

// Calculate the stepping required.
$step 256 $Range;
$stepw $step $Range;

print <<<EOSTYLE
<head><title>Colour Map by Paul Gregg: http://www.pgregg.com/projects/</title>
<style type="text/css">
TD {
    width: 
{$stepw}px;
    height: 
{$step}px;
    padding: 0pt;
    spacing: 0pt;
    margin: 20pt;
}
</style>
<div id="overDiv" style="position:absolute; visibility:hide; z-index:1;"></div>
<script LANGUAGE="JavaScript" SRC="/inc/overlib.js"></script>
</head>
<body>
EOSTYLE;


#print "<pre>"; print_r($Xcolours); print_r($Ycolours); print "</pre><hr>\n";


// Display a rough RBG table based of White and Black
print "<table cellpadding=0 cellspacing=0 border=0>\n";
print 
"<tr>\n";
// Display HTML for White, Red, Green, Blue
print "<td>\n";
$XYstart = array (255255255);
$Xend = array (25500);
$Yend = array (02550);
$XYend = array (00255);
print 
GenHTMLColours($XYstart$Xend$Yend$XYend$Range);
print 
"</td>\n";
// Display HTML for Black, Red, Green, Blue
print "<td>\n";
$XYstart = array (000);
$Xend = array (25500);
$Yend = array (02550);
$XYend = array (00255);
print 
GenHTMLColours($XYstart$Xend$Yend$XYend$Range);
print 
"</td>\n";
print 
"</tr>\n";
print 
"</table>\n";


print 
"<hr>\n";


// Now lets work out a more complex arrangement of coloured squares

print "<table cellpadding=0 cellspacing=0 border=0>\n";

// Red base
print "<tr>\n";

// Display HTML for Yellow, Green, Red, White
print "<td>\n";
$XYstart = array (2552550);
$Xend = array (02550);
$Yend = array (25500);
$XYend = array (255255255);
print 
GenHTMLColours($XYstart$Xend$Yend$XYend$Range);
print 
"</td>\n";

// Display HTML for Green, Cyan. White, Blue
print "<td>\n";
$XYstart = array (02550);
$Xend = array (0255255);
$Yend = array (255255255);
$XYend = array (00255);
print 
GenHTMLColours($XYstart$Xend$Yend$XYend$Range);
print 
"</td>\n";

print 
"</tr>\n";



print 
"<tr>\n";
// Red, White, Magenta, Grey
print "<td>\n";
$XYstart = array (25500);
$Xend = array (255255255);
$Yend = array (2550255);
$XYend = array (127127127);
print 
GenHTMLColours($XYstart$Xend$Yend$XYend$Range);
print 
"</td>\n";

// White, Blue, Grey, Magenta
print "<td>\n";
$XYstart = array (255255255);
$Xend = array (00255);
$Yend = array (127127127);
$XYend = array (2550255);
print 
GenHTMLColours($XYstart$Xend$Yend$XYend$Range);
print 
"</td>\n";

print 
"</tr>\n";



print 
"<tr>\n";
//Magenta, Grey, Blue, Black
print "<td>\n";
$XYstart = array (2550255);
$Xend = array (127127127);
$Yend = array (00255);
$XYend = array (000);
print 
GenHTMLColours($XYstart$Xend$Yend$XYend$Range);
print 
"</td>\n";

//Grey, Magenta, Black, Red
print "<td>\n";
$XYstart = array (127127127);
$Xend = array (2550255);
$Yend = array (000);
$XYend = array (25500);
print 
GenHTMLColours($XYstart$Xend$Yend$XYend$Range);
print 
"</td>\n";

print 
"</tr>\n";



print 
"<tr>\n";
// Blue, Black, Cyan, Green
print "<td>\n";
$XYstart = array (00255);
$Xend = array (000);
$Yend = array (0255255);
$XYend = array (02550);
print 
GenHTMLColours($XYstart$Xend$Yend$XYend$Range);
print 
"</td>\n";

// Black, Red. Green, Yellow
print "<td>\n";
$XYstart = array (000);
$Xend = array (25500);
$Yend = array (02550);
$XYend = array (2552550);
print 
GenHTMLColours($XYstart$Xend$Yend$XYend$Range);
print 
"</td>\n";

print 
"</tr>\n";


print 
"</table>\n";

exit;


Function 
GenHTMLColours($XYstart$Xend$Yend$XYend$Range) {
    
#list ($x1, $x2, $x3) = $Xend;
    #list ($y1, $y2, $y3) = $Yend;
    #$XYend = array ($x1|$y1, $x2|$y2, $x3|$y3);
    
    
$Xcolours GenerateColourRange($XYstart$Xend$Range);
    
$Ycolours GenerateColourRange($XYstart$Yend$Range);
    
$XXYcolours GenerateColourRange($Xend$XYend$Range);
    
$YXYcolours GenerateColourRange($Yend$XYend$Range);
    
    
$output "<table cellpadding=0 cellspacing=0 border=0>\n";
    
$row 0;
    foreach (
$Ycolours as $Ycolour) {
        
$output .= " <tr>\n";
        
$Xleft $Ycolours[$row];
        
$Xright $XXYcolours[$row];
        
$RowColours GenerateColourRange($Xleft$Xright$Range);
        foreach (
$RowColours as $RowColour) {
          
$r hexdec(substr($RowColour,1,2));
          
$g hexdec(substr($RowColour,3,2));
          
$b hexdec(substr($RowColour,5,2));
            
$mouseovertext HTML_JS_Safe("Hex: $RowColour\nRGB: $r,$g,$b");
            
$output .= "  <td bgcolor='$RowColour' onmouseover=\"drc_vauto('$mouseovertext','Colour'); return true;\" onmouseout=\"nd(); return true;\"></td>\n";
        }
        
$output .= " </tr>\n";
        
$row++;
    }
    
$output .= "</table>\n";
    return 
$output;
}

Function 
HTML_JS_Safe($colvalue) {
        
$cr chr(13);
        
$colvalue preg_replace("/$cr/"""$colvalue);

        
$colvalue str_replace("&"'&#38;'$colvalue);
        
$colvalue str_replace("<"'&#60;'$colvalue);
        
$colvalue str_replace(">"'&#62;'$colvalue);
        
$colvalue str_replace("/"'&#47;'$colvalue);
        
$colvalue preg_replace("/\'/""&#39;"$colvalue);
        
$colvalue preg_replace("/\"/""&#34;"$colvalue);
        
$colvalue str_replace("\\"''$colvalue);
        
$colvalue str_replace("("'&#40;'$colvalue);
        
$colvalue str_replace(")"'&#41;'$colvalue);
        
$colvalue str_replace("@"'&#64;'$colvalue);
        
$colvalue str_replace("{"'&#123;'$colvalue);
        
$colvalue str_replace("}"'&#125;'$colvalue);
        
$colvalue preg_replace("/\n/""<br>"$colvalue);
        
$colvalue htmlspecialchars($colvalue);
        return 
$colvalue;
}
?>