[ create a new paste ] login | about

Link: http://codepad.org/KWUQGxrS    [ raw code | output | fork ]

Python, pasted on Sep 16:
def wav2RGB(wavelength):
    w = int(wavelength)

    # colour
    if w >= 380 and w < 440:
        R = -(w - 440.) / (440. - 350.)
        G = 0.0
        B = 1.0
    elif w >= 440 and w < 490:
        R = 0.0
        G = (w - 440.) / (490. - 440.)
        B = 1.0
    elif w >= 490 and w < 510:
        R = 0.0
        G = 1.0
        B = -(w - 510.) / (510. - 490.)
    elif w >= 510 and w < 580:
        R = (w - 510.) / (580. - 510.)
        G = 1.0
        B = 0.0
    elif w >= 580 and w < 645:
        R = 1.0
        G = -(w - 645.) / (645. - 580.)
        B = 0.0
    elif w >= 645 and w <= 780:
        R = 1.0
        G = 0.0
        B = 0.0
    else:
        R = 0.0
        G = 0.0
        B = 0.0

    # intensity correction
    if w >= 380 and w < 420:
        SSS = 0.3 + 0.7*(w - 350) / (420 - 350)
    elif w >= 420 and w <= 700:
        SSS = 1.0
    elif w > 700 and w <= 780:
        SSS = 0.3 + 0.7*(780 - w) / (780 - 700)
    else:
        SSS = 0.0
    SSS *= 255

    return [int(SSS*R), int(SSS*G), int(SSS*B)]

for x in [736.93, 695.57, 656.53, 619.68, 584.90, 552.07, 521.09, 491.84, 464.24, 438.18, 413.59, 390.37]:
  print wav2RGB(x)


Output:
1
2
3
4
5
6
7
8
9
10
11
12
[174, 0, 0]
[255, 0, 0]
[255, 0, 0]
[255, 102, 0]
[255, 239, 0]
[153, 255, 0]
[40, 255, 0]
[0, 255, 242]
[0, 122, 255]
[5, 0, 255]
[71, 0, 237]
[99, 0, 178]


Create a new paste based on this one


Comments: