Модул:Spectrum

Мавод аз Википедиа — донишномаи озод
Ҳуҷҷатгузорӣ
local S={}

function S.SpectrumMap(frame)
	local args=frame.args[1];
	local s;
	if (mw.ustring.find(args,'\\')) then
		local params=mw.text.split(args,'\\');
		local specStart=400;
		local specEnd=700;
		local specLen=specEnd - specStart;
		local imgHeight=1280;
		local imgWidth=7430;
		local specLines={};
		local specLine={};
		for i=2,#params do
			if (i==2) or (params[i]-params[i-1]>1.2) then	-- не пропускаем
				if (i<#params) and (params[i+1]-params[i]<=1.2) then	--очень близкие линии
					specLine={
						L = (((params[i]+params[i+1])/2 - specStart) / specLen * imgWidth),
						comment = tostring(params[i])..' нм и '..tostring(params[i+1])..' нм'
					}
				else
					specLine={
						L = ((params[i] - specStart) / specLen * imgWidth),
						comment = tostring(params[i])..' нм'
					}
				end
				table.insert(specLines,specLine);
			end
		end
		s='<imagemap>\nImage:'..params[1]..'|250px|\n'; 
		for i=1,#specLines do
			--linePos=math.floor((params[i] - specStart) / specLen * imgWidth);
			s=s..'rect '..tostring(specLines[i].L - 75)..' 0 '..tostring(specLines[i].L + 75)..' '..imgHeight..' [[:File:'..params[1]..'|'..specLines[i].comment..']]\n';
		end
		s=s..'desc none\n</imagemap>\n';
		s=frame:preprocess(s);
	else
		s='[[File:'..args..'|250px]]';
	end
	return s
end

return S