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.= "

" . $types[$i] . ": "; foreach ($this->colors[$stypes[$i]] as $color) { $out.= "w"; } $out.="

\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"); ?> Color Palette by Color Scheme Generator

\n"; echo " "; for ($i = 0; $i < 6; $i++) { if ($i == 5 && $which != "_") continue; echo " \n"; } } ?>
" . $names[$which] . "" . $which . $i . "