Skip to content

Instantly share code, notes, and snippets.

@philipok-1
Last active October 31, 2016 17:28
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 philipok-1/99de9fa271a27e17b0ff62fbe2c0e3e6 to your computer and use it in GitHub Desktop.
Save philipok-1/99de9fa271a27e17b0ff62fbe2c0e3e6 to your computer and use it in GitHub Desktop.
quick script to convert value to range of hot/cold RGB colours
# coding: utf-8
import re, subprocess
rgb_array=[(0, 100, 255), (0, 116, 255), (0, 132, 255), (0, 148, 255), (0, 164, 255), (0, 180, 255), (0, 196, 255), (0, 212, 255), (0, 228, 255), (0, 255, 244), (0, 255, 208), (0, 255, 168), (0, 255, 131), (0, 255, 92), (0, 255, 54), (0, 255, 16), (23, 255, 0), (62, 255, 0), (101, 255, 0), (138, 255, 0), (176, 255, 0), (215, 255, 0), (253, 255, 0), (255, 250, 0), (255, 240, 0), (255, 230, 0), (255, 220, 0), (255, 210, 0), (255, 200, 0), (255, 190, 0), (255, 180, 0), (255, 170, 0), (255, 160, 0), (255, 150, 0), (255, 140, 0), (255, 130, 0), (255, 120, 0), (255, 110, 0), (255, 100, 0), (255, 90, 0), (255, 80, 0), (255, 70, 0), (255, 60, 0), (255, 50, 0), (255, 40, 0), (255, 30, 0), (255, 20, 0), (255, 10, 0), (255, 0, 0), (255, 0, 16), (255, 0, 32), (255, 0, 48), (255, 0, 64)]
def temp_rgb(temp, min, max):
temp=int(temp)
if temp<min: temp=min
elif temp>max: temp=max
index = (((temp - min) * (53 - 0)) / (max - min)) + 0
output=rgb_array[index]
return output
def get_temp():
temp=subprocess.check_output(["/opt/vc/bin/vcgencmd measure_temp"], shell=True)
out=re.search(r'\d+\.\d+', temp)
return str(out.group(0))
def main():
print temp_rgb(-20, -5, 30)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment