Last active
January 23, 2019 08:37
-
-
Save ven-kyoshiro/a066402e026eb33b1f50cd4ce6ad1eda to your computer and use it in GitHub Desktop.
you can convert xy to RGB
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 math | |
def xy2color(x,y): | |
norm = min(1.0,(x*x + y*y)**(1/2)) | |
rad = math.atan2(x,y)+math.pi | |
if rad < math.pi*2/3: | |
ratio = rad/(math.pi*2/3) | |
r = 1.-ratio | |
g = ratio | |
b = 0 | |
elif rad < math.pi*4/3: | |
ratio = (rad-math.pi*2/3)/(math.pi*2/3) | |
r = 0 | |
g = 1. - ratio | |
b = ratio | |
else: | |
ratio = (rad-math.pi*4/3)/(math.pi*2/3) | |
r = ratio | |
g = 0 | |
b = 1.-ratio | |
return [1-min(max(r*norm,0.),1), 1-min(max(g*norm,0.),1), 1-min(max(b*norm,0.),1)] | |
# color campux | |
x = [] | |
for i in range(100): | |
x+=[(i-50)/50]*100 | |
y = [(i-50)/50 for i in range(100)]*100 | |
ccc = [xy2color(xx,yy) for xx,yy in zip(x,y)] | |
sc = plt.scatter(x,y,c=ccc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment