Module:Ctb
Revision as of 21:44, 25 August 2014 by blackwiki>Vladimir891
-- 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
local ThisUnits = Units / 4
colors = {}
table.insert(colors, {255.0, 0.0, 0.0})
table.insert(colors, {255.0, 255.0, 0.0})
table.insert(colors, {0.0, 255.0, 0.0})
table.insert(colors, {0.0, 0.0, 255.0})
table.insert(colors, {255.0, 0.0, 255.0})
local function draw(color1, color2)
local ThisR = color1[1] + (color1[1] == 0.0 and PsR*0.5 or 0.0)
local ThisG = color1[2] + (color1[2] == 0.0 and PsG*0.5 or 0.0)
local ThisB = color1[3] + (color1[3] == 0.0 and PsB*0.5 or 0.0)
local ThisR2 = color2[1] + (color2[1] == 0.0 and PsR*0.5 or 0.0)
local ThisG2 = color2[2] + (color2[2] == 0.0 and PsG*0.5 or 0.0)
local ThisB2 = color2[3] + (color2[3] == 0.0 and PsB*0.5 or 0.0)
local results = {}
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)
table.insert(
results,
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
return table.concat(results, '')
end
results = {}
for i = 1, #colors - 1 do
table.insert(results, draw(colors[i], colors[i + 1]))
end
output = string.format(
'<table style="width:%dem;height:%dem;border:0px;border-spacing:0px;padding:0px;"><tr>',
BarWidth,BarHeight
) .. table.concat(results, '') .. '</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 )
local args=frame.args
local ColorName = args[1]
local HexString = "000000"
output = ""
if ColorName == nil then ColorName = ""
else
local RGB = ColorNameList[ColorName]
if RGB == nil then RGB = {0,0,0}
else HexString = string.format('%02x%02x%02x',RGB[1],RGB[2],RGB[3])
end
--for i = 1, #ColorNameList do
-- if ColorNameList[i] == ColorName then
-- HexString = HexStringList[i]
-- break
-- end
--end
end
return HexString
end
-- This array stores the names and RGB values for a list of colors.
-- (WORK IN PROGRESS. A lot more will be added as time permits)
ColorNameList = {
--Whites
['white'] = {255,255,255},
['antiquewhite'] = {250,235,215},
['whitesmoke'] = {245,245,245},
['snow'] = {255,250,250},
['floralwhite'] = {255,250,240},
['ghostwhite'] = {248,248,255},
['navajowhite'] = {255,222,173},
--Grays
['silver'] = {192,192,192},
['gainsboro'] = {220,220,220},
['gray-medium'] = {128,128,128},
['lightgray'] = {211,211,211},
['lightslategray'] = {119,136,153},
['slategrey'] = {112,128,144},
['darkslategray'] = {47,79,79},
['dimgray'] = {105,105,105},
['darkgray'] = {169,169,169},
['black'] = {0,0,0},
--Tans & Browns
['tan'] = {210,180,140},
['cornsilk'] = {255,248,220},
['wheat'] = {245,222,179},
['beige'] = {245,245,220},
['blanchedalmond'] = {255,235,205},
['bisque'] = {255,228,196},
['brown'] = {165,42,42},
['burlywood'] = {222,184,135},
['chocolate'] = {210,105,30},
['darkkhaki'] = {189,183,107},
['rosybrown'] = {188,143,143},
['saddlebrown'] = {139,69,19},
['sandybrown'] = {244,164,96},
['sienna'] = {160,82,45},
['ivory'] = {255,255,240},
['khaki'] = {240,230,140},
['linen'] = {250,240,230},
['oldlace'] = {253,245,230},
['seashell'] = {255,245,238},
['moccasin'] = {255,228,181},
['papayawhip'] = {255,239,213},
['peachpuff'] = {255,218,185},
['peru'] = {205,133,63},
--Reds
['darkred'] = {139,0,0},
['coral'] = {255,127,80},
['crimson'] = {220,20,60},
['firebrick'] = {178,34,34},
['deeppink'] = {255,20,147},
['hotpink'] = {255,105,180},
['indianred'] = {205,92,92},
['lightpink'] = {255,182,193},
['maroon'] = {128,0,0},
['red'] = {255,0,0},
['tomato'] = {255,99,71},
['pink'] = {255,192,203},
['mistyrose'] = {255,228,225},
['lightcoral'] = {240,128,128},
--Orange and Gold
['orange'] = {255,165,0},
['orangered'] = {255,69,0},
['darkorange'] = {255,140,0},
['darkgoldenrod'] = {184,134,11},
['salmon'] = {250,128,114},
['lightsalmon'] = {255,160,122},
['darksalmon'] = {233,150,122},
--Yellows
['yellow'] = {255,255,0},
['gold'] = {255,215,0},
['goldenrod'] = {218,165,32},
['lemonchiffon'] = {255,250,205},
['lightgoldenrodyellow'] = {250,250,210},
['lightyellow'] = {255,255,224},
['palegoldenrod'] = {238,232,170},
['yellowgreen'] = {154,205,50},
-- Greens
['green'] = {0,128,0},
['greenyellow'] = {173,255,47},
['green beige'] = {214,199,148},
['forestgreen'] = {34,139,34},
['springgreen'] = {0,255,127},
['lawngreen'] = {124,252,0},
['chartreuse'] = {127,255,0},
['darkgreen'] = {0,100,0},
['darkolivegreen'] = {85,107,47},
['palegreen'] = {152,251,152},
['olive'] = {128,128,0},
['olivine'] = {154,185,115},
['darkolive'] = {85,107,47},
['olivedrab'] = {107,142,35},
['olivedrabcamo'] = {84, 79, 61},
['blackolive'] = {59, 60, 54},
['oldmoss'] = {80,97,37},
['honeydew'] = {240,255,240},
['lightgreen'] = {144,238,144},
['lime'] = {0,255,0},
['limegreen'] = {50,205,50},
['mediumspringgreen'] = {0,250,154},
['mintcream'] = {245,255,250},
--Green-Blues
['cyan'] = {0,255,255},
['darkcyan'] = {0,139,139},
['aqua'] = {0,250,255},
['aquamarine'] = {127,255,212},
['seagreen'] = {46,139,87},
['lightseagreen'] = {32,178,170},
['mediumseagreen'] = {60,179,113},
['darkseagreen'] = {143,188,143},
['azure'] = {240,255,255},
['teal'] = {0,128,128},
['turquoise'] = {64,224,208},
['darkturquoise'] = {0,206,209},
['paleturquoise'] = {175,238,238},
['lightcyan'] = {224,255,255},
['mediumturquoise'] = {72,209,204},
['mediumaquamarine'] = {102,205,170},
--Blues--
['blue'] = {0,0,255},
['darkblue'] = {0,0,139},
['aliceblue'] = {240,248,255},
['steelblue'] = {70,130,180},
['cadetblue'] = {95,158,160},
['cornflowerblue'] = {100,149,237},
['blueviolet'] = {138,43,226},
['royalblue'] = {65,105,225},
['powderblue'] = {176,224,230},
['skyblue'] = {135,206,235},
['slateblue'] = {106,90,205},
['lightblue'] = {173,216,230},
['darkslateblue'] = {72,61,139},
['deepskyblue'] = {0,191,255},
['dodgerblue'] = {30,144,255},
['lightskyblue'] = {135,206,250},
['lightsteelblue'] = {176,196,222},
['mediumblue'] = {0,0,205},
['mediumslateblue'] = {123,104,238},
['midnightblue'] = {25,25,112},
['navyblue'] = {0,0,128},
--Purples
['magenta'] = {255,0,255},
['purple'] = {128,0,128},
['mediumpurple'] = {147,112,219},
['violet'] = {238,130,238},
['darkviolet'] = {148,0,211},
['darkmagenta'] = {139,0,139},
['plum'] = {221,160,221},
['orchid'] = {218,112,214},
['mediumorchid'] = {186,85,211},
['darkorchid'] = {153,50,204},
['mediumvioletred'] = {199,21,133},
['palevioletred'] = {219,112,147},
['fuchsia'] = {255,0,255},
['indigo'] = {75,0,130},
['lavender'] = {230,230,250},
['lavenderblush'] = {255,240,245},
['thistle'] = {216,191,216},
} --end of color table
return p