/** * Run a test, send multiple generated colors through the $this->textColor() method * * Tests the integrety of the property update system in the color class * * @param object $color Color object * @param integer $strength lower the number, the more colors generated thus more powerful test * @param boolean $test_order see $this->textColor() * @see $this->textColor() * @return array test results */ public function test(Color $color, $strength = 20, $test_order = false) { set_time_limit(600); $pass = $fail = 0; $errors = array(); for ($r = 0; $r <= 255; $r = $r + $strength) { for ($g = 0; $g <= 255; $g = $g + $strength) { for ($b = 0; $b <= 255; $b = $b + $strength) { $color = Color::create(array('red' => $r, 'green' => $g, 'blue' => $b)); $result = $this->textColor($color, $test_order); if (true === $result) { $pass++; } else { $fail++; $errors[] = $result; } } } } return array('passes' => $pass, 'fails' => $fail, 'errors' => $errors); }
$color5->hue = 300; $color5->lightness = $color5->saturation = 0.5; $color4->dump(); $color5->dump(); //Sync the properties of color5 to color4 $color4->sync($color5); $color4->dump(); echo '<h2>Bulk update</h2>'; $color6 = Color::create(); $color6->bulkUpdate(array('hue' => 40, 'saturation' => 0.7, 'lightness' => 0.2)); $color6->dump(); echo '<h2>toString</h2>'; $color7 = Color::create(array('hue' => 40, 'saturation' => 0.7, 'lightness' => 0.2)); echo $color7; echo '<h2>Using color tools</h2>'; $color8 = Color::create(array('red' => 90, 'green' => 50, 'blue' => 20)); $color8->dump(); echo '<p>'; echo 'color is light: ' . var_export($color8->isLight(), true); echo '<br>'; echo 'color is dark: ' . var_export($color8->isDark(), true); echo '</p>'; $color8->lighten(60); $color8->dump(); echo '<p>'; echo 'color is light: ' . var_export($color8->isLight(), true); echo '<br>'; echo 'color is dark: ' . var_export($color8->isDark(), true); echo '</p>'; $color9 = $color8->copy()->getComplementary(); echo '<p>complementary</p>';
protected function getRandomColor($username) { $hash = md5($username . $this->salt++); $hex = substr($hash, -6); return Color::create(compact('hex')); }