showColors() and color_table

Post Reply
Eraene
Posts: 42
Joined: Wed Nov 27, 2013 10:18 pm

showColors() and color_table

Post by Eraene »

If I wanted to sort color_table by a r, g, or b value, is there a way to do that by changing the showColors() function in GUIUtils.lua?

For reference, here is the showColors() function:
Code: [show] | [select all] lua
function showColors(...)
  local cols = ... or 3
  local i = 1
  for k,v in pairs(color_table) do
    local fg
    local luminosity = (0.2126 * ((v[1]/255)^2.2)) + (0.7152 * ((v[2]/255)^2.2)) + (0.0722 * ((v[3]/255)^2.2))
    if luminosity > 0.5 then
      fg = "black"
    else
      fg = "white"
    end
    cecho(string.format("<%s:%s>%s%s", fg, k, k, string.rep(" ", 23-k:len())))
    echo"  "
    if i == cols then
      echo"\n"
      i = 1
    else
      i = i + 1
    end
  end
end

Post Reply