Skip to content

Commit

Permalink
change aliases in colori.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Remiscan committed Feb 11, 2020
1 parent f2aba9e commit f524466
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions colori.php
Original file line number Diff line number Diff line change
Expand Up @@ -846,4 +846,48 @@ public function change($propriete, $valeur, $remplace = false) {
else
return new Couleur($nouvelleCouleur->rgb());
}

// change() aliases
public function complement() {
return $this->change('h', 180);
}

public function negative() {
return $this->change('r', 255 * (1 - $this->r), true)
->change('g', 255 * (1 - $this->g), true)
->change('b', 255 * (1 - $this->b), true);
}

// options : {scale: true/false}
public function darken($value, $options = null) {
if ($options === null) $options = new stdClass();
$scale = ($options === true) || (property_exists($options, 'scale') ? $options['scale'] : false);
$newValue = ($scale == true) ? ($this->l * (100 - floatval($value))) . '%'
: -1 * floatval($value) . '%';
return $this->change('l', $newValue, $scale);
}

public function lighten($value, $options = null) {
if ($options === null) $options = new stdClass();
$scale = ($options === true) || (property_exists($options, 'scale') ? $options['scale'] : false);
$newValue = ($scale == true) ? ($this->l * (100 + floatval($value))) . '%'
: floatval($value) . '%';
return $this->change('l', $newValue, $scale);
}

public function desaturate($value, $options = null) {
if ($options === null) $options = new stdClass();
$scale = ($options === true) || (property_exists($options, 'scale') ? $options['scale'] : false);
$newValue = ($scale == true) ? ($this->s * (100 - floatval($value))) . '%'
: -1 * floatval($value) . '%';
return $this->change('s', $newValue, $scale);
}

public function saturate($value, $options = null) {
if ($options === null) $options = new stdClass();
$scale = ($options === true) || (property_exists($options, 'scale') ? $options['scale'] : false);
$newValue = ($scale == true) ? ($this->s * (100 + floatval($value))) . '%'
: floatval($value) . '%';
return $this->change('s', $newValue, $scale);
}
}

0 comments on commit f524466

Please sign in to comment.