Last active
July 17, 2021 23:44
-
-
Save tjnurmin/6670022 to your computer and use it in GitHub Desktop.
Generate heat map colors through interpolation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// declare start, mid, end colors | |
$c = array( | |
array(0,0,0), | |
array(128,128,128), | |
array(255,255,255) | |
); | |
$loops = 127; | |
for ($t = 0; $t <= $loops; $t++) | |
{ | |
$e = $t / $loops; | |
echo "("; | |
echo intval((1 - $e) * $c[0][0] + $e * $c[1][0]) . ","; | |
echo intval((1 - $e) * $c[0][1] + $e * $c[1][1]) . ","; | |
echo intval((1 - $e) * $c[0][2] + $e * $c[1][2]); | |
echo "),<br />"; | |
} | |
$loops = 128; | |
for ($t = 0; $t <= $loops; $t++) | |
{ | |
$e = $t / $loops; | |
if ($t > 0) // skip the mid color which is already in the array | |
{ | |
echo "("; | |
echo intval((1 - $e) * $c[1][0] + $e * $c[2][0]) . ","; | |
echo intval((1 - $e) * $c[1][1] + $e * $c[2][1]) . ","; | |
echo intval((1 - $e) * $c[1][2] + $e * $c[2][2]); | |
echo "),<br />"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment