Micaela's Build Your Color Palette
CODE FOLLOWS
<?php
include('../includes/header.php');
error_reporting(E_ALL); // set error reporting to all
// form for selecting palette colors
?>
<h1>Micaela's Build Your Color Palette</h1>
<form method="post">
Cold Tone:
<select name="cold">
<option>Blue</option>
<option>Teal</option>
<option>Cyan</option>
<option>Navy</option>
</select>
<br><br>
Warm Tone:
<select name="warm">
<option>Orange</option>
<option>Gold</option>
<option>Coral</option>
<option>Amber</option>
</select>
<br><br>
Hot Tone:
<select name="hot">
<option>Red</option>
<option>Crimson</option>
<option>Scarlet</option>
<option>Ruby</option>
</select>
<br><br>
Pastel Tone:
<select name="pastel">
<option>Pink</option>
<option>Mint</option>
<option>Lavender</option>
<option>Peach</option>
</select>
<br><br>
<input type="submit" name="submit" value="Submit">
<br><br>
<input type="submit" name="random" value="Random">
<br><br>
</form>
<?php
// map color names to some hex color values
$colorMap = array(
"Blue" => "#4716FC",
"Teal" => "teal",
"Cyan" => "#3BB5C2",
"Navy" => "#4980C9",
"Orange" => "#E77A3B",
"Gold" => "#D09B22",
"Coral" => "#D5829F",
"Amber" => "#800D35",
"Red" => "#FF0000",
"Crimson" => "#850000",
"Scarlet" => "#C20000",
"Ruby" => "#B50A0A",
"Pink" => "#D30090",
"Mint" => "#67AEA7",
"Lavender" => "#B372E1",
"Peach" => "#FF4076"
);
// handles palette submission
if (isset($_POST['submit']))
{
$cold = $_POST['cold'];
$warm = $_POST['warm'];
$hot = $_POST['hot'];
$pastel = $_POST['pastel'];
$palette = array($cold, $warm, $hot, $pastel); // store selected colors in an array
echo "<h2>Your Color Palette</h2>";
echo "<pre>";
print_r($palette); // prints results
echo "</pre>";
echo "<h3>Palette Preview</h3>";
foreach ($palette as $color)
{
$bg = $colorMap[$color]; // calls color map
echo "<div style='
display:inline-block;
width:80px;
height:80px;
background:$bg;
margin:5px;
border-radius:10px;
border:2px solid #444;
text-align:center;
line-height:80px;
color:#f6ffff;
font-weight:bold;
box-shadow: 0 2px 6px rgba(0,0,0,0.3);
'>$color</div>";
}
echo "<br><br>";
echo "<form method='get'>";
echo "<button type='submit'>Try Again</button>";
echo "<br><br>";
echo "</form>";
}
// generate a random palette
if (isset($_POST['random']))
{
$cold = array("Blue","Teal","Cyan","Navy");
$warm = array("Orange","Gold","Coral","Amber");
$hot = array("Red","Crimson","Scarlet","Ruby");
$pastel = array("Pink","Mint","Lavender","Peach");
$palette = array(
$cold[array_rand($cold)],
$warm[array_rand($warm)],
$hot[array_rand($hot)],
$pastel[array_rand($pastel)]
);
echo "<h2>Your Random Color Palette</h2>";
echo "<pre>";
print_r($palette);
echo "</pre>";
echo "<h3>Palette Preview</h3>";
foreach ($palette as $color)
{
$bg = $colorMap[$color];
echo "<div style='
display:inline-block;
width:80px;
height:80px;
background:$bg;
margin:5px;
border-radius:10px;
border:2px solid #444;
text-align:center;
line-height:80px;
color:#f6ffff;
font-weight:bold;
box-shadow: 0 2px 6px rgba(0,0,0,0.3);
'>$color</div>";
}
echo "<br><br>";
echo "<form method='get'>";
echo "<button type='submit'>Try Again</button>";
echo "<br><br>";
echo "</form>";
}
include('../includes/footer.php');
?>