Module:CalcDye

-- reference from Dye#Dyeing armor -- local p = {} function p.base( f ) local args = f	if f == mw.getCurrentFrame then args = require( 'Module:ProcessArgs' ).merge( true ) else f = mw.getCurrentFrame end local colors = { white = { red = 0xf9, green = 0xff, blue = 0xfe }, orange = { red = 0xf9, green = 0x80, blue = 0x1d }, magenta = { red = 0xc7, green = 0x4e, blue = 0xbd }, lightblue = { red = 0x3a, green = 0xb3, blue = 0xda }, yellow = { red = 0xfe, green = 0xd8, blue = 0x3d }, lime = { red = 0x80, green = 0xc7, blue = 0x1f }, pink = { red = 0xf3, green = 0x8b, blue = 0xaa }, gray = { red = 0x47, green = 0x4f, blue = 0x52 }, lightgray = { red = 0x9d, green = 0x9d, blue = 0x97 }, cyan = { red = 0x16, green = 0x9c, blue = 0x9c }, purple = { red = 0x89, green = 0x32, blue = 0xb8 }, blue = { red = 0x3c, green = 0x44, blue = 0xaa }, brown = { red = 0x83, green = 0x54, blue = 0x32 }, green = { red = 0x5e, green = 0x7c, blue = 0x16 }, red = { red = 0xb0, green = 0x2e, blue = 0x26 }, black = { red = 0x1d, green = 0x1d, blue = 0x21 } }	local totalRed = 0 local totalGreen = 0 local totalBlue = 0 local totalMaximum = 0 local numberOfColors = 0 for k, color in pairs(colors) do		if args[k] then for i=1, args[k], 1 do				totalRed = totalRed + color.red totalGreen = totalGreen + color.green totalBlue = totalBlue + color.blue totalMaximum = totalMaximum + math.max(color.red, color.green, color.blue) numberOfColors = numberOfColors + 1 end end end if numberOfColors == 0 then return 'N/A' end local averageRed = totalRed / numberOfColors local averageGreen = totalGreen / numberOfColors local averageBlue = totalBlue / numberOfColors local averageMaximum = totalMaximum / numberOfColors local maximumOfAverage = math.max(averageRed, averageGreen, averageBlue) local gainFactor = averageMaximum / maximumOfAverage local resultRed = math.floor(averageRed * gainFactor) local resultGreen = math.floor(averageGreen * gainFactor) local resultBlue = math.floor(averageBlue * gainFactor) return string.format("%02X", resultRed) .. string.format("%02X", resultGreen) .. string.format("%02X", resultBlue) end

return p