Вход Регистрация
Файл: concrete5.7.5.6/concrete/vendor/primal/color/lib/Primal/Color/RGBColor.php
Строк: 66
<?php 

namespace PrimalColor;

class 
RGBColor extends Color {
    public 
$red 0;
    public 
$green 0;
    public 
$blue 0;
    public 
$alpha 1;
    
    function 
__construct($r 0$g 0$b 0$a=1) {
        
$this->red   $r;
        
$this->green $g;
        
$this->blue  $b;
        
$this->alpha $a;
    }
    
    function 
toHSV() {
        
$r = ((int)$this->red   256) / 255;
        
$g = ((int)$this->green 256) / 255;
        
$b = ((int)$this->blue  256) / 255;
        
$a $this->alpha;
        
        
$max max($r$g$b);
        
$min min($r$g$b);
        
$d $max $min;

        
$h 0;
        
$s = ($max === 0) ? $d $max;
        
$v $max;
        
        if (
$max !== $min) {
            switch (
$max) {
            case 
$r:
                
$h = ($g $b) / $d + (($g $b) ? 0);
                break;
            case 
$g:
                
$h = ($b $r) / $d 2;
                break;
            case 
$b:
                
$h = ($r $g) / $d 4;
            }
            
$h $h 6;
        }
        
        return new 
HSVColor($h*360$s*100$v*100$a);
    }
    
    function 
toHSL() {
        
$r = ((int)$this->red   256) / 255;
        
$g = ((int)$this->green 256) / 255;
        
$b = ((int)$this->blue  256) / 255;
        
$a $this->alpha;
        
        
$max max($r$g$b);
        
$min min($r$g$b);
        
        
$l = ($max $min ) / 2;
        if (
$max === $min) {
            
$h $s 0;
        } else {
            
$d $max $min;
            
$s = ($l 0.5) ? ($d / (2-$max-$min)) : ($d / ($max $min));
            switch (
$max) {
            case 
$r:
                
$h = ($g $b) / $d + (($g $b) ? 0);
                break;
            case 
$g:
                
$h = ($b $r) / $d 2;
                break;
            case 
$b:
                
$h = ($r $g) / $d 4;
            }
            
$h $h 6;
        }
        
        return new 
HSLColor($h*360$s*100$l*100$a);
    }
    
    function 
toCMYK() {
        
$r = ((int)$this->red   256) / 255;
        
$g = ((int)$this->green 256) / 255;
        
$b = ((int)$this->blue  256) / 255;
        
$a $this->alpha;

        if (
$r === && $g === && $b===0) {
            return new 
CMYKColor(0,0,0,1);
        }

        
$k min($r$g$b);
        
$c = ($r $k) / ($k);
        
$m = ($g $k) / ($k);
        
$y = ($b $k) / ($k);
        
        return new 
CMYKColor($c*100$m*100$y*100$k*100$a);
    }
    
    function 
toRGB() {
        return clone 
$this;
    }
    
    function 
toCSS($alpha null) {
        return ((
$alpha === true || $this->alpha 1) && $alpha !== false) ? "rgba({$this->red}{$this->green}{$this->blue}{$this->alpha})" "rgb({$this->red}{$this->green}{$this->blue})";
    }
    
    function 
toHex() {
        
$stack = array('#');
        
$stack[] = str_pad(dechex(min(255round($this->red  ))), 2'0'STR_PAD_LEFT);
        
$stack[] = str_pad(dechex(min(255round($this->green))), 2'0'STR_PAD_LEFT);
        
$stack[] = str_pad(dechex(min(255round($this->blue ))), 2'0'STR_PAD_LEFT);
        
        return 
implode(''$stack);
    }
    
}
Онлайн: 1
Реклама