Esempio n. 1
0
 /**
  * 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);
 }
Esempio n. 2
0
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>';
$color9->dump();
echo '<p>CSS Gradient</p>';
print_r($color9->getCssGradient());
echo '<h2>Using color formatter</h2>';
$color10 = Color::load('rgba(20, 40, 200, 0.8);');
$color10->dump();
echo 'HSL: ' . $color10->getHslaString() . '<br>';
$color11 = Color::load('#ccc');
$color11->dump();
echo 'RGB: ' . $color11->getRgbString();
?>

            </section>

        </div>

    </body>

</html>
Esempio n. 3
0
 /**
  * Loads a color object from a hsl or hsla string
  *
  * @param object $color Color object
  * @param mixed
  * @return object Color object
  */
 public function loadHslString(Color $color, $subject)
 {
     $subject = trim($subject);
     $subject = str_replace(array('hsla', 'hsl', '(', ')', ';', ' '), '', $subject);
     $hslnum = explode(',', $subject);
     if (count($hslnum) !== 3 && count($hslnum) !== 4) {
         return false;
     }
     foreach ($hslnum as &$val) {
         $val = floatval(trim($val));
     }
     $hsl = array('hue' => $hslnum[0], 'saturation' => $hslnum[1], 'lightness' => $hslnum[2]);
     if (isset($hslnum[3])) {
         $hsl['alpha'] = $hslnum[3];
     }
     $color->bulkUpdate($hsl);
     return $color;
 }
Esempio n. 4
0
 protected function getRandomColor($username)
 {
     $hash = md5($username . $this->salt++);
     $hex = substr($hash, -6);
     return Color::create(compact('hex'));
 }