Created
August 17, 2018 04:16
-
-
Save planetceres/7adbc298c21fe17a97a1ceb7e47e210c to your computer and use it in GitHub Desktop.
RGB values from probability value in range (0,1)
This file contains 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
def rgb_from_prob(value, minimum=0, maximum=1): | |
''' | |
Based on: https://stackoverflow.com/a/20792531/3450793 | |
''' | |
minimum, maximum = float(minimum), float(maximum) | |
ratio = 2 * (value-minimum) / (maximum - minimum) | |
g = int(max(0, 255*(1 - ratio))) | |
r = int(max(0, 255*(ratio - 1))) | |
b = 255 - g - r | |
return r, g, b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment