This is some code I designed to generate a random color or test another color (hex values) against itself or against another. It also keeps a list of liked colors and descriptions and displays them on the side. It will then, upon pressing the compile button, put the codes in an array-friendly format for easy transportation to the file. I've left some of the colors in the array for display purposes. It also requires an empty file called colors.html (with correct permissions) to function (for list-saving to work). - Kate, webmaster@griflet.com
By : kate2587
<?php
$colors = array(
"D4D0B4" => "light tan",
"A69E5E" => "gold",
"666644" => "hunting brown",
"4E4439" => "less dark brown",
"3B3632" => "really dark brown",
"583324" => "dark brown",
"641504" => "brick red",
"7C0605" => "brick red",
);
?>
<html>
<head>
<style type="text/css">
table.show {border-width: 0; width: 300; height: 20; cellpadding: 10; font-weight: bold;}
body {font-family: 'Trebuchet MS', Verdana, 'Comic Sans MS';}
input {border-width: 1; border-color: black; background: white; color: black;}
td {text-valign: top;}
body , table , table.show {color: <?php echo $font_color; ?>;}
a {text-decoration: none; color: <?php if(isset($font_color)) {echo "$font_color";} if (empty($font_color)) {echo "black";} ?>;}
</style>
<title>Color Center</title>
</head>
<?php
foreach($GLOBALS as $varname => $value)
{$$varname = $value;}
//RANDOM
function random()
{
global $bgcolor;
$num[1] = rand(0,15);
$num[2] = rand(0,15);
$num[3] = rand(0,15);
$num[4] = rand(0,15);
$num[5] = rand(0,15);
$num[6] = rand(0,15);
foreach($num As $letter)
{
if ($letter == "10") {$letter = "A";}
elseif ($letter == "11") {$letter = "B";}
elseif ($letter == "12") {$letter = "C";}
elseif ($letter == "13") {$letter = "D";}
elseif ($letter == "14") {$letter = "E";}
elseif ($letter == "15") {$letter = "F";}
else {$letter = $letter;}
$bgcolor = $bgcolor . $letter
;}
return $bgcolor;
}
$file = "colors.html";
//ADD
if ($action == "add")
{
$fp = fopen($file,"a");
$toAdd = "<br>\"$added\" => \"$descrip\"";
fwrite($fp, $toAdd);
fclose($fp);
$bgcolor = $added;
}
//ERASE
if ($action == "erase")
{
$fp = fopen($file,"w");
fclose($fp);
$action = "random";
}
//COMPILE
if ($action == "compile")
{
if(empty($bgcolor)) {$bgcolor = "FFFFFF";}
if(empty($font_color)) {$font_color = "000000";}
}
function compile()
{
echo "<form><textarea cols='35' rows='5' wrap>";
$file_for_me = "colors.html";
$fp = fopen($file_for_me,"r");
$file_lines = fread($fp,"20000");
$lines = explode("<br>", $file_lines);
unset($lines[0]);
foreach ($lines As $spot)
{
$list = $list . "\n$spot, ";
}
echo "$list</textarea></form>";
}
//MORE ON RANDOM
if ($action == "random") {random();}
if (empty($font_color)) {$font_color = "000000";}
if (empty($bgcolor)) {$bgcolor = "FFFFFF";}
?>
<body bgcolor="#<?php echo $bgcolor; ?>">
<font color="#<?php echo $font_color; ?>">
<!--start table-->
<table border="0">
<tr><td width="300" valign="top">
<?php if ($action == "compile") {compile();} ?>
<script language="javascript">
function clear_em()
{
window.document.test_form.bgcolor.value = "";
window.document.test_form.font_color.value = "";
window.document.test_form.test_color.value = "";
}
</script>
<form action="<?php echo $PHP_SELF;?>" method="get" name="test_form">
<b>bgcolor</b> <input type="text" name="bgcolor" value="<?php echo $bgcolor; ?>"><br>
<b>font color</b> <input type="text" name="font_color" value="<?php echo $font_color; ?>"><br>
<b>test color</b> <input type="text" name="test_color" value="<?php echo $test_color; ?>"><br>
<input type="submit" value="test"> <input type="button" value="clear" onClick="clear_em()"><br>
</form>
<form action="<?php echo $PHP_SELF; ?>" method="get">
<input type="submit" value="random">
<input type="hidden" value="random" name="action">
</form>
<form action="<?php echo $PHP_SELF; ?>" method="get">
<b>add a color<br>
color code <input type="text" name="added" value="<?php echo $bgcolor;?>"><br>
description</b> <input type="text" name="descrip" value="<?php echo $descrip;?>"><br>
<input type="submit" value="add to list">
<input type="hidden" value="add" name="action">
</form>
<br>
<?php
echo "<b>background</b> = $bgcolor<br>";
echo "<b>text color</b> = $font_color<br><br>";
?>
<form action="<?php echo "$PHP_SELF"; ?>" method="get">
<input type="submit" value="original page">
</form>
<!--NEXT COLUMN-->
</td><td width="225" valign="top">
<b>List</b><br>
<?php
include "colors.html";
?>
<!--ERASE CONFIRM-->
<script language="javascript">
function erase_yesno()
{
if (confirm("Do you really want to erase the values?"))
{window.location.href="<?php echo "$PHP_SELF?action=erase";?>"}
else {window.location.href="<?php echo "$PHP_SELF?action=random";?>"};
}
</script>
<!--compile submit-->
<form action="<?php echo $PHP_SELF ?>" method="get">
<input type="submit" value="compile">
<input type="hidden" value="compile" name="action">
</form>
<!--erase submit-->
<form action="<?php echo $PHP_SELF ?>" method="get">
<input type="button" value="erase list" onClick="erase_yesno(); return erase_yesno;">
<input type="hidden" value="erase" name="action">
</form>
<!--write test?-->
<?php
if ($test_color != "")
{
echo("<table bgcolor=\"$test_color\" border='0' width='200' height='500'><tr><td><br> <br></td></tr></table>");
}
?>
<!--start new column-->
<td valign="top">
<?php
foreach($colors as $color => $def)
{ echo "<table class=\"show\" bgcolor=\"";
echo $color;
echo "\"><tr><td><a href=\"";
$path = "$PHP_SELF?bgcolor=$color&descrip=$def";
echo "$path\">$color - $def</a></td><td width='40'><a href=\"$PHP_SELF?bgcolor=$bgcolor&font_color=$font_color&test_color=$color\">test</a></td></tr></table><br>";
}
?>
</td></tr></table>
</font>
</body>
</html>
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.
More GUI Code Articles More By Codewalkers
Please enable JavaScript to view the comments powered by Disqus. blog comments powered by