par
drBouvierLeduc » 23 oct. 2012, 13:49
Un peu de lecture théorique sur les couleurs m'a aidé : la roue qui m'intéressait s'appelle la roue RYB (RJB en français : rouge jaune bleu) et correspond à la synthèse soustractive des couleurs (par opposition à la rouge RGB -> synthèse additive).
Bref, j'ai trouvé une fonction écrite en java qui fait exactement ce que je cherchais : modifier une teinte sur la roue RYB.
Elle se trouve dans librairie ColorLib pour processing (au passage, merci l'open source !) :
https://code.google.com/p/colorlib/sour ... h.java#260.
Il suffit de la transposer en PHP et le tour est joué.
Voilà ce que ça donne si ça intéresse des gens :
/**
* Modifie une teinte selon la roue RYB (rouge jaune bleu).
* Adapte de ColorLib / licence MIT
* https://code.google.com/p/colorlib/
*
* @param $h int
* teinte a modifier
* 0 < $h < 1
* @param $angle int
* angle a parcourir sur la roue chromatique
* 0 < $angle < 360
* @return int
* nouvelle teinte
* 0 < $h < 1
*/
function rotation_ryb($h, $angle=30){
$h *= 360;
$angle %= 360;
$angle_ref = 0;
$roue = array(
array( 0, 0 ), array( 15, 8 ), array( 30, 17 ), array( 45, 26 ),
array( 60, 34 ), array( 75, 41 ), array( 90, 48 ), array( 105, 54 ), array( 120, 60 ),
array( 135, 81 ), array( 150, 103 ), array( 165, 123 ), array( 180, 138 ),
array( 195, 155 ), array( 210, 171 ), array( 225, 187 ), array( 240, 204 ),
array( 255, 219 ), array( 270, 234 ), array( 285, 251 ), array( 300, 267 ),
array( 315, 282 ), array( 330, 298 ), array( 345, 329 ), array( 360, 0 )
);
for ($i = 0; $i < count($roue) - 1; $i++) {
$x0 = $roue[$i][0];
$y0 = $roue[$i][1];
$x1 = $roue[$i + 1][0];
$y1 = $roue[$i + 1][1];
if ($y1 < $y0) {
$y1 += 360;
}
if ($y0 <= $h && $h <= $y1) {
$angle_ref = 1 * $x0 + ($x1 - $x0) * ($h - $y0) / ($y1 - $y0);
}
}
$angle_ref = ($angle_ref + $angle) % 360;
for ($i = 0; $i < count($roue) - 1; $i++) {
$x0 = $roue[$i][0];
$y0 = $roue[$i][1];
$x1 = $roue[$i + 1][0];
$y1 = $roue[$i + 1][1];
if ($y1 < $y0)
$y1 += 360;
if ($x0 <= $angle_ref && $angle_ref <= $x1) {
$h = 1 * $y0 + ($y1 - $y0) * ($angle_ref - $x0) / ($x1 - $x0);
}
}
$h %= 360;
$h /= 360;
return $h;
}
Un peu de lecture théorique sur les couleurs m'a aidé : la roue qui m'intéressait s'appelle la roue RYB (RJB en français : rouge jaune bleu) et correspond à la synthèse soustractive des couleurs (par opposition à la rouge RGB -> synthèse additive).
Bref, j'ai trouvé une fonction écrite en java qui fait exactement ce que je cherchais : modifier une teinte sur la roue RYB.
Elle se trouve dans librairie ColorLib pour processing (au passage, merci l'open source !) : [url]https://code.google.com/p/colorlib/source/browse/trunk/colorLib/src/colorLib/Swatch.java#260[/url].
Il suffit de la transposer en PHP et le tour est joué.
Voilà ce que ça donne si ça intéresse des gens :
[php]
/**
* Modifie une teinte selon la roue RYB (rouge jaune bleu).
* Adapte de ColorLib / licence MIT
* https://code.google.com/p/colorlib/
*
* @param $h int
* teinte a modifier
* 0 < $h < 1
* @param $angle int
* angle a parcourir sur la roue chromatique
* 0 < $angle < 360
* @return int
* nouvelle teinte
* 0 < $h < 1
*/
function rotation_ryb($h, $angle=30){
$h *= 360;
$angle %= 360;
$angle_ref = 0;
$roue = array(
array( 0, 0 ), array( 15, 8 ), array( 30, 17 ), array( 45, 26 ),
array( 60, 34 ), array( 75, 41 ), array( 90, 48 ), array( 105, 54 ), array( 120, 60 ),
array( 135, 81 ), array( 150, 103 ), array( 165, 123 ), array( 180, 138 ),
array( 195, 155 ), array( 210, 171 ), array( 225, 187 ), array( 240, 204 ),
array( 255, 219 ), array( 270, 234 ), array( 285, 251 ), array( 300, 267 ),
array( 315, 282 ), array( 330, 298 ), array( 345, 329 ), array( 360, 0 )
);
for ($i = 0; $i < count($roue) - 1; $i++) {
$x0 = $roue[$i][0];
$y0 = $roue[$i][1];
$x1 = $roue[$i + 1][0];
$y1 = $roue[$i + 1][1];
if ($y1 < $y0) {
$y1 += 360;
}
if ($y0 <= $h && $h <= $y1) {
$angle_ref = 1 * $x0 + ($x1 - $x0) * ($h - $y0) / ($y1 - $y0);
}
}
$angle_ref = ($angle_ref + $angle) % 360;
for ($i = 0; $i < count($roue) - 1; $i++) {
$x0 = $roue[$i][0];
$y0 = $roue[$i][1];
$x1 = $roue[$i + 1][0];
$y1 = $roue[$i + 1][1];
if ($y1 < $y0)
$y1 += 360;
if ($x0 <= $angle_ref && $angle_ref <= $x1) {
$h = 1 * $y0 + ($y1 - $y0) * ($angle_ref - $x0) / ($x1 - $x0);
}
}
$h %= 360;
$h /= 360;
return $h;
}[/php]