1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
<html><head>
<style>
td {
font-size: 12px;
font-family: monospace;
text-align: center;
padding-left: 3px;
padding-right: 3px
}
td.bright { color: #eee; }
td.dark { color: #222; }
</style>
</head>
<body>
<table>
<?
# we create a 9x9 table selecting a different background for each cell
for {set i 0} { $i < 9 } {incr i} {
puts "<tr>"
for {set j 0} {$j < 9} {incr j} {
set r [expr int(255 * ($i + $j) / 16)]
set g [expr int(255 * (8 + $j - $i) / 16)]
set b [expr int(255 * (abs (4 - $i) + abs(4 - $j)) / 8)]
# determining the background luminosity (YIQ space of NTSC) and choosing
# the foreground color accordingly in order maintain maximum contrast
if { [expr ($r*0.29894)+($g*0.58704)+($b*0.11402)] > 148.0} {
set cssclass "dark"
} else {
set cssclass "bright"
}
set cell [format "%3d %3d %3d" $r $g $b]
puts [format \
"<td bgcolor=\"%02x%02x%02x\" class=\"%s\">%s</td>" \
$r $g $b $cssclass $cell]
}
puts "</tr>"
}
?>
</table>
</body></html>
|