Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Message
| Swatches from the new colour cube:

Lua code to generate the above:
values = { 0,
95,
95 + 40,
95 + 40 + 40,
95 + 40 + 40 + 40,
95 + 40 + 40 + 40 + 40
};
which = 16
print (string.rep ("-", 80))
print""
for red = 0, 5 do
for green = 0, 5 do
for blue = 0, 5 do
Tell (string.format (" %3i: ", which))
ColourTell ("",
RGBColourToName (values [red + 1] +
values [green + 1] * 256 +
values [blue + 1] * 65536),
" ")
which = which + 1
end -- of for each blue
print ""
end -- of for each green
print ""
end -- of for each read
-- grayscale stuff
gray = 8
for line = 1, 4 do
for col = 1, 6 do
Tell (string.format (" %3i: ", which))
ColourTell ("",
RGBColourToName (gray +
gray * 256 +
gray * 65536),
" ")
which = which + 1
gray = gray + 10
end -- for each line
print ""
end -- for each col
print ""
Swatches with hex codes:

Lua code to generate the above:
values = { 0,
95,
95 + 40,
95 + 40 + 40,
95 + 40 + 40 + 40,
95 + 40 + 40 + 40 + 40
};
which = 16
print (string.rep ("-", 80))
print""
for red = 0, 5 do
for green = 0, 5 do
for blue = 0, 5 do
colour = values [red + 1] +
values [green + 1] * 256 +
values [blue + 1] * 65536
textcolour = "white"
if values [red + 1] + values [green + 1] + values [blue + 1] > (128 * 3) then
textcolour = "black"
end -- if
ColourTell (textcolour, RGBColourToName (colour),
string.format (" %3i: %02X%02X%02X ",
which, values [red + 1], values [green + 1], values [blue + 1] ))
Tell " "
which = which + 1
end -- of for each blue
print ""
end -- of for each green
print ""
end -- of for each read
-- grayscale stuff
gray = 8
for line = 1, 4 do
for col = 1, 6 do
colour = gray +
gray * 256 +
gray * 65536
textcolour = "white"
if gray > 128 then
textcolour = "black"
end -- if
ColourTell (textcolour, RGBColourToName (colour), string.format (" %3i: %06X ", which, colour))
Tell " "
which = which + 1
gray = gray + 10
end -- for each line
print ""
end -- for each col
print ""
By way of comparison, here are the "official" colour names used by the client, sorted into "sort of" colour order:

Lua code to generate the above:
print ""
t = {}
for k, v in pairs (colour_names) do
table.insert (t, k)
end -- for
table.sort (t, function (a, b)
col1 = colour_names [a]
col2 = colour_names [b]
r1 = bit.band (col1, 0xFF)
r2 = bit.band (col2, 0xFF)
-- slight adjustment so identical colours sort together
g1 = bit.band (bit.shr (col1, 8), 0xFF) * 1.001
g2 = bit.band (bit.shr (col2, 8), 0xFF) * 1.001
b1 = bit.band (bit.shr (col1, 16), 0xFF) * 1.002
b2 = bit.band (bit.shr (col2, 16), 0xFF) * 1.002
return r1 + g1 + b1 < r2 + g2 + b2
end -- function
)
which = 0
print ""
function showcolour (name)
colour = colour_names [name]
r = bit.band (colour, 0xFF)
g = bit.band (bit.shr (colour, 8), 0xFF)
b = bit.band (bit.shr (colour, 16), 0xFF)
textcolour = "white"
if r + g + b > (128 * 3) then
textcolour = "black"
end -- if
ColourTell (textcolour, RGBColourToName (colour),
string.format (" %-20s: %02X%02X%02X ", name, r, g, b ))
Tell " "
which = which + 1
end -- showcolour
for i = 1, #t / 3 do
showcolour (t [i])
showcolour (t [i + #t / 3 ])
showcolour (t [i + (#t / 3) * 2])
print ""
end -- for
print ""
And now the "official" colour names used by the client, sorted into alphabetical order:

Lua code to generate the above:
print ""
t = {}
for k, v in pairs (colour_names) do
table.insert (t, k)
end -- for
table.sort (t, function (a, b) return a < b end)
function showcolour (name)
colour = colour_names [name]
r = bit.band (colour, 0xFF)
g = bit.band (bit.shr (colour, 8), 0xFF)
b = bit.band (bit.shr (colour, 16), 0xFF)
textcolour = "white"
if r + g + b > (128 * 3) then
textcolour = "black"
end -- if
ColourTell (textcolour, RGBColourToName (colour),
string.format (" %-20s: %02X%02X%02X ", name, r, g, b ))
Tell " "
end -- showcolour
for i = 1, #t / 3 do
showcolour (t [i])
showcolour (t [i + #t / 3 ])
showcolour (t [i + (#t / 3) * 2])
print ""
end -- for
print ""
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|