Skip to content

Instantly share code, notes, and snippets.

@planetceres
Created August 17, 2018 04:16
Show Gist options
  • Save planetceres/7adbc298c21fe17a97a1ceb7e47e210c to your computer and use it in GitHub Desktop.
Save planetceres/7adbc298c21fe17a97a1ceb7e47e210c to your computer and use it in GitHub Desktop.
RGB values from probability value in range (0,1)
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