Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Intended to work with http://colorschemedesigner.com with Tetrad OR Accented Analogic schemes
- * UPDATE: works with any type of scheme:
- * http://students.washington.edu/kuksenok/colors/ColorScheme.php?demo&scheme=three
- * http://students.washington.edu/kuksenok/colors/ColorScheme.php?demo&scheme=two
- *
- * Any scheme can be made "dark" rather than "light" by including the "dark" flag
- * eg: http://students.washington.edu/kuksenok/colors/ColorScheme.php?demo
- * http://students.washington.edu/kuksenok/colors/ColorScheme.php?demo&scheme=billow
- * http://students.washington.edu/kuksenok/colors/ColorScheme.php?demo&scheme=billow&dark
- */
- class ColorScheme {
- private $colors = array();
- private $inverse = false;
- public function __construct($txtdef, $dark=false) {
- $this->inverse = $dark;
- $sections = explode("*** ", file_get_contents($txtdef));
- $types = array("P", "A", "B", "C");
- for ($i = 1; $i <= 4; $i++) {
- $variations = explode("\n", $sections[$i]);
- $arr = array();
- for ($j = 2; $j <= 6; $j++) {
- $bits = explode(" = ", trim($variations[$j]));
- $arr[] = array($bits[1], explode(",", substr($bits[2], 4, -1)));
- }
- usort($arr, 'ColorScheme::ccompare');
- $this->colors[$types[$i - 1]] = $arr;
- }
- $grays = array("0", 0, "3", 51, "6", 102, "9", 153, "C", 204, "F", 255);
- $this->colors["_"] = array();
- for ($i = 0; $i < count($grays); $i+=2) {
- $hex = "#";
- while (strlen($hex) < 7)
- $hex.=$grays[$i];
- $this->colors["_"][] = array($hex, array($grays[$i + 1], $grays[$i + 1], $grays[$i + 1]));
- }
- }
- public function rand_rgb() {
- return $this->rand("none", 1, null);
- }
- public function rand_hex() {
- return $this->rand("none", 0, null);
- }
- public function rand_shade_hex($whichColor="_") {
- return $this->rand("which", 0, $whichColor);
- }
- public function rand_color_hex($whichShade=2) {
- return $this->rand("shade", 0, $whichShade);
- }
- public function rand_shade_rgb($whichColor="_") {
- return $this->rand("which", 1, $whichColor);
- }
- public function rand_color_rgb($whichShade=2) {
- return $this->rand("shade", 1, $whichShade);
- }
- private function rand($fix, $type, $fixpoint=null) {
- $types = array("P", "A", "B", "C", "_");
- $which = $fix == "which" ? $fixpoint : $types[rand(0, count($this->colors) - 1)];
- $shade = $fix == "shade" ? $fixpoint : rand(0, count($this->colors[$which]) - 1);
- return $this->get($type, $which, $shade);
- }
- public function rgb($which="_", $shade=2) {
- return $this->get(1, $which, $shade);
- }
- public function hex($which="_", $shade=2) {
- return $this->get(0, $which, $shade);
- }
- private function get($type, $which="_", $shade=2) {
- if (!isset($this->colors[$which]))
- $which = "_";
- if (!isset($this->colors[$which][$shade]))
- $shade = 2;
- if ($this->inverse) {
- $shade = count($this->colors[$which]) - $shade - 1;
- }
- return $this->colors[$which][$shade][$type];
- }
- public static function ccompare($x, $y) {
- $diff = 0;
- for ($i = 0; $i < 3; $i++) {
- $diff += (int) $x[1][$i] - (int) $y[1][$i];
- }
- return $diff;
- }
- public function __toString() {
- $out = "";
- $types = array("Primary", "Secondary A", "Secondary B", "Complementary", "Grayscale");
- $stypes = array("P", "A", "B", "C", "_");
- for ($i = 0; $i < count($stypes); $i++) {
- $out.= "<h3>" . $types[$i] . ": ";
- foreach ($this->colors[$stypes[$i]] as $color) {
- $out.= "<span style=\"color:" . $color[0] . "\"><strong>w</strong></span>";
- }
- $out.="</h3>\n";
- }
- return $out;
- }
- }
- if (isset($_REQUEST['demo'])) {
- $txtdef = "colors/" . (isset($_REQUEST['scheme']) ? $_REQUEST['scheme'] . ".scheme" : "billow.scheme");
- $cs = new ColorScheme($txtdef, isset($_REQUEST['dark']));
- $names = array("P" => "primary", "A" => "secondary-a", "B" => "secondary-b", "C" => "complement", "_" => "gscale");
- ?>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
- "http://www.w3.org/TR/html4/strict.dtd">
- <html>
- <head>
- <meta http-equiv="content-type" content="text/html; charset=utf-8">
- <title>Color Palette by Color Scheme Generator</title>
- <meta name="generator" content="ColorSchemeGenerator.com">
- <style type="text/css">
- /* Palette color codes */
- /* Feel free to copy&paste color codes to your application */
- <?php
- foreach (array_keys($names) as $which) {
- for ($i = 0; $i < 6; $i++) {
- if ($i == 5 && $which != "_")
- continue;
- echo "." . $names[$which] . "-" . ($i + 1) . " { background-color: " . $cs->hex($which, $i) . " }\n";
- }
- }
- ?>
- /* end */
- body {
- margin:0; padding: 2em;
- background:white;
- color: #666;
- font: 75%/1.33 Verdana, sans-serif;
- text-align:left;
- }
- h1 {
- margin: 0.5em 0;
- font-size: 200%;
- }
- p {
- margin: 0.5em 0;
- }
- .color-table {
- margin: 2em 2em 5em;
- border-collapse:collapse;
- border:none;
- border-spacing:0;
- font-size:100%;
- }
- .color-table th {
- padding: 0 1em 0 0;
- text-align:right;
- vertical-align: middle;
- font-size:110%;
- border: none;
- }
- .color-table td.sample {
- width:10em; height:8em;
- padding: 10px;
- text-align:center;
- vertical-align:middle;
- font-size:90%;
- border: 1px solid white;
- white-space:nowrap;
- }
- .color-table.small td.sample {
- width:6em; height:6em;
- padding:0;
- border:none;
- }
- .color-table .white { margin-bottom:0.2em; color:white }
- .color-table .black { margin-top:0.2em; color:black }
- hr {
- border:none;
- border-bottom:1px solid silver;
- }
- #footer {
- padding:1em;
- font-size:80%;
- }
- </style>
- </head>
- <body>
- <h1><a href="<?php echo $txtdef; ?>"><?php echo $txtdef; ?></a></h1>
- <table class="color-table small">
- <?php
- foreach (array_keys($names) as $which) {
- echo " <tr>\n";
- echo " <th>" . $names[$which] . "</th>";
- for ($i = 0; $i < 6; $i++) {
- if ($i == 5 && $which != "_")
- continue;
- echo " <td class=\"sample " . $names[$which] . "-" . ($i + 1) . "\"><span style=\"padding:5px;color:#dddddd;background-color:#333333;border:dotted 1px #ffffff;\">" . $which . $i . "</span></td>\n";
- }
- }
- ?>
- </table>
- <p id="footer">Color scheme [probably], and some of the code for this page, originally from <a href="http://colorschemedesigner.com">Color Scheme Designer</a> © Petr Stanicek 2002-2010</p>
- </body>
- </html>
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement