0){
$m = $l + $l - $v;
$sv = ($v - $m ) / $v;
$h *= 6.0;
$sextant = floor($h);
$fract = $h - $sextant;
$vsf = $v * $sv * $fract;
$mid1 = $m + $vsf;
$mid2 = $v - $vsf;
switch ($sextant) {
case 0:
$r = $v; $g = $mid1; $b = $m;
break;
case 1:
$r = $mid2; $g = $v; $b = $m;
break;
case 2:
$r = $m; $g = $v; $b = $mid1;
break;
case 3:
$r = $m; $g = $mid2; $b = $v;
break;
case 4:
$r = $mid1; $g = $m; $b = $v;
break;
case 5:
$r = $v; $g = $m; $b = $mid2;
break;
}
}
// Convert from RGB values (0 .. 1) to hex (00 .. FF)
$color='#' .str_pad(dechex($r*256),2,'0',STR_PAD_LEFT)
.str_pad(dechex($g*256),2,'0',STR_PAD_LEFT)
.str_pad(dechex($b*256),2,'0',STR_PAD_LEFT);
return $color;
}
/** Generate a HTML test page with random text with random hex nonces injected that
* are can be colored with HTMLColorFingerprint()
*/
echo "
Can you spot which values are the same?
";
$plain = ($_REQUEST['plain'] == 1) ? 1 : 0;
$seed = intval($_REQUEST['seed']);
echo "Colors ";
echo $plain ? "on off" : "on off";
echo "
Seed";
for ($i=0;$i<20;$i++) {
if ($i==$seed)
echo " $seed";
else
echo $seeds[]=" $i";
}
mt_srand($seed); // Seed RNG so we always get the same output
$wordList=array('lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetuer', 'adipiscing', 'elit', 'aenean',
'commodo', 'ligula', 'eget', 'massa', 'cum', 'sociis', 'natoque', 'penatibus', 'et', 'magnis', 'dis',
'parturient', 'montes', 'nascetur', 'ridiculus', 'mus', 'donec', 'quam', 'felis', 'ultricies', 'nec');
// Generate $nrNonces nonces to be inserted at random locations in the text
$nrNonces=10;
$nonces=array();
for ($i=0;$i<$nrNonces;$i++) {
$value='';
for ($j = 0; $j < 10; $j++) {
$value .= str_pad(dechex(mt_rand(0, 255)), 2, '0', STR_PAD_LEFT);
}
$nonces[]=$value;
}
// Generate random paragraphs, sentences, phrases and words based on $wordList above and inject nonces
// from $nonces
$nrParagraphs=5; // Number of paragraphs to generate
$paragraphs=array();
for ($paragraph=0;$paragraph<$nrParagraphs;$paragraph++) {
$nrSentences = mt_rand(3, 7); // Number of sentences per paragraph
$sentences = array();
for ($sentence = 0; $sentence < $nrSentences; $sentence++) {
$nrPhrases = mt_rand(1, 5); // Number of phrases per sentence
$phrases = array();
for ($phrase = 0; $phrase < $nrPhrases; $phrase++) {
$nrWords = mt_rand(1, 10); // Number of words per phrase
$words = array();
$randWords = $wordList;
for ($word = 0; $word < $nrWords; $word++) {
$randWord = mt_rand(0, sizeof($randWords) - 1); // Choose random word
$words[] = $randWords[$randWord];
array_splice($randWords, $randWord,1); // Remove chosen word so we don't choose the same word twice in a phrase
}
if (mt_rand(0, 5)==0) {
// Insert a random nonce in the phrase
$value=$nonces[mt_rand(0, sizeof($nonces)-1)]; // Pick random nonce
$color=($_REQUEST['plain'] == 1) ? '#CCCCCC' : HTMLColorFingerprint($value);
$nonceHTML = "$value";
array_splice($words, mt_rand(0,sizeof($words)), 0, $nonceHTML);
}
$phrases[] = join(' ', $words);
}
$sentences[] = ucfirst(join(', ', $phrases));
}
echo ''.join('. ', $sentences).'.
';
}
echo "";