/** * @param int $value * @return $this */ public function withValue($value) { $color = clone $this; $color->value = MathUtil::capValue($value, 0.0, 1.0); return $color; }
/** * @param int $saturation * @return $this */ public function withSaturation($saturation) { $color = clone $this; $color->saturation = MathUtil::capValue($saturation, 0.0, 1.0); return $color; }
public function __construct($red, $green, $blue) { $this->red = MathUtil::capValue($red, 0, 255); $this->green = MathUtil::capValue($green, 0, 255); $this->blue = MathUtil::capValue($blue, 0, 255); }
public function __construct($hue, $saturation, $lightness) { parent::__construct($hue, $saturation); $this->lightness = MathUtil::capValue($lightness, 0.0, 1.0); }
/** * @param float $alpha * @return $this */ public function withAlpha($alpha) { $color = clone $this; $color->alpha = MathUtil::capValue($alpha, 0.0, 1.0); return $color; }
public function divideArray(array $xy) { list($x, $y) = PointUtil::parseArray($xy); if ($x) { MathUtil::validateDivisor($x); $this->x /= $x; } if ($y) { MathUtil::validateDivisor($y); $this->y /= $y; } return $this; }
public function __construct($x, $y, $z) { $this->x = MathUtil::capValue($x, 0, self::REF_X); $this->y = MathUtil::capValue($y, 0, self::REF_Y); $this->z = MathUtil::capValue($z, 0, self::REF_Z); }
public function withDividedArray(array $xy) { list($x, $y) = PointUtil::parseArray($xy); $point = clone $this; if ($x) { MathUtil::validateDivisor($x); $point->withDividedX($x); } if ($y) { MathUtil::validateDivisor($y); $point->withDividedY($y); } return $point; }
/** * @param int $lightness * @return $this */ public function withLightness($lightness) { $color = clone $this; $color->lightness = MathUtil::capValue($lightness, 0.0, 1.0); return $color; }
/** * @param int $z * @return $this */ public function withZ($z) { $color = clone $this; $color->z = MathUtil::capValue($z, 0, 100); return $color; }
/** * @param int $b * @return $this */ public function withB($b) { $color = clone $this; $color->b = MathUtil::capValue($b, -128, 127); return $color; }
public function __construct($hue, $saturation, $value) { parent::__construct($hue, $saturation); $this->value = MathUtil::capValue($value, 0.0, 1.0); }
public function __construct($red, $green, $blue, $alpha) { parent::__construct($red, $green, $blue); $this->alpha = MathUtil::capValue($alpha, 0.0, 1.0); }
public function __construct($hue, $saturation, $value, $alpha) { parent::__construct($hue, $saturation, $value); $this->alpha = MathUtil::capValue($alpha, 0.0, 1.0); }
/** * @param int $blue * @return $this */ public function withBlue($blue) { $color = clone $this; $color->blue = MathUtil::capValue($blue, 0, 255); return $color; }
public static function parseFunctionString($string) { if (!preg_match(self::FUNCTION_REGEX, $string, $matches)) { return null; } $function = $matches[1]; $args = array_map('trim', explode(',', $matches[2])); if (!isset(self::$functions[$function])) { return new NonExistentFunctionNameException("Color function {$function} is not registered"); } $className = self::$functions[$function]['className']; $argDefs = self::$functions[$function]['args']; if (count($args) !== count($argDefs)) { throw new RuntimeException(sprintf("Invalid argument count for {$function}: Expected %d values, got %d values", count($argDefs), count($args))); } $args = array_map(function ($value, $arg) { return MathUtil::convertValue($value, $arg['type'], $arg['base'], isset($arg['rotate']) && $arg['rotate']); }, $args, $argDefs); $reflect = new \ReflectionClass($className); return $reflect->newInstanceArgs($args); }
public function __construct($hue, $saturation) { $this->hue = MathUtil::rotateValue($hue, 360); $this->saturation = MathUtil::capValue($saturation, 0.0, 1.0); }