示例#1
0
 /**
  * @param ColorInterface $baseColor
  * @return \Generator
  */
 protected function generate(ColorInterface $baseColor)
 {
     (yield $baseColor);
     (yield Color::complement($baseColor, 120));
     (yield Color::complement($baseColor, 180));
     (yield Color::complement($baseColor, -60));
 }
示例#2
0
文件: Palette.php 项目: talesoft/phim
 public static function getHtml(PaletteInterface $palette, $columns = null, $width = null, $height = null)
 {
     $html = '';
     foreach ($palette as $i => $color) {
         $html .= Color::getHtml($color, $width, $height);
         if ($columns !== null && ($i + 1) % $columns === 0) {
             $html .= '<br>';
         }
     }
     return $html;
 }
示例#3
0
 public function offsetSet($offset, $color)
 {
     $color = Color::get($color);
     if (!$color instanceof ColorInterface) {
         throw new RuntimeException("The color you passed to PaletteTrait->offsetSet() is not valid");
     }
     if ($offset === null) {
         $this->colors[] = $color;
     } else {
         $this->colors[$offset] = $color;
     }
 }
示例#4
0
 public function testFunctionStringConversion()
 {
     $c = Color::get('hsl(50%, 50%, 100%)')->getHsl();
     $this->assertEquals(180, $c->getHue());
     $c = Color::get('hsl(-180, 50%, 100%)')->getHsl();
     $this->assertEquals(180, $c->getHue());
     $c = Color::get('hsl(-150%, 50%, 100%)')->getHsl();
     $this->assertEquals(180, $c->getHue());
     $c = Color::get('hsl(150%, 50%, 100%)')->getHsl();
     $this->assertEquals(180, $c->getHue());
     $this->assertEquals(0.5, $c->getSaturation());
     $this->assertEquals(1.0, $c->getLightness());
     $c = Color::get('rgb(34.23%, 20%, 120)')->getRgb();
     $this->assertEquals(87, $c->getRed());
     $this->assertEquals(51, $c->getGreen());
     $this->assertEquals(120, $c->getBlue());
     $c = Color::get('hsla(0.872664626rad, .4, 90%, 22.3%)')->getHsla();
     $this->assertEquals(50, $c->getHue());
     $this->assertEquals(0.4, $c->getSaturation());
     $this->assertEquals(0.9, $c->getLightness());
     $this->assertEquals(0.223, $c->getAlpha());
 }
示例#5
0
文件: Color.php 项目: talesoft/phim
 public static function getHtml(ColorInterface $color, $width = null, $height = null)
 {
     $width = $width ?: 120;
     $height = $height ?: 120;
     $color = $color->getRgba();
     $inversed = self::inverse($color)->getRgba();
     $name = self::getName($color);
     $hue = $color->getHsl()->getHue();
     return sprintf('<div style="display: inline-block; vertical-align: middle; width: %dpx; height: %dpx; ' . 'background: %s; color: %s; font-size: 12px; font-family: Arial, sans-serif; ' . 'text-align: center; line-height: %dpx;">%s<br>%s<br>%s%s</div>', $width, $height, $color, $inversed, intval($height / 4), $color->getLab()->getRgb(), Color::getHexString($color->getRgb()), self::getHueRange($hue) . "->" . round($hue, 2), $name ? "<br>{$name}" : '');
 }
示例#6
0
    $color = color_get($hex);
    echo \Phim\color_get_html($color);
    $mc = new \Phim\Color\Scheme\HueRotationScheme($color, 20, 5);
    foreach ($mc as $compareColor) {
        echo '<div style="display: inline-block; vertical-align: top; text-align: center;">';
        echo \Phim\color_get_html($compareColor);
        echo '<br>';
        echo '<span style="padding: 10px;">' . \Phim\Color::getDifference($color, $compareColor) . '</span>';
        echo '</div>';
    }
    echo '<br>';
}
echo '</div>';
echo '<h1>Finding visually similar colors (Tolerance: ' . $t . ', control with &lt;url&gt;?t=&lt;tolerance&gt;)</h1>';
echo '<div style="white-space: nowrap;">';
foreach ($names as $name => $hex) {
    $color = color_get($hex);
    echo \Phim\color_get_html($color);
    foreach (\Phim\color_get_names() as $compareColor) {
        $deltaE = \Phim\Color::getDifference($color, color_get($compareColor));
        if ($deltaE < $t) {
            echo '<div style="display: inline-block; vertical-align: top; text-align: center;">';
            echo Phim\Color::getHtml(color_get($compareColor));
            echo '<br>';
            echo '<span style="padding: 10px;">' . $deltaE . '</span>';
            echo '</div>';
        }
    }
    echo '<br>';
}
echo '</div>';
示例#7
0
 protected function generateStep(ColorInterface $baseColor, $i, $step)
 {
     return Color::complement($baseColor, $i * $step);
 }
示例#8
0
 protected function generateStep(ColorInterface $baseColor, $i, $step)
 {
     return Color::lighten($baseColor, $i * $step);
 }
示例#9
0
 /**
  * SchemeBase constructor.
  * @param ColorInterface|string|int $baseColor
  */
 public function __construct($baseColor)
 {
     $this->baseColor = Color::get($baseColor);
     $colors = iterator_to_array($this->generate($this->baseColor));
     parent::__construct($colors, count($colors));
 }
示例#10
0
function color_get_html($color, $width = null, $height = null)
{
    return Color::getHtml(color_get($color), $width, $height);
}