Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Color2dec: Difference between revisions

From Neodyland Wiki
mNo edit summary
m format
Line 60: Line 60:
decval [3] = hexdec( string.byte (hexcod, 4)) * 16 + hexdec (string.byte (hexcod, 4))
decval [3] = hexdec( string.byte (hexcod, 4)) * 16 + hexdec (string.byte (hexcod, 4))
end   
end   
return decval [1], decval [2] , decval [3];
return decval [1] .. '/' .. decval [2] .. '/' .. decval [3];
end   
end   




return p;
return p;

Revision as of 10:51, 22 August 2019

Module documentation[ create · purge ]
This documentation is transcluded from Module:Color2dec/doc.
--This function converts a valid hexadecimal colorcode into three decimal numbers: 
--	#bbccdd gives 187|187|204,  while #FF0 will give 255|255|0 
--Invalid color codes will give invalid or unpredictable results, or LUA errors.


local p = {}


local function getParameters( frame_args, arg_list )
    local get_args = {};
    local index = 1;
    local value;

    for i,arg in ipairs( arg_list ) do
        value = frame_args[arg]
        if value == nil then
            value = frame_args[index];
            index = index + 1;
        end
        get_args[arg] = value;
    end
    return get_args;
end


local function hexdec ( arg )
	local dig  =  ( string.upper ( string.char ( arg ) ) );
	local dec  =  0;
	if     dig == 'F' then
		dec = 0xF
	elseif dig == 'E' then
		dec = 0xE
	elseif dig == 'D' then
		dec = 0xD
	elseif dig == 'C' then
		dec = 0xC
	elseif dig == 'B' then
		dec = 0xB
	elseif dig == 'A' then
		dec = 0xA
	else
		dec = dig
	end
	return dec;
end  

-- 
function p.hexval ( inp )
	local color = getParameters( inp.args, { 'colcod' } );
	local hexcod = color['colcod'] or '#000000'; 
	local decval = {};
	if #hexcod == 7 then
		decval [1] = hexdec( string.byte (hexcod, 2)) * 16 + hexdec (string.byte (hexcod, 3))
		decval [2] = hexdec( string.byte (hexcod, 4)) * 16 + hexdec (string.byte (hexcod, 5))
		decval [3] = hexdec( string.byte (hexcod, 6)) * 16 + hexdec (string.byte (hexcod, 7))
	else
		decval [1] = hexdec( string.byte (hexcod, 2)) * 16 + hexdec (string.byte (hexcod, 2))
		decval [2] = hexdec( string.byte (hexcod, 3)) * 16 + hexdec (string.byte (hexcod, 3))
		decval [3] = hexdec( string.byte (hexcod, 4)) * 16 + hexdec (string.byte (hexcod, 4))
	end  
	return decval [1] .. '/' .. decval [2] .. '/' .. decval [3];
end  


return p;
Cookies help us deliver our services. By using our services, you agree to our use of cookies.