Last active
May 22, 2019 04:58
-
-
Save ven-kyoshiro/dc3f65463900b67121547e5c02d7f590 to your computer and use it in GitHub Desktop.
[0,1] to RGB tuple
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
import matplotlib.pyplot as plt | |
import numpy as np | |
def val2color(x): | |
assert x<=1, 'x should be in the [0,1]' | |
base =0.5 | |
if x<1/3: | |
g=x*3. | |
r= 1-g | |
b=0 | |
elif x>2/3: | |
r = (x-2/3)*3. | |
b = 1.-r | |
g=0 | |
else: | |
b=(x-1/3)*3 | |
g = 1-b | |
r=0 | |
return (r*(1-base)+base,g*(1-base)+base,b*(1-base)+base) | |
%matplotlib inline | |
x = np.linspace(0,1,100) | |
plt.scatter(x,x,color=[val2color(xx) for xx in x]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment