<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://wiki.mimikkofans.club/index.php?action=history&amp;feed=atom&amp;title=%E6%A8%A1%E5%9D%97%3AColor</id>
	<title>模块:Color - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.mimikkofans.club/index.php?action=history&amp;feed=atom&amp;title=%E6%A8%A1%E5%9D%97%3AColor"/>
	<link rel="alternate" type="text/html" href="https://wiki.mimikkofans.club/index.php?title=%E6%A8%A1%E5%9D%97:Color&amp;action=history"/>
	<updated>2026-04-08T01:51:50Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.mimikkofans.club/index.php?title=%E6%A8%A1%E5%9D%97:Color&amp;diff=412&amp;oldid=prev</id>
		<title>一位史蒂夫：​导入1个版本</title>
		<link rel="alternate" type="text/html" href="https://wiki.mimikkofans.club/index.php?title=%E6%A8%A1%E5%9D%97:Color&amp;diff=412&amp;oldid=prev"/>
		<updated>2025-09-01T16:40:02Z</updated>

		<summary type="html">&lt;p&gt;导入1个版本&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2025年9月2日 (二) 00:40的版本&lt;/td&gt;
				&lt;/tr&gt;
&lt;!-- diff cache key wiki_club:diff::1.12:old-411:rev-412 --&gt;
&lt;/table&gt;</summary>
		<author><name>一位史蒂夫</name></author>
	</entry>
	<entry>
		<id>https://wiki.mimikkofans.club/index.php?title=%E6%A8%A1%E5%9D%97:Color&amp;diff=411&amp;oldid=prev</id>
		<title>abaaba&gt;Lihb：​同步自moegirl.icu的同名页面</title>
		<link rel="alternate" type="text/html" href="https://wiki.mimikkofans.club/index.php?title=%E6%A8%A1%E5%9D%97:Color&amp;diff=411&amp;oldid=prev"/>
		<updated>2024-07-26T18:00:00Z</updated>

		<summary type="html">&lt;p&gt;同步自moegirl.icu的同名页面&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- 该模块主要用于操作颜色。&lt;br /&gt;
&lt;br /&gt;
local colorKeywords = {&lt;br /&gt;
  aliceblue = { 240, 248, 255 },&lt;br /&gt;
  antiquewhite = { 250, 235, 215 },&lt;br /&gt;
  aqua = { 0, 255, 255 },&lt;br /&gt;
  aquamarine = { 127, 255, 212 },&lt;br /&gt;
  azure = { 240, 255, 255 },&lt;br /&gt;
  beige = { 245, 245, 220 },&lt;br /&gt;
  bisque = { 255, 228, 196 },&lt;br /&gt;
  black = { 0, 0, 0 },&lt;br /&gt;
  blanchedalmond = { 255, 235, 205 },&lt;br /&gt;
  blue = { 0, 0, 255 },&lt;br /&gt;
  blueviolet = { 138, 43, 226 },&lt;br /&gt;
  brown = { 165, 42, 42 },&lt;br /&gt;
  burlywood = { 222, 184, 135 },&lt;br /&gt;
  cadetblue = { 95, 158, 160 },&lt;br /&gt;
  chartreuse = { 127, 255, 0 },&lt;br /&gt;
  chocolate = { 210, 105, 30 },&lt;br /&gt;
  coral = { 255, 127, 80 },&lt;br /&gt;
  cornflowerblue = { 100, 149, 237 },&lt;br /&gt;
  cornsilk = { 255, 248, 220 },&lt;br /&gt;
  crimson = { 220, 20, 60 },&lt;br /&gt;
  cyan = { 0, 255, 255 },&lt;br /&gt;
  darkblue = { 0, 0, 139 },&lt;br /&gt;
  darkcyan = { 0, 139, 139 },&lt;br /&gt;
  darkgoldenrod = { 184, 134, 11 },&lt;br /&gt;
  darkgray = { 169, 169, 169 },&lt;br /&gt;
  darkgreen = { 0, 100, 0 },&lt;br /&gt;
  darkgrey = { 169, 169, 169 },&lt;br /&gt;
  darkkhaki = { 189, 183, 107 },&lt;br /&gt;
  darkmagenta = { 139, 0, 139 },&lt;br /&gt;
  darkolivegreen = { 85, 107, 47 },&lt;br /&gt;
  darkorange = { 255, 140, 0 },&lt;br /&gt;
  darkorchid = { 153, 50, 204 },&lt;br /&gt;
  darkred = { 139, 0, 0 },&lt;br /&gt;
  darksalmon = { 233, 150, 122 },&lt;br /&gt;
  darkseagreen = { 143, 188, 143 },&lt;br /&gt;
  darkslateblue = { 72, 61, 139 },&lt;br /&gt;
  darkslategray = { 47, 79, 79 },&lt;br /&gt;
  darkslategrey = { 47, 79, 79 },&lt;br /&gt;
  darkturquoise = { 0, 206, 209 },&lt;br /&gt;
  darkviolet = { 148, 0, 211 },&lt;br /&gt;
  deeppink = { 255, 20, 147 },&lt;br /&gt;
  deepskyblue = { 0, 191, 255 },&lt;br /&gt;
  dimgray = { 105, 105, 105 },&lt;br /&gt;
  dimgrey = { 105, 105, 105 },&lt;br /&gt;
  dodgerblue = { 30, 144, 255 },&lt;br /&gt;
  firebrick = { 178, 34, 34 },&lt;br /&gt;
  floralwhite = { 255, 250, 240 },&lt;br /&gt;
  forestgreen = { 34, 139, 34 },&lt;br /&gt;
  fuchsia = { 255, 0, 255 },&lt;br /&gt;
  gainsboro = { 220, 220, 220 },&lt;br /&gt;
  ghostwhite = { 248, 248, 255 },&lt;br /&gt;
  gold = { 255, 215, 0 },&lt;br /&gt;
  goldenrod = { 218, 165, 32 },&lt;br /&gt;
  gray = { 128, 128, 128 },&lt;br /&gt;
  green = { 0, 128, 0 },&lt;br /&gt;
  greenyellow = { 173, 255, 47 },&lt;br /&gt;
  grey = { 128, 128, 128 },&lt;br /&gt;
  honeydew = { 240, 255, 240 },&lt;br /&gt;
  hotpink = { 255, 105, 180 },&lt;br /&gt;
  indianred = { 205, 92, 92 },&lt;br /&gt;
  indigo = { 75, 0, 130 },&lt;br /&gt;
  ivory = { 255, 255, 240 },&lt;br /&gt;
  khaki = { 240, 230, 140 },&lt;br /&gt;
  lavender = { 230, 230, 250 },&lt;br /&gt;
  lavenderblush = { 255, 240, 245 },&lt;br /&gt;
  lawngreen = { 124, 252, 0 },&lt;br /&gt;
  lemonchiffon = { 255, 250, 205 },&lt;br /&gt;
  lightblue = { 173, 216, 230 },&lt;br /&gt;
  lightcoral = { 240, 128, 128 },&lt;br /&gt;
  lightcyan = { 224, 255, 255 },&lt;br /&gt;
  lightgoldenrodyellow = { 250, 250, 210 },&lt;br /&gt;
  lightgray = { 211, 211, 211 },&lt;br /&gt;
  lightgreen = { 144, 238, 144 },&lt;br /&gt;
  lightgrey = { 211, 211, 211 },&lt;br /&gt;
  lightpink = { 255, 182, 193 },&lt;br /&gt;
  lightsalmon = { 255, 160, 122 },&lt;br /&gt;
  lightseagreen = { 32, 178, 170 },&lt;br /&gt;
  lightskyblue = { 135, 206, 250 },&lt;br /&gt;
  lightslategray = { 119, 136, 153 },&lt;br /&gt;
  lightslategrey = { 119, 136, 153 },&lt;br /&gt;
  lightsteelblue = { 176, 196, 222 },&lt;br /&gt;
  lightyellow = { 255, 255, 224 },&lt;br /&gt;
  lime = { 0, 255, 0 },&lt;br /&gt;
  limegreen = { 50, 205, 50 },&lt;br /&gt;
  linen = { 250, 240, 230 },&lt;br /&gt;
  magenta = { 255, 0, 255 },&lt;br /&gt;
  maroon = { 128, 0, 0 },&lt;br /&gt;
  mediumaquamarine = { 102, 205, 170 },&lt;br /&gt;
  mediumblue = { 0, 0, 205 },&lt;br /&gt;
  mediumorchid = { 186, 85, 211 },&lt;br /&gt;
  mediumpurple = { 147, 112, 219 },&lt;br /&gt;
  mediumseagreen = { 60, 179, 113 },&lt;br /&gt;
  mediumslateblue = { 123, 104, 238 },&lt;br /&gt;
  mediumspringgreen = { 0, 250, 154 },&lt;br /&gt;
  mediumturquoise = { 72, 209, 204 },&lt;br /&gt;
  mediumvioletred = { 199, 21, 133 },&lt;br /&gt;
  midnightblue = { 25, 25, 112 },&lt;br /&gt;
  mintcream = { 245, 255, 250 },&lt;br /&gt;
  mistyrose = { 255, 228, 225 },&lt;br /&gt;
  moccasin = { 255, 228, 181 },&lt;br /&gt;
  navajowhite = { 255, 222, 173 },&lt;br /&gt;
  navy = { 0, 0, 128 },&lt;br /&gt;
  oldlace = { 253, 245, 230 },&lt;br /&gt;
  olive = { 128, 128, 0 },&lt;br /&gt;
  olivedrab = { 107, 142, 35 },&lt;br /&gt;
  orange = { 255, 165, 0 },&lt;br /&gt;
  orangered = { 255, 69, 0 },&lt;br /&gt;
  orchid = { 218, 112, 214 },&lt;br /&gt;
  palegoldenrod = { 238, 232, 170 },&lt;br /&gt;
  palegreen = { 152, 251, 152 },&lt;br /&gt;
  paleturquoise = { 175, 238, 238 },&lt;br /&gt;
  palevioletred = { 219, 112, 147 },&lt;br /&gt;
  papayawhip = { 255, 239, 213 },&lt;br /&gt;
  peachpuff = { 255, 218, 185 },&lt;br /&gt;
  peru = { 205, 133, 63 },&lt;br /&gt;
  pink = { 255, 192, 203 },&lt;br /&gt;
  plum = { 221, 160, 221 },&lt;br /&gt;
  powderblue = { 176, 224, 230 },&lt;br /&gt;
  purple = { 128, 0, 128 },&lt;br /&gt;
  red = { 255, 0, 0 },&lt;br /&gt;
  rosybrown = { 188, 143, 143 },&lt;br /&gt;
  royalblue = { 65, 105, 225 },&lt;br /&gt;
  saddlebrown = { 139, 69, 19 },&lt;br /&gt;
  salmon = { 250, 128, 114 },&lt;br /&gt;
  sandybrown = { 244, 164, 96 },&lt;br /&gt;
  seagreen = { 46, 139, 87 },&lt;br /&gt;
  seashell = { 255, 245, 238 },&lt;br /&gt;
  sienna = { 160, 82, 45 },&lt;br /&gt;
  silver = { 192, 192, 192 },&lt;br /&gt;
  skyblue = { 135, 206, 235 },&lt;br /&gt;
  slateblue = { 106, 90, 205 },&lt;br /&gt;
  slategray = { 112, 128, 144 },&lt;br /&gt;
  slategrey = { 112, 128, 144 },&lt;br /&gt;
  snow = { 255, 250, 250 },&lt;br /&gt;
  springgreen = { 0, 255, 127 },&lt;br /&gt;
  steelblue = { 70, 130, 180 },&lt;br /&gt;
  tan = { 210, 180, 140 },&lt;br /&gt;
  teal = { 0, 128, 128 },&lt;br /&gt;
  thistle = { 216, 191, 216 },&lt;br /&gt;
  tomato = { 255, 99, 71 },&lt;br /&gt;
  turquoise = { 64, 224, 208 },&lt;br /&gt;
  violet = { 238, 130, 238 },&lt;br /&gt;
  wheat = { 245, 222, 179 },&lt;br /&gt;
  white = { 255, 255, 255 },&lt;br /&gt;
  whitesmoke = { 245, 245, 245 },&lt;br /&gt;
  yellow = { 255, 255, 0 },&lt;br /&gt;
  yellowgreen = { 154, 205, 50 },&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local rgbRegex = &amp;#039;^rgb%(%s-(%d-),%s-(%d-)%s-,%s-(%d-)%s-%)$&amp;#039;&lt;br /&gt;
local rgbaRegex = &amp;#039;^rgba%(%s-(%d-),%s-(%d-)%s-,%s-(%d-)%s-,%s-([%d%.]+)%s-%)$&amp;#039;&lt;br /&gt;
local hslRegex = &amp;#039;^hsl%(%s-(%d-),%s-(%d-)%%%s-,%s-(%d-)%%%s-%)$&amp;#039;&lt;br /&gt;
local hslaRegex = &amp;#039;^hsla%(%s-(%d-),%s-(%d-)%%%s-,%s-(%d-)%%%s-,%s-([%d%.]+)%s-%)$&amp;#039;&lt;br /&gt;
local hexRegex = &amp;#039;^#(%x%x)(%x%x)(%x%x)$&amp;#039;&lt;br /&gt;
local hexShorthandRegex = &amp;#039;^#(%x)(%x)(%x)$&amp;#039;&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  Color实例结构&lt;br /&gt;
  interface ColorInstance {&lt;br /&gt;
	__index = Color&lt;br /&gt;
    value: [number, number, number]&lt;br /&gt;
    format: &amp;#039;rgb&amp;#039; | &amp;#039;hsl&amp;#039;&lt;br /&gt;
    opacity: number&lt;br /&gt;
  }&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local Color = {}&lt;br /&gt;
local colorMetaTable = { __index = Color }&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @param {number} min&lt;br /&gt;
  @param {number} max&lt;br /&gt;
  &lt;br /&gt;
  @return {number}&lt;br /&gt;
]]&lt;br /&gt;
local function _random(min, max)&lt;br /&gt;
  return tonumber(mw.getCurrentFrame():expandTemplate{ title = &amp;#039;random&amp;#039;, args = { min, max } })&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc 操作颜色加深减淡&lt;br /&gt;
&lt;br /&gt;
  @param {[number, number, number]} rgb&lt;br /&gt;
  @param {&amp;#039;+&amp;#039; | &amp;#039;-&amp;#039;} operator - 加深，减淡&lt;br /&gt;
  @param {number} ratio 范围：0 ~ 100&lt;br /&gt;
&lt;br /&gt;
  @return {[number, number, number]}&lt;br /&gt;
]]&lt;br /&gt;
local function _computeRgb(rgb, operator, ratio)&lt;br /&gt;
  local ranges = {}&lt;br /&gt;
  local cloneRgb = { rgb[1], rgb[2], rgb[3] }&lt;br /&gt;
  for i, v in ipairs(rgb) do&lt;br /&gt;
    ranges[i] = {&lt;br /&gt;
      [&amp;#039;-&amp;#039;] = (255 - v) / 100,&lt;br /&gt;
      [&amp;#039;+&amp;#039;] = -v / 100&lt;br /&gt;
    }&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  for i, v in ipairs(cloneRgb) do&lt;br /&gt;
    cloneRgb[i] = v + ranges[i][operator] * ratio&lt;br /&gt;
    if cloneRgb[i] &amp;lt; 0 then cloneRgb[i] = 0 end&lt;br /&gt;
    if cloneRgb[i] &amp;gt; 255 then cloneRgb[i] = 255 end&lt;br /&gt;
  end&lt;br /&gt;
  return cloneRgb&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc 判断一个字符串或table是否为合法的color值&lt;br /&gt;
  @param {(string | [number, number, number])} rawValue - 接受一个字符串或数组table，有效的格式有：css颜色关键字，hex颜色，hex简写颜色，rgb函数，rgba函数，hsl函数，hsla函数&lt;br /&gt;
&lt;br /&gt;
  @return {boolean}&lt;br /&gt;
]]&lt;br /&gt;
function Color.isColorStr(rawValue)&lt;br /&gt;
  if type(rawValue) == &amp;#039;string&amp;#039; then&lt;br /&gt;
    if&lt;br /&gt;
      rawValue:match(rgbRegex) or&lt;br /&gt;
      rawValue:match(rgbaRegex) or&lt;br /&gt;
      rawValue:match(hslRegex) or&lt;br /&gt;
      rawValue:match(hslaRegex) or&lt;br /&gt;
      colorKeywords[rawValue]&lt;br /&gt;
    then return true end&lt;br /&gt;
    rawValue = mw.text.unstripNoWiki(rawValue)&lt;br /&gt;
      :gsub(&amp;#039;^&amp;amp;#35;&amp;#039;, &amp;#039;#&amp;#039;)  -- 为了避免解析器自动换行，一些返回颜色值的模板常用&amp;#039;&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;&amp;#039;或&amp;#039;&amp;amp;#35;&amp;#039;代替&amp;#039;#&amp;#039;&lt;br /&gt;
      :gsub(&amp;#039;^＃&amp;#039;, &amp;#039;#&amp;#039;)  -- Bhsd加的全角字符兼容，不知道为啥&lt;br /&gt;
    if&lt;br /&gt;
      rawValue:match(hexRegex) or&lt;br /&gt;
      rawValue:match(hexShorthandRegex)&lt;br /&gt;
    then return true end&lt;br /&gt;
  elseif type(rawValue) == &amp;#039;table&amp;#039; then&lt;br /&gt;
    if #rawValue ~= 3 and #rawValue ~= 4 then return false end&lt;br /&gt;
    for _, v in ipairs(rawValue) do&lt;br /&gt;
      if type(v) ~= &amp;#039;number&amp;#039; then return false end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  return false&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc 创建一个Color实例&lt;br /&gt;
  @param {(string | [number, number, number])} rawValue - 接受一个字符串或数组table，有效的格式有：css颜色关键字，hex颜色，hex简写颜色，rgb函数，rgba函数，hsl函数，hsla函数&lt;br /&gt;
&lt;br /&gt;
  @return {(Color | nil)} - 如果rawValue无效，则返回nil&lt;br /&gt;
]]&lt;br /&gt;
function Color.create(rawValue)&lt;br /&gt;
  if not Color.isColorStr(rawValue) then return nil end&lt;br /&gt;
  if type(rawValue) == &amp;#039;string&amp;#039; then&lt;br /&gt;
    rawValue =     mw.text.unstripNoWiki(rawValue)&lt;br /&gt;
      :gsub(&amp;#039;^&amp;amp;#35;&amp;#039;, &amp;#039;#&amp;#039;)  -- 为了避免解析器自动换行，一些返回颜色值的模板常用&amp;#039;&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;&amp;#039;或&amp;#039;&amp;amp;#35;&amp;#039;代替&amp;#039;#&amp;#039;&lt;br /&gt;
      :gsub(&amp;#039;^＃&amp;#039;, &amp;#039;#&amp;#039;)  -- Bhsd加的全角字符兼容，不知道为啥&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  local color = setmetatable({}, colorMetaTable)&lt;br /&gt;
&lt;br /&gt;
  local r_h, g_s, b_l, opacity -- rgb or hsl&lt;br /&gt;
  if type(rawValue) == &amp;#039;string&amp;#039; then&lt;br /&gt;
		if rawValue:match(rgbRegex) then&lt;br /&gt;
			color.format = &amp;#039;rgb&amp;#039;&lt;br /&gt;
      r_h, g_s, b_l = rawValue:match(rgbRegex)&lt;br /&gt;
&lt;br /&gt;
      r_h = tonumber(r_h)&lt;br /&gt;
      g_s = tonumber(g_s)&lt;br /&gt;
      b_l = tonumber(b_l)&lt;br /&gt;
		elseif rawValue:match(rgbaRegex) then&lt;br /&gt;
			color.format = &amp;#039;rgb&amp;#039;&lt;br /&gt;
      r_h, g_s, b_l, opacity = rawValue:match(rgbaRegex)&lt;br /&gt;
&lt;br /&gt;
      r_h = tonumber(r_h)&lt;br /&gt;
      g_s = tonumber(g_s)&lt;br /&gt;
      b_l = tonumber(b_l)&lt;br /&gt;
			opacity = tonumber(opacity)&lt;br /&gt;
		elseif rawValue:match(hslRegex) then&lt;br /&gt;
			color.format = &amp;#039;hsl&amp;#039;&lt;br /&gt;
			r_h, g_s, b_l = rawValue:match(hslRegex)&lt;br /&gt;
&lt;br /&gt;
      r_h = tonumber(r_h)&lt;br /&gt;
      g_s = tonumber(g_s)&lt;br /&gt;
      b_l = tonumber(b_l)&lt;br /&gt;
		elseif rawValue:match(hslaRegex) then&lt;br /&gt;
			color.format = &amp;#039;hsl&amp;#039;&lt;br /&gt;
      r_h, g_s, b_l, opacity = rawValue:match(hslaRegex)&lt;br /&gt;
&lt;br /&gt;
      r_h = tonumber(r_h)&lt;br /&gt;
      g_s = tonumber(g_s)&lt;br /&gt;
      b_l = tonumber(b_l)&lt;br /&gt;
			opacity = tonumber(opacity)&lt;br /&gt;
		elseif rawValue:match(hexRegex) then&lt;br /&gt;
			color.format = &amp;#039;rgb&amp;#039;&lt;br /&gt;
      r_h, g_s, b_l = rawValue:match(hexRegex)&lt;br /&gt;
      r_h = tonumber(r_h, 16)&lt;br /&gt;
      g_s = tonumber(g_s, 16)&lt;br /&gt;
			b_l = tonumber(b_l, 16)&lt;br /&gt;
		elseif rawValue:match(hexShorthandRegex) then&lt;br /&gt;
			color.format = &amp;#039;rgb&amp;#039;&lt;br /&gt;
      r_h, g_s, b_l = rawValue:match(hexShorthandRegex)&lt;br /&gt;
      r_h = tonumber(r_h, 16) * 17&lt;br /&gt;
      g_s = tonumber(g_s, 16) * 17&lt;br /&gt;
			b_l = tonumber(b_l, 16) * 17&lt;br /&gt;
		else&lt;br /&gt;
			color.format = &amp;#039;rgb&amp;#039;&lt;br /&gt;
      local colorkeywordRgb = colorKeywords[rawValue]&lt;br /&gt;
      r_h = colorkeywordRgb[1]&lt;br /&gt;
      g_s = colorkeywordRgb[2]&lt;br /&gt;
      b_l = colorkeywordRgb[3]&lt;br /&gt;
    end&lt;br /&gt;
	elseif type(rawValue) == &amp;#039;table&amp;#039; then&lt;br /&gt;
		color.format = &amp;#039;rgb&amp;#039;&lt;br /&gt;
    r_h = rawValue[1]&lt;br /&gt;
    g_s = rawValue[2]&lt;br /&gt;
    b_l = rawValue[3]&lt;br /&gt;
    opacity = rawValue[4]&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  color.value = { r_h, g_s, b_l }&lt;br /&gt;
  color.opacity = opacity or 1&lt;br /&gt;
  return color&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc 克隆一个Color对象&lt;br /&gt;
&lt;br /&gt;
  @param {Color} this&lt;br /&gt;
&lt;br /&gt;
  @return {Color} - 一个新的Color对象&lt;br /&gt;
]]&lt;br /&gt;
function Color.clone(this)&lt;br /&gt;
  local rgb = this:rgb().value&lt;br /&gt;
  return Color.create(rgb):setOpacity(this.opacity)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc rgb转hsl&lt;br /&gt;
&lt;br /&gt;
  @param {number} r&lt;br /&gt;
  @param {number} g&lt;br /&gt;
  @param {number} b&lt;br /&gt;
&lt;br /&gt;
  @return [number, number, number] - 返回的所有值均为整数&lt;br /&gt;
]]&lt;br /&gt;
function Color.rgb2hsl(r, g, b)&lt;br /&gt;
  r = r / 255&lt;br /&gt;
  g = g / 255&lt;br /&gt;
  b = b / 255&lt;br /&gt;
&lt;br /&gt;
  local max = math.max(r, g, b)&lt;br /&gt;
  local min = math.min(r, g, b)&lt;br /&gt;
  local diff = max - min&lt;br /&gt;
&lt;br /&gt;
  local h, s&lt;br /&gt;
  local l = (max + min) / 2&lt;br /&gt;
&lt;br /&gt;
  if max == min then&lt;br /&gt;
    h = 0&lt;br /&gt;
    s = 0&lt;br /&gt;
  elseif max == r and g &amp;gt;= b then&lt;br /&gt;
    h = 60 * ((g - b) / diff)&lt;br /&gt;
  elseif max == r and g &amp;lt; b then&lt;br /&gt;
    h = 60 * ((g - b) / diff) + 360&lt;br /&gt;
  elseif max == g then&lt;br /&gt;
    h = 60 * ((b - r) / diff) + 120&lt;br /&gt;
  elseif max == b then&lt;br /&gt;
    h = 60 * ((r - g) / diff) + 240&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  if l == 0 or max == min then&lt;br /&gt;
    s = 0&lt;br /&gt;
  elseif 0 &amp;lt; 1 and l &amp;lt;= 0.5 then&lt;br /&gt;
    s = diff / (2 * l)&lt;br /&gt;
  elseif l &amp;gt; 0.5 then&lt;br /&gt;
    s = diff / (2 - 2 * l)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  return {&lt;br /&gt;
    math.floor(h + 0.5),&lt;br /&gt;
    math.floor(s * 100 + 0.5),&lt;br /&gt;
    math.floor(l * 100 + 0.5)&lt;br /&gt;
  }&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc hsl转rgb&lt;br /&gt;
&lt;br /&gt;
  @param {number} h&lt;br /&gt;
  @param {number} s - css中使用百分比，但该函数需要传整数 50% =&amp;gt; 50&lt;br /&gt;
  @param {number} l - css中使用百分比，但该函数需要传整数 50% =&amp;gt; 50&lt;br /&gt;
&lt;br /&gt;
  @return [number, number, number]&lt;br /&gt;
]]&lt;br /&gt;
function Color.hsl2rgb(h, s, l)&lt;br /&gt;
  h = h % 360&lt;br /&gt;
  s = s / 100&lt;br /&gt;
  l = l / 100&lt;br /&gt;
&lt;br /&gt;
  local c = (1 - math.abs(2 * l - 1)) * s&lt;br /&gt;
  local x = c * (1 - math.abs(((h / 60) % 2) - 1))&lt;br /&gt;
  local m = l - c / 2&lt;br /&gt;
  local vRGB = {}&lt;br /&gt;
&lt;br /&gt;
  if h &amp;gt;=0 and h &amp;lt; 60 then&lt;br /&gt;
    vRGB = {c, x, 0}&lt;br /&gt;
  elseif h &amp;gt;= 60 and h &amp;lt; 120 then&lt;br /&gt;
    vRGB = {x, c, 0}&lt;br /&gt;
  elseif h &amp;gt;= 120 and h &amp;lt; 180 then&lt;br /&gt;
    vRGB = {0, c, x}&lt;br /&gt;
  elseif h &amp;gt;= 180 and h &amp;lt; 240 then&lt;br /&gt;
    vRGB = {0, x, c}&lt;br /&gt;
  elseif h &amp;gt;= 240 and h &amp;lt; 300 then&lt;br /&gt;
    vRGB = {x, 0, c}&lt;br /&gt;
  elseif h &amp;gt;= 300 and h &amp;lt; 360 then&lt;br /&gt;
    vRGB = {c, 0, x}&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  local r = 255 * (vRGB[1] + m)&lt;br /&gt;
  local g = 255 * (vRGB[2] + m)&lt;br /&gt;
  local b = 255 * (vRGB[3] + m)&lt;br /&gt;
&lt;br /&gt;
  return {&lt;br /&gt;
    math.floor(r + 0.5),&lt;br /&gt;
    math.floor(g + 0.5),&lt;br /&gt;
    math.floor(b + 0.5)&lt;br /&gt;
  }&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc 将color对象的数据转为rgb格式&lt;br /&gt;
&lt;br /&gt;
  @param {Color} this&lt;br /&gt;
  @return {Color} - this&lt;br /&gt;
]]&lt;br /&gt;
function Color.rgb(this)&lt;br /&gt;
  if this.format == &amp;#039;rgb&amp;#039; then return this end&lt;br /&gt;
  if this.format == &amp;#039;hsl&amp;#039; then&lt;br /&gt;
    this.value = Color.hsl2rgb(this.value[1], this.value[2], this.value[3])&lt;br /&gt;
    this.format = &amp;#039;rgb&amp;#039;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  return this&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc 将color对象的数据转为hsl格式&lt;br /&gt;
&lt;br /&gt;
  @param {Color} this&lt;br /&gt;
  @return {Color} - this&lt;br /&gt;
]]&lt;br /&gt;
function Color.hsl(this)&lt;br /&gt;
  if this.format == &amp;#039;hsl&amp;#039; then return this end&lt;br /&gt;
  if this.format == &amp;#039;rgb&amp;#039; then&lt;br /&gt;
    this.value = Color.rgb2hsl(this.value[1], this.value[2], this.value[3])&lt;br /&gt;
    this.format = &amp;#039;hsl&amp;#039;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  return this&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc 加深一个颜色(明度-)&lt;br /&gt;
&lt;br /&gt;
  @param {Color} this&lt;br /&gt;
  @param {number} ratio - 范围：0 ~ 100&lt;br /&gt;
&lt;br /&gt;
  @return {Color} - this&lt;br /&gt;
]]&lt;br /&gt;
function Color.darken(this, ratio)&lt;br /&gt;
  local rgb = this:rgb().value&lt;br /&gt;
  this.value = _computeRgb(rgb, &amp;#039;+&amp;#039;, ratio)&lt;br /&gt;
&lt;br /&gt;
  return this&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc 减淡一个颜色(明度+)&lt;br /&gt;
&lt;br /&gt;
  @param {Color} this&lt;br /&gt;
  @param {number} ratio - 范围：0 ~ 100&lt;br /&gt;
&lt;br /&gt;
  @return {Color} - this&lt;br /&gt;
]]&lt;br /&gt;
function Color.lighten(this, ratio)&lt;br /&gt;
  local rgb = this:rgb().value&lt;br /&gt;
  this.value = _computeRgb(rgb, &amp;#039;-&amp;#039;, ratio)&lt;br /&gt;
&lt;br /&gt;
  return this&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc 提高一个颜色的饱和度&lt;br /&gt;
&lt;br /&gt;
  @param {Color} this&lt;br /&gt;
  @param {number} ratio - 范围：0 ~ 100&lt;br /&gt;
&lt;br /&gt;
  @return {Color} - this&lt;br /&gt;
]]&lt;br /&gt;
function Color.saturate(this, ratio)&lt;br /&gt;
  local hsl = this:hsl().value&lt;br /&gt;
  this.value[2] = hsl[2] + (100 - hsl[2]) * (ratio / 100)&lt;br /&gt;
  if this.value[2] &amp;gt; 100 then this.value[2] = 100 end&lt;br /&gt;
&lt;br /&gt;
  return this&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc 降低一个颜色的饱和度&lt;br /&gt;
&lt;br /&gt;
  @param {Color} this&lt;br /&gt;
  @param {number} ratio - 范围：0 ~ 100&lt;br /&gt;
&lt;br /&gt;
  @return {Color} - this&lt;br /&gt;
]]&lt;br /&gt;
function Color.desaturate(this, ratio)&lt;br /&gt;
  local hsl = this:hsl().value&lt;br /&gt;
  this.value[2] = hsl[2] - hsl[2] * (ratio / 100)&lt;br /&gt;
  if this.value[2] &amp;lt; 0 then this.value[2] = 0 end&lt;br /&gt;
&lt;br /&gt;
  return this&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc 混合两个颜色&lt;br /&gt;
&lt;br /&gt;
  @param {Color} this 颜色1&lt;br /&gt;
  @param {Color} color 颜色2&lt;br /&gt;
  @param {number} weight 颜色1比重 范围：0 ~ 100，默认值为50&lt;br /&gt;
&lt;br /&gt;
  @return {Color} this&lt;br /&gt;
]]&lt;br /&gt;
function Color.mix(this, color, weight)&lt;br /&gt;
  local color1 = this:rgb()&lt;br /&gt;
  local color2 = color:rgb()&lt;br /&gt;
  local p = weight == nil and 50 or weight&lt;br /&gt;
  p = p / 100&lt;br /&gt;
&lt;br /&gt;
  local w = 2 * p - 1&lt;br /&gt;
  local a = color1.opacity - color2.opacity&lt;br /&gt;
&lt;br /&gt;
  local w1 = (((w * a == -1) and w or (w + a) / (1 + w * a)) + 1) / 2.0&lt;br /&gt;
  local w2 = 1 - w1&lt;br /&gt;
&lt;br /&gt;
  this.value = {&lt;br /&gt;
    w1 * color1.value[1] + w2 * color2.value[1],&lt;br /&gt;
    w1 * color1.value[2] + w2 * color2.value[2],&lt;br /&gt;
    w1 * color1.value[3] + w2 * color2.value[3]&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  this:setOpacity(color1.opacity * p + color2.opacity * (1 - p))&lt;br /&gt;
&lt;br /&gt;
  return this&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc 设置一个值的不透明度&lt;br /&gt;
&lt;br /&gt;
  @param {Color} this&lt;br /&gt;
  @param {number} value - 范围：0 ~ 1&lt;br /&gt;
&lt;br /&gt;
  @return {Color} - this&lt;br /&gt;
]]&lt;br /&gt;
function Color.setOpacity(this, value)&lt;br /&gt;
  this.opacity = tonumber(value)&lt;br /&gt;
  return this&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc Gamma校正&lt;br /&gt;
&lt;br /&gt;
  @param {number} r_g_b&lt;br /&gt;
  @return {number}&lt;br /&gt;
]]&lt;br /&gt;
local function adjustGamma(r_g_b)&lt;br /&gt;
  if r_g_b &amp;lt;= 0.04045 then return r_g_b / 12.92&lt;br /&gt;
  else return ((r_g_b + 0.055) / 1.055) ^ 2.4 end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc 获得颜色的相对亮度&lt;br /&gt;
&lt;br /&gt;
  @param {Color} this&lt;br /&gt;
  @return {number}&lt;br /&gt;
]]&lt;br /&gt;
function Color.getRelativeLuminance(this)&lt;br /&gt;
  local rgb = this:rgb().value&lt;br /&gt;
  return 0.2126 * adjustGamma(rgb[1] / 255) +&lt;br /&gt;
         0.7152 * adjustGamma(rgb[2] / 255) +&lt;br /&gt;
         0.0722 * adjustGamma(rgb[3] / 255)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc 获得两颜色的对比度比例&lt;br /&gt;
&lt;br /&gt;
  @param {Color} this&lt;br /&gt;
  @param {Color} color&lt;br /&gt;
  @return {number}&lt;br /&gt;
]]&lt;br /&gt;
function Color.getContrastRatio(this, color)&lt;br /&gt;
  local ratio = (this:getRelativeLuminance() + 0.05) / (color:getRelativeLuminance() + 0.05)&lt;br /&gt;
  if ratio &amp;lt; 1 then return 1 / ratio&lt;br /&gt;
  else return ratio end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc 检测一个颜色是否为亮色&lt;br /&gt;
&lt;br /&gt;
  @param {Color} this&lt;br /&gt;
  @return {boolean}&lt;br /&gt;
]]&lt;br /&gt;
function Color.isLight(this)&lt;br /&gt;
  return this:getRelativeLuminance() &amp;gt; (0.05 * 1.05) ^ 0.5 - 0.05&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc 检测一个颜色是否为暗色&lt;br /&gt;
&lt;br /&gt;
  @param {Color} this&lt;br /&gt;
  @return {boolean}&lt;br /&gt;
]]&lt;br /&gt;
function Color.isDark(this)&lt;br /&gt;
  return this:isLight() == false&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc 根据范围随机产生一个颜色&lt;br /&gt;
&lt;br /&gt;
  @param {number} [min = 0] - 范围：0 ~ 255&lt;br /&gt;
  @param {number} [max = 255] - 范围：0 ~ 255&lt;br /&gt;
&lt;br /&gt;
  @return {Color}&lt;br /&gt;
]]&lt;br /&gt;
function Color.random(min, max)&lt;br /&gt;
  min = min or 0&lt;br /&gt;
  max = max or 255&lt;br /&gt;
&lt;br /&gt;
  local rgb = {&lt;br /&gt;
    _random(min, max),&lt;br /&gt;
    _random(min, max),&lt;br /&gt;
    _random(min, max)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  return Color.create(rgb)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc 反转一个颜色&lt;br /&gt;
&lt;br /&gt;
  @param {Color} this&lt;br /&gt;
&lt;br /&gt;
  @return {Color} - this&lt;br /&gt;
]]&lt;br /&gt;
function Color.reverse(this)&lt;br /&gt;
  local rgb = this:rgb().value&lt;br /&gt;
  for i, v in ipairs(rgb) do&lt;br /&gt;
    rgb[i] = math.abs(v - 255)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  return this&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
  @desc 将一个Color实例转化为有效的css颜色值字符串&lt;br /&gt;
&lt;br /&gt;
  @param {Color} this&lt;br /&gt;
  @param {(&amp;#039;auto&amp;#039; | &amp;#039;hex&amp;#039; | &amp;#039;hex-opacity&amp;#039;)} [format = &amp;#039;auto&amp;#039;] - 格式，&lt;br /&gt;
    为auto时，根据Color对象本身的format进行转换，使用对应的css函数，并保留透明度。在调用前应该先执行rgb()或hsl()，以明确输出格式。&lt;br /&gt;
    为hex时，返回hex颜色。无视透明度。&lt;br /&gt;
    为hex-opacity时，返回hex颜色。若不透明度不为1，则假定背景为白色将透明度和颜色进行计算。&lt;br /&gt;
]]&lt;br /&gt;
function Color.toString(this, format)&lt;br /&gt;
  local function toHex(num)&lt;br /&gt;
    local int, float = math.modf(num)&lt;br /&gt;
    if float &amp;gt; 0.4 then int = int + 1 end&lt;br /&gt;
    local zero = &amp;#039;&amp;#039;&lt;br /&gt;
    if int &amp;lt; 16 then zero = &amp;#039;0&amp;#039; end&lt;br /&gt;
    return zero..string.format(&amp;#039;%X&amp;#039;, int)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  format = format or &amp;#039;auto&amp;#039;&lt;br /&gt;
  if format == &amp;#039;auto&amp;#039; then&lt;br /&gt;
    if this.format == &amp;#039;rgb&amp;#039; then&lt;br /&gt;
      if this.opacity &amp;gt;= 0 and this.opacity &amp;lt; 1 then&lt;br /&gt;
        return &amp;#039;rgba(&amp;#039;..table.concat(this.value, &amp;#039;,&amp;#039;)..&amp;#039;,&amp;#039;..this.opacity..&amp;#039;)&amp;#039;&lt;br /&gt;
      else&lt;br /&gt;
        return &amp;#039;rgb(&amp;#039;..table.concat(this.value, &amp;#039;,&amp;#039;)..&amp;#039;)&amp;#039;&lt;br /&gt;
      end&lt;br /&gt;
    elseif this.format == &amp;#039;hsl&amp;#039; then&lt;br /&gt;
      local hsl = this.value&lt;br /&gt;
      if this.opacity &amp;gt;= 0 and this.opacity &amp;lt; 1 then&lt;br /&gt;
        return string.format(&amp;#039;hsla(%s, %s%%, %s%%, %s)&amp;#039;, hsl[1], hsl[2], hsl[3], this.opacity)&lt;br /&gt;
      else&lt;br /&gt;
        return string.format(&amp;#039;hsl(%s, %s%%, %s%%)&amp;#039;, hsl[1], hsl[2], hsl[3])&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  elseif format == &amp;#039;hex&amp;#039; then&lt;br /&gt;
    this:rgb()&lt;br /&gt;
    return &amp;#039;#&amp;#039;..toHex(this.value[1])..toHex(this.value[2])..toHex(this.value[3])&lt;br /&gt;
  elseif format == &amp;#039;hex-opacity&amp;#039; then&lt;br /&gt;
    this:rgb()&lt;br /&gt;
    local r = this.value[1]&lt;br /&gt;
    local g = this.value[2]&lt;br /&gt;
    local b = this.value[3]&lt;br /&gt;
&lt;br /&gt;
    r = r + r * (1 - this.opacity)&lt;br /&gt;
    g = g + g * (1 - this.opacity)&lt;br /&gt;
    b = b + b * (1 - this.opacity)&lt;br /&gt;
&lt;br /&gt;
    if r &amp;gt; 255 then r = 255 end&lt;br /&gt;
    if g &amp;gt; 255 then g = 255 end&lt;br /&gt;
    if b &amp;gt; 255 then b = 255 end&lt;br /&gt;
&lt;br /&gt;
    return &amp;#039;#&amp;#039;..toHex(r)..toHex(g)..toHex(b)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return Color&lt;/div&gt;</summary>
		<author><name>abaaba&gt;Lihb</name></author>
	</entry>
</feed>