Difference between revisions of "Module:Ctb"
Jump to navigation
Jump to search
blackwiki>Vladimir891 |
blackwiki>Vladimir891 |
||
| Line 146: | Line 146: | ||
-- function looks up name in an array and returns the numerical RGB values packed into a hexadecimal string suitable for HTML output | -- function looks up name in an array and returns the numerical RGB values packed into a hexadecimal string suitable for HTML output | ||
function p.GetColor( frame ) | function p.GetColor( frame ) | ||
| − | ColorNameList = {"White", "Red", "Green", "Olive", "Dark Olive", "Olive Drab", "Olive Drab Camo", "Blue"} | + | ColorNameList = {"White", "Red", "Green", "Olive", "Olivine", "Dark Olive", "Olive Drab", "Olive Drab Camo", "Black Olive", "Old Moss", "Blue"} |
| − | HexStringList = {"FFFFFF", "FF0000", "00FF00", "808000", "556B2F", "6B8E23", "544F3D", "0000FF"} | + | HexStringList = {"FFFFFF", "FF0000", "00FF00", "808000", "9AB973", "556B2F", "6B8E23", "544F3D", "3B3C36", "52652F", "0000FF"} |
local args=frame.args | local args=frame.args | ||
local ColorName = args[1] | local ColorName = args[1] | ||
Revision as of 04:23, 25 August 2014
-- Toolbox for various effects
-- More features are being added
-- For function 'm'
-- arg[1] = comma-delimited list of parameters
-- arg[2] = comma-delimited list of attributes
-- if arg[1] = "Cbr" then it draws a smooth, blended color progression between the two specified colors.
-- Parameters (arg[2]) : Color1_Red, Color1_Green, Color1_Blue, Color2_Red, Color2_Green, Color2_Blue, Width (em), Units (increments), Height (em)
-- if arg[1] = "Spc" then it draws a smooth, blended spectrum progressing from red to yellow to green to blue to purple, adjusted based on specified parameters
-- Parameters (arg[2]) : Pastel_Red, Pastel_Green, Pastel_Blue, Unused_Red, Unused_Green, Unused_Blue, Width (em), Units (increments), Height (em)
-- For function 'GetColor'
-- arg[1] = name of color (e.g., "Old Moss") ; returns hexadecimal string for that color which can be used for HTML output
local p = {}
function p.m( frame )
local args=frame.args
local list = args[1]
local attr = args[2]
output = ""
local Elems = 0
if list == nil then list = "" end
local Dlist = mw.text.split( list, ",")
if attr == nil then attr = "" end
local Dattr = mw.text.split( attr, ",")
for i = 1, #Dlist do
if Dlist[i] == "Cbr" then -- Color bar with a progression between two colors
local ClR = tonumber(Dattr[1]) or 0xFF
local ClG = tonumber(Dattr[2]) or 0xFF
local ClB = tonumber(Dattr[3]) or 0xFF
local ClR2 = tonumber(Dattr[4]) or 0x00
local ClG2 = tonumber(Dattr[5]) or 0x00
local ClB2 = tonumber(Dattr[6]) or 0x00
local BarWidth = tonumber(Dattr[7]) or 22.0 -- default to 22.0em
local Units = tonumber(Dattr[8]) or 20
local BarHeight = tonumber(Dattr[9]) or 1.0 -- default to 1.0em
local UnitWidth = BarWidth / Units
local DR = (ClR2 - ClR) / Units
local DG = (ClG2 - ClG) / Units
local DB = (ClB2 - ClB) / Units
output=string.format('<table style="width:%dem;height:%dem;border:0px;border-spacing:0px;padding:0px;"><tr>',BarWidth,BarHeight)
for x=1,Units do
output=output..string.format('<td style="width:%dem;height:%dem;background-color:#%02x%02x%02x;"></td>',UnitWidth,BarHeight,ClR,ClG,ClB)
ClR=ClR+DR
ClG=ClG+DG
ClB=ClB+DB
end
output=output.."</tr></table>"
end
if Dlist[i] == "Spc" then -- Color bar with a smooth spectrum
local PsR = tonumber(Dattr[1]) or 0.0 -- pastel weighting factors ( float value between 0 - 1; determines how pastel the color spectrum is ( 0 = none; 1 = fully pastel)
local PsG = tonumber(Dattr[2]) or 0.0
local PsB = tonumber(Dattr[3]) or 0.0
local ClR2 = tonumber(Dattr[4]) or 0.0 -- currently unused (future expansion)
local ClG2 = tonumber(Dattr[5]) or 0.0
local ClB2 = tonumber(Dattr[6]) or 0.0
local BarWidth = tonumber(Dattr[7]) or 22.0 -- default to 22.0em
local Units = tonumber(Dattr[8]) or 20
local BarHeight = tonumber(Dattr[9]) or 1.0 -- default to 1.0em
local UnitWidth = BarWidth / Units
output=string.format('<table style="width:%dem;height:%dem;border:0px;border-spacing:0px;padding:0px;"><tr>',BarWidth,BarHeight)
local ThisUnits = Units / 4
-- Red to yellow
local ThisR=255.0
local ThisG=0.0 + (PsG*0.5)
local ThisB=0.0 + (PsB*0.5)
local ThisR2=255.0
local ThisG2=255.0
local ThisB2=0.0 + (PsB*0.5)
local DR = (ThisR2 - ThisR) / ThisUnits
local DG = (ThisG2 - ThisG) / ThisUnits
local DB = (ThisB2 - ThisB) / ThisUnits
for x=1,ThisUnits do
local ThisRD = math.floor(ThisR)
local ThisGD = math.floor(ThisG)
local ThisBD = math.floor(ThisB)
output=output..string.format('<td style="width:%dem;height:%dem;background-color:#%02x%02x%02x;"></td>',UnitWidth,BarHeight,ThisRD,ThisGD,ThisBD)
ThisR=ThisR+DR
ThisG=ThisG+DG
ThisB=ThisB+DB
end
-- Yellow to green
local ThisR2=0.0 + (PsR*0.5)
local ThisG2=255.0
local ThisB2=0.0 + (PsB*0.5)
local DR = (ThisR2 - ThisR) / ThisUnits
local DG = (ThisG2 - ThisG) / ThisUnits
local DB = (ThisB2 - ThisB) / ThisUnits
for x=1,ThisUnits do
local ThisRD = math.floor(ThisR)
local ThisGD = math.floor(ThisG)
local ThisBD = math.floor(ThisB)
output=output..string.format('<td style="width:%dem;height:%dem;background-color:#%02x%02x%02x;"></td>',UnitWidth,BarHeight,ThisRD,ThisGD,ThisBD)
ThisR=ThisR+DR
ThisG=ThisG+DG
ThisB=ThisB+DB
end
-- Green to blue
local ThisR2=0.0 + (PsR*0.5)
local ThisG2=0.0 + (PsG*0.5)
local ThisB2=255.0
local DR = (ThisR2 - ThisR) / ThisUnits
local DG = (ThisG2 - ThisG) / ThisUnits
local DB = (ThisB2 - ThisB) / ThisUnits
for x=1,ThisUnits do
local ThisRD = math.floor(ThisR)
local ThisGD = math.floor(ThisG)
local ThisBD = math.floor(ThisB)
output=output..string.format('<td style="width:%dem;height:%dem;background-color:#%02x%02x%02x;"></td>',UnitWidth,BarHeight,ThisRD,ThisGD,ThisBD)
ThisR=ThisR+DR
ThisG=ThisG+DG
ThisB=ThisB+DB
end
-- Blue to purple
local ThisR2=255.0
local ThisG2=0.0 + (PsG*0.5)
local ThisB2=255.0
local DR = (ThisR2 - ThisR) / ThisUnits
local DG = (ThisG2 - ThisG) / ThisUnits
local DB = (ThisB2 - ThisB) / ThisUnits
for x=1,ThisUnits do
local ThisRD = math.floor(ThisR)
local ThisGD = math.floor(ThisG)
local ThisBD = math.floor(ThisB)
output=output..string.format('<td style="width:%dem;height:%dem;background-color:#%02x%02x%02x;"></td>',UnitWidth,BarHeight,ThisRD,ThisGD,ThisBD)
ThisR=ThisR+DR
ThisG=ThisG+DG
ThisB=ThisB+DB
end
output=output.."</tr></table>"
end
end
return output
end
-- return hexadecimal string for a color based on name
-- function looks up name in an array and returns the numerical RGB values packed into a hexadecimal string suitable for HTML output
function p.GetColor( frame )
ColorNameList = {"White", "Red", "Green", "Olive", "Olivine", "Dark Olive", "Olive Drab", "Olive Drab Camo", "Black Olive", "Old Moss", "Blue"}
HexStringList = {"FFFFFF", "FF0000", "00FF00", "808000", "9AB973", "556B2F", "6B8E23", "544F3D", "3B3C36", "52652F", "0000FF"}
local args=frame.args
local ColorName = args[1]
local HexString = "000000"
output = ""
if ColorName == nil then ColorName = ""
else
for i = 1, #ColorNameList do
if ColorNameList[i] == ColorName then
HexString = HexStringList[i]
break
end
end
end
return HexString
end
return p