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
m -link
m fine version
Line 2: Line 2:
--This function converts a valid hexadecimal colorcode into three decimal numbers:  
--This function converts a valid hexadecimal colorcode into three decimal numbers:  
-- #bbccdd gives 187|187|204,  while #FF0 will give 255|255|0  
-- #bbccdd gives 187|187|204,  while #FF0 will give 255|255|0  
--The function "tbcgen" generates a complete 5-parameter string
--Invalid color codes will give invalid or unpredictable results, or LUA errors.
--Invalid color codes will give invalid or unpredictable results, or LUA errors.


local p = {}


local p = {}


--
--
Line 11: Line 12:
local dig  =  ( string.upper ( string.char ( arg ) ) );
local dig  =  ( string.upper ( string.char ( arg ) ) );
local dec  =  0;
local dec  =  0;
if    dig == 'F' then
if    dig == 'F' then dec = 0xF
dec = 0xF
elseif dig == 'E' then dec = 0xE
elseif dig == 'E' then
elseif dig == 'D' then dec = 0xD
dec = 0xE
elseif dig == 'C' then dec = 0xC
elseif dig == 'D' then
elseif dig == 'B' then dec = 0xB
dec = 0xD
elseif dig == 'A' then dec = 0xA
elseif dig == 'C' then
else  dec = dig
dec = 0xC
end
elseif dig == 'B' then
return dec;
dec = 0xB
end 
elseif dig == 'A' then
 
dec = 0xA
--
local function convert ( arg )
local hex  =  arg;
local dec  =  {};
if #hex == 7 then
dec [1] = hexdec ( string.byte (hex, 2)) * 16 + hexdec (string.byte (hex, 3))
dec [2] = hexdec ( string.byte (hex, 4)) * 16 + hexdec (string.byte (hex, 5))
dec [3] = hexdec ( string.byte (hex, 6)) * 16 + hexdec (string.byte (hex, 7))
else
else
dec = dig
dec [1] = hexdec ( string.byte (hex, 2)) * 16 + hexdec (string.byte (hex, 2))
end
dec [2] = hexdec ( string.byte (hex, 3)) * 16 + hexdec (string.byte (hex, 3))
dec [3] = hexdec ( string.byte (hex, 4)) * 16 + hexdec (string.byte (hex, 4))
end
return dec;
return dec;
end
--
function p.tsthex ( frame )
    local args = frame.args
local hexcod = args[1] or '#000000';
local septor = args[2] or '_';
local decval = {};
decval = convert ( hexcod );
return table.concat( decval, septor  )
end   
end   
--
function p.hexval ( frame )
    local args = frame.args
local hexcode = args[1] or '#000000';
local decval = {};
decval = convert ( hexcode );
return decval;
end


--
--
Line 33: Line 63:
     local args = frame.args
     local args = frame.args
local tbctab = {};
local tbctab = {};
local hexcod = args[1] or '#000000';
decval = convert ( hexcod );
tbctab [1]  = '0';
tbctab [1]  = '0';
tbctab [5]  = args[2] or 'colour';
tbctab [2]  = decval [1];
local hexcod = args[1] or '#000000';  
tbctab [3]   = decval [2];
if #hexcod == 7 then
tbctab [4]   = decval [3];
tbctab [2] = hexdec( string.byte (hexcod, 2)) * 16 + hexdec (string.byte (hexcod, 3))
tbctab [5]   = args[2] or 'couleur';
tbctab [3] = hexdec( string.byte (hexcod, 4)) * 16 + hexdec (string.byte (hexcod, 5))
tbctab [4] = hexdec( string.byte (hexcod, 6)) * 16 + hexdec (string.byte (hexcod, 7))
else
tbctab [2] = hexdec( string.byte (hexcod, 2)) * 16 + hexdec (string.byte (hexcod, 2))
tbctab [3] = hexdec( string.byte (hexcod, 3)) * 16 + hexdec (string.byte (hexcod, 3))
tbctab [4] = hexdec( string.byte (hexcod, 4)) * 16 + hexdec (string.byte (hexcod, 4))
end 
return mw.getCurrentFrame():expandTemplate{ title = 'Tbc', args =  tbctab };
return mw.getCurrentFrame():expandTemplate{ title = 'Tbc', args =  tbctab };
end
end
return p;
return p;

Revision as of 20:26, 25 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 
--The function "tbcgen" generates a complete 5-parameter string 
--Invalid color codes will give invalid or unpredictable results, or LUA errors.

local p = {}


--
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  

-- 
local function convert ( arg )
	local hex  =  arg;
	local dec  =  {};
	if #hex == 7 then
		dec [1] = hexdec ( string.byte (hex, 2)) * 16 + hexdec (string.byte (hex, 3))
		dec [2] = hexdec ( string.byte (hex, 4)) * 16 + hexdec (string.byte (hex, 5))
		dec [3] = hexdec ( string.byte (hex, 6)) * 16 + hexdec (string.byte (hex, 7))
	else
		dec [1] = hexdec ( string.byte (hex, 2)) * 16 + hexdec (string.byte (hex, 2))
		dec [2] = hexdec ( string.byte (hex, 3)) * 16 + hexdec (string.byte (hex, 3))
		dec [3] = hexdec ( string.byte (hex, 4)) * 16 + hexdec (string.byte (hex, 4))
	end  
	return dec;
end

-- 
function p.tsthex ( frame )
    local args = frame.args
	local hexcod = args[1] or '#000000'; 
	local septor = args[2] or '_'; 
	local decval = {};
	decval = convert ( hexcod ); 
	return table.concat( decval, septor  )
end  

-- 
function p.hexval ( frame )
    local args = frame.args
	local hexcode = args[1] or '#000000'; 
	local decval = {};
	decval = convert ( hexcode ); 
	return decval;
end


--
function p.tbcgen ( frame )
    local args = frame.args
	local tbctab = {};
	local hexcod = args[1] or '#000000'; 
	decval = convert ( hexcod ); 
	tbctab [1]   = '0';
	tbctab [2]   = decval [1];
	tbctab [3]   = decval [2];
	tbctab [4]   = decval [3];
	tbctab [5]   = args[2] or 'couleur';
	return mw.getCurrentFrame():expandTemplate{ title = 'Tbc', args =  tbctab };
end
	
return p;
Cookies help us deliver our services. By using our services, you agree to our use of cookies.