/**
* @return float[]
*/
- public function toLottie()
+ public function toLottie($digits = 12, $regex = false)
{
// Lottie colors are decimal numbers between 0 (0) and 1 (255) rounded at 12 digits
- $digits = 12;
- return [round($this->_red, $digits), round($this->_green, $digits), round($this->_blue, $digits), round($this->_alpha, $digits)];
+ return [$this->_lottieRound($this->_red, $digits, $regex), $this->_lottieRound($this->_green, $digits, $regex), $this->_lottieRound($this->_blue, $digits, $regex), $this->_lottieRound($this->_alpha, $digits, $regex)];
}
+ protected function _lottieRound($n, $digits = 12, $regex = false)
+ {
+ $roundDigits = max(12, $digits);
+ $n = round($n, $roundDigits);
+ if ($roundDigits == $digits) {
+ return $n;
+ }
+ return substr((string)$n, 0, $digits + 2) . '\d*';
+ }
+
public function toHexRVB()
{
return $this->toHexComposante('red') . $this->toHexComposante('green') . $this->toHexComposante('blue');