Posted By

chopbust on 07/13/11


Tagged


Versions (?)

Temperature Color Array


 / Published in: PHP
 

Returns the color (red to green) when you give a percentage amount, or reversible.

  1. //color temperatures (for funsies) //straight = red to green, reverse = green to red
  2. function getTemperatureColor($percentage, $type="straight") {
  3.  
  4. $colors = array("#ff0200", "#ff270a", "#ff5306" ,"#ffa801", "#ffd301", "#eef302", "#c0ff02", "#73ff01", "#27ff01", "#00ff00");
  5.  
  6. $colors = array("#c43c35", "#d65227", "#f27312" ,"#f57711", "#f8840a", "#e89b0a", "#bda119", "#9fa225", "#7ba332", "#47a546");
  7.  
  8. if ($type == "reverse") {
  9. $colors = array_reverse($colors);
  10. }
  11.  
  12. if ($percentage >= 100) {
  13. return $colors[9];
  14. } else if ($percentage <= 9) {
  15. return $colors[0];
  16. }
  17.  
  18. //for the double digits
  19. $number = floor($percentage / 10);
  20.  
  21. return $colors[$number];
  22. }

Report this snippet  

You need to login to post a comment.