<html>
<head>
<title>Do these colors match?</title>
<style type="text/css">
body {
background-color: #7F7F7F;
color: #662933;
};
a:link {
color: #00007F;
};
a:visited {
color: #00007F;
};
a:active {
color: #7F007F;
};
</style>
</head>
<body>
<?PHP
/*
* Collect input for generating a neural network to determine whether color
* combinations are aesthetically pleasing
*
* Copyright (C) 2008 Gregor Richards
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
function reqHas($i) {
return in_array($i, array_keys($_REQUEST));
}
if (reqHas("s")) {
if (!file_exists("data/matches")) {
$h = fopen("data/matches", "w");
if ($h === false) {
print "Error"; exit(1);
}
fclose($h);
}
// lock the output file ...
if (reqHas("y") || reqHas("n")) {
$yn = 0;
if (reqHas("y")) {
$yn = 1;
}
$h = fopen("data/matches", "a");
flock($h, LOCK_EX);
fwrite($h,
intval($_REQUEST["r1"]) . " " .
intval($_REQUEST["g1"]) . " " .
intval($_REQUEST["b1"]) . " " .
intval($_REQUEST["r2"]) . " " .
intval($_REQUEST["g2"]) . " " .
intval($_REQUEST["b2"]) . " " .
$yn . "\n");
fclose($h);
print "Your rating has been tallied.";
}
}
print "<br/>";
function prependZ($s, $l) {
while (strlen($s) < $l) {
$s = "0" . $s;
}
return $s;
}
function colorToRGB($c) {
return
"#" .
prependZ(dechex($c[0]), 2) .
prependZ(dechex($c[1]), 2) .
prependZ(dechex($c[2]), 2);
}
$c1 = array(mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
$c2 = array(mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
$c1h = colorToRGB($c1);
$c2h = colorToRGB($c2);
print "<h1>Do these colors go together?</h1>" .
"<table cellspacing='0' align='center'>";
for ($y = 0; $y < 5; $y++) {
print "<tr>";
for ($x = 0; $x < 5; $x++) {
print "<td style='width: 3em; height: 3em; background-color: ";
if (($x + $y) % 2 == 0) {
print $c1h;
} else {
print $c2h;
}
print "'> </td>";
}
print "</tr>";
}
print "</table><br/>";
?>
<form action='index.php' method='post' style='text-align: center'>
<input type='hidden' name='s' value='1'/>
<input type='hidden' name='r1' value='<?PHP print $c1[0]; ?>'/>
<input type='hidden' name='g1' value='<?PHP print $c1[1]; ?>'/>
<input type='hidden' name='b1' value='<?PHP print $c1[2]; ?>'/>
<input type='hidden' name='r2' value='<?PHP print $c2[0]; ?>'/>
<input type='hidden' name='g2' value='<?PHP print $c2[1]; ?>'/>
<input type='hidden' name='b2' value='<?PHP print $c2[2]; ?>'/>
<input type='submit' name='n' accesskey='a' value='No'/>
<input type='submit' name='y' accesskey='s' value='Yes'/>
<input type='submit' name='u' accesskey='d' value="Can't decide"/>
</form>
</body>
</html>