Module:Sandbox/AlexNB/nmColor: Difference between revisions

Content deleted Content added
AlexNB (talk | contribs)
No edit summary
AlexNB (talk | contribs)
adding magentas (test)
Line 93:
end
return wavelength_vis
end
 
local minAntiMagenta = 540
local maxAntiMagenta = 570
 
local function process_magenta(wavelength_abs)
local redvalue_RED
local bluevalue_RED
local greenvalue_RED
local redvalue_BLUE
local bluevalue_BLUE
local greenvalue_BLUE
nm2RGB(absorption_to_visible(wavelengthminAntiMagenta), false)
redvalue_RED = redvalue
bluevalue_RED = bluevalue
greenvalue_RED = greenvalue
nm2RGB(absorption_to_visible(maxAntiMagenta), false)
redvalue_BLUE = redvalue
bluevalue_BLUE = bluevalue
greenvalue_BLUE = greenvalue
redvalue = (redvalue_RED + redvalue_BLUE)/2
bluevalue = (bluevalue_RED + bluevalue_BLUE)/2
greenvalue = (greenvalue_RED + greenvalue_BLUE)/2
end
 
Line 98 ⟶ 121:
-- this function returns the string "#RRGGBB" with approximate RGB value for a complementary color (reflection) to a color, defined as a wavelength passed as a first argument
local wavelength = tonumber(frame.args[1])
-- adding magentas to smoothen red->blue transition. Trying 540..570 nm
nm2RGB(absorption_to_visible(wavelength), false)
if (wavelength>=minAntiMagenta) and (wavelength<=maxAntiMagenta)
then process_magenta(wavelength)
else nm2RGB(absorption_to_visible(wavelength), false)
end
local result='#' .. string.format("%.2X%.2X%.2X", 255*redvalue, 255*greenvalue, 255*bluevalue)
return result