Modul:Bak pasir/Hidayatsrf/SpectralColor
This module generates the 'rgb(r,g,b)' HTML code of the approximate color of a given wavelength.
Usage
suntingexported function :
Lambdacolor(frame)
– returns the "rgb(r,g,b)" code of the wavelength given as first argument
Uses :
mw.frame
– args[1] = longueur d'onde en nanomètres (entier)
Note : The color tables comes from File:Spectrum-sRGB-low.svg. Tables are big and by step of 2 nm, so interpolation is not necessary
Examples
sunting- Spectral lines of mercury 405 nm(ultraviolet), <span style="background-color:Galat skrip: tidak ada modul tersebut "SpectralColor".">436 nm, <span style="background-color:Galat skrip: tidak ada modul tersebut "SpectralColor".">546 nm and <span style="background-color:Galat skrip: tidak ada modul tersebut "SpectralColor".">a doublet near 578 nm
- <span style="background-color:Galat skrip: tidak ada modul tersebut "SpectralColor".">Triplet of magnesium near 517 nm
- <span style="background-color:Galat skrip: tidak ada modul tersebut "SpectralColor".">Doublet of sodium near 589 nm
- <span style="background-color:Galat skrip: tidak ada modul tersebut "SpectralColor".">Spectral line Hα of hydrogen at 656 nm
- {{#invoke:SpectralColor|lambdacolor|589}} gives 'Galat skrip: tidak ada modul tersebut "SpectralColor".'
-- Gives the approximate rgb of a given wavelength : lambda_nm -> "rgb(r,g,b)"
-- Values comes from http://commons.wikimedia.org/wiki/File:Spectrum-sRGB-low.svg
-- [381 nm .. 709 nm] langkah 2
-- usage {{#invoque:SpectralColor|lambdacolor|wavelength_in_nanometers}}
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} --
-- exported fonction
function c.lambdacolor(frame)
local lambda = tonumber(frame.args[1])
if ((lambda < 381) or (lambda > 709)) then
return("rgb(0,0,0)")
end -- invisible
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..")") -- no interpolation
end
--[[ -----------------------
-- TEST -- Uncomment to try in stand-alone; produces a page .html with a rainbow
--
c.frame = {}
c.frame.args = {}
function plcolor(lambda)
c.frame.args[1] = lambda
print('<span style="background-color:'..c.lambdacolor(c.frame)..'">'..lambda..'</span><br/>')
end
print('<html><head></head><body>')
for wl = 381, 713, 2 do plcolor(wl) end
print('</body></html>')
---------------------- --]]
return c