Created
August 27, 2019 10:58
-
-
Save equalent/5caeecc1525bb18a2cf711adbdd29b31 to your computer and use it in GitHub Desktop.
Color from light temperature
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
| from math import log | |
| k = int(input("Kelvin: "))//100 | |
| (r,g,b) = (0,0,0) | |
| # RED: | |
| if k <= 66: | |
| r=255 | |
| else: | |
| r = k-60 | |
| r = 329.698727446 * (r ** -0.1332047592) | |
| if r<0: | |
| r=0 | |
| elif r>255: | |
| r=255 | |
| # GREEN: | |
| if g <= 66: | |
| g = k | |
| g = 99.4708025861 * log(g) - 161.1195681661 | |
| if g<0: | |
| g=0 | |
| elif g>255: | |
| g=255 | |
| else: | |
| g=k-60 | |
| g=288.1221695283 * (g ** -0.0755148492) | |
| # BLUE: | |
| if k>=66: | |
| b=255 | |
| else: | |
| if k<=19: | |
| b = 0 | |
| else: | |
| b=k-10 | |
| b=138.5177312231 * log(b) - 305.0447927307 | |
| if b<0: | |
| b=0 | |
| elif b>255: | |
| b=255 | |
| print("RGB: (%i, %i, %i)" % (r, g, b)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment