Skip to content

Instantly share code, notes, and snippets.

@eddy1982
Created May 8, 2015 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddy1982/69fb102ccf86473bedef to your computer and use it in GitHub Desktop.
Save eddy1982/69fb102ccf86473bedef to your computer and use it in GitHub Desktop.
Map value to color scale
<!-- Map value to color scale -->
<?php
function lineargradient($ra,$ga,$ba,$rz,$gz,$bz,$iterationnr) {
$colorindex = array();
for($iterationc=1; $iterationc<=$iterationnr; $iterationc++) {
$iterationdiff = $iterationnr-$iterationc;
$colorindex[] = '#'.
dechex(intval((($ra*$iterationc)+($rz*$iterationdiff))/$iterationnr)).
dechex(intval((($ga*$iterationc)+($gz*$iterationdiff))/$iterationnr)).
dechex(intval((($ba*$iterationc)+($bz*$iterationdiff))/$iterationnr));
}
return $colorindex;
}
$colorindex = lineargradient(
100, 0, 0, // rgb of the start color
0, 255, 255, // rgb of the end color
100 // number of colors in your linear gradient
);
$color = $colorindex[1];
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment