Programming and Scripting :: Colors in Flua?



I don't understand the way colors are used in flua.  I can set one of 16 colors with a number, and most of those can also be set with Color.<colorname>.  But flua has support for many more colors than those 16, and i'm finding it difficult to use them with what i'm getting from the documentation.  Even the input.lua script provided in the flua package uses a color picker, but i'm having trouble understanding what it's doing.

Does anyone here have experience with using colors in flua, or can understand the docs well enough to explain the syntax to me?

Thanks for your time.

Not sure of your question.
I am using the color chooser in my wallpaper.lua to select solid color backgrounds for dsl v2.2. The color choose is pretty easy to use, give it a starting color in decimal for R G B and it will return a new decimal value choosen. Then I convert to hex for xsri. For example the jwm default background that I chose was #336699 so I load up color_chooser with rgb set to 51,102,153 and then let the use choose from there what they would want. The result is a success flag and the three rgb values.

But maybe your question is on get_color and set_color? Those appear to be setting or extracting the rgb values for a color by name or number. Which you could then use by such name or number for the duration of your program.

Yes, it is mostly get_color/set_color that i was messing with...it seems to be the only way to set specific rgb color instead of choosing one of the defaults from the 16-color palette (or using the color picker...i'm looking for a non-interactive way of setting arbitrary colors).  It appears that "color=Color.get_color(n,n,n)" works, but the integers needed do not seem to follow the pattern you'd find in rgb.txt: 0-255 for red, green, and blue respectively.  Also tried Color.gray_ramp(n), but can't get that to work either.

Specifically, this is the sort of thing I'm trying to accomplish.  Say I want my button label text to be equivalent to "orange1", so I try this:
label_color=Color.get_color(255,165,0)
..but it makes something like aquamarine instead.

Maybe i need to first define a color name using rgb values, and then set a color property by that name?

Found one way to do it, after a lot of trial and error...

Instead of setting RGB within the widget properties, I use a number like usual, such as 5, which is magenta by default.  However, at the top of the file i set the color 5 to 255,165,0 to make it orange instead of magenta:
Code Sample
Color:set_color(5,255,165,0)

This also changes Color.magenta, so i assume the color names refer to the color numbers.

mikshaw, I use other numbers than the named ones and it still works.  I don't know how many entries I can make into the color table, but it looks like color numbers below 1001 work but funny things happen after 1024.  Here is my example (using your orange):
Code Sample
-- set up four colors
-- color table goes up to "small number" according to docs

temp = Color:set_color(17,255,165,0)
temp = Color:set_color(124,125,125,256)
temp = Color:set_color(254,25,25,125)
temp = Color:set_color(1001,25,125,125)

w = Window{320,200,"Test Window"}
w.color = 17

name = Input{76,10,210,25,"Name:"}
name.color = 124

myBox = Box{20,40,100,100}
myBox.color = 254
myBox.box = Boxtype.flat

myBox = Box{140,40,60,60}
myBox.color = 1001
myBox.box = Boxtype.flat

w:end_layout()
w:show()

Next Page...
original here.