Hopp til innhold

Modul:Spektralfarge

Fra Wikipedia, den frie encyklopedi

--[[
Gir den omtrentlige rgb-koden til en gitt bølgelgende: lambda_nm -> "rgb(r,g,b)"
Verdiene kommer fra http://commons.wikimedia.org/wiki/File:Spectrum-sRGB-low.svg
[381 nm .. 709 nm] steg 2
bruk {{#invoque:Spektralfarge|lambdafarge|bølgelengde_i_nanometer}}
]]

local c = {}
c.reds = {0,0,0,0,0,0,36,36,31,25,51,44,36,31,44,54,57,76,85,82,97,107,110,112,110,108,110,112,111,108,106,103,103,97,92,87,89,84,78,67,51,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,57,89,115,138,157,171,187,199,213,223,234,243,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,247,243,232,224,215,207,201,191,181,175,169,157,151,143,136,128,118,110,100,98,98,87,74,85,70,70,51,51,51,51,48,48,48,48,48,48,48} --
c.greens = {18,18,18,18,25,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25,60,80,97,112,127,141,157,163,177,182,187,196,205,214,223,227,235,246,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,250,246,241,236,230,225,218,206,192,179,168,156,145,135,124,112,106,94,85,72,65,51,44,18,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} --
c.blues = {31,31,31,31,48,48,54,62,67,72,82,89,97,106,120,135,150,168,188,205,226,248,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,250,245,237,230,225,221,218,216,213,212,213,212,207,202,196,191,186,181,178,173,170,166,164,160,156,151,148,142,139,130,126,118,106,92,70,36,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,40,44,54,60,65,65,67,67,76,72,74,74,78,70,70,67,62,67,62,57,57,60,54,48,48,48,40,40,31,25,36,36,25,0,36,25,25,0,0,0,0,25,25,25,25,25,25,25} --
-- eksportert funksjon
function c.lambdafarge(frame)
    local lambda = tonumber(frame.args[1])
    if ((lambda < 381) or (lambda > 709)) then
        return("rgb(0,0,0)")
    end -- usynlig
    local idx = math.floor((lambda - 381)/2)+1
    local r = c.reds[idx]
    local g = c.greens[idx]
	local b = c.blues[idx]
	return ("rgb("..r..","..g..","..b..")") -- ingen interpolering
end

return c