Code Sample |
-- set up four colors -- color table goes up to 255 slots? temp = Color:set_color(17,255,165,0) temp = Color:set_color(224,125,125,256) temp = Color:set_color(258,25,25,125) temp = Color:set_color(1001,25,125,125) -- create a set of entries into the color table -- 101 to 136 as a ramp of blue/red -- 137 to 172 as a ramp of blue/green for i = 1,36 do temp = Color:set_color(100+i,255-7*i,0,7*i) end for i = 1,36 do temp = Color:set_color(136+i,0,255-7*i,7*i) end w = Window{320,200,"Test Window"} w.color = 17 --make a bunch of colored boxes for i = 1,36 do myBox = Box{10*i,150,5,5} myBox.color = 100+i myBox.box = Boxtype.flat end for i = 1,36 do myBox = Box{10*i,160,5,5} myBox.color = 136+i myBox.box = Boxtype.flat end name = Input{76,10,210,25,"Name:"} name.color = 224 myBox = Box{20,40,100,100} myBox.color = Color.white myBox.box = Boxtype.flat myBox = Box{140,40,60,60} myBox.color = 1001 myBox.box = Boxtype.flat w:end_layout() w:show() |
Code Sample |
temp = Color:set_color(17,255,165,0) Color.orange = 17 myBox = Box{140,40,60,60} myBox.color = Color.orange myBox.box = Boxtype.flat |
Code Sample |
#!/bin/flua -- Color codes for Lua FLTK -- mikshaw 2005,2006 -- thanks to clacker and roberts for help -- keep slider colors updated as values change function update_sliders() Color:set_color(100,slideR.value,slideG.value,slideB.value) slideR.selection_color = 100 slideG.selection_color = 100 slideB.selection_color = 100 slideR:redraw();slideG:redraw();slideB:redraw() end -- default widget properties Fl_Widget.initializers = {textfont = 15, labelfont = 15,box=Boxtype.thin_up} Fl_Slider.initializers = {type=Slidertype.hor,align=Align.left,step=1,minimum=0,maximum=255,selection_color=0,callback=update_sliders} Fl_Box.initializers = {align=Align.right} -- MAIN WINDOW ww = 480 wh = 365 w = Window{ww,wh,"Lua FLTK Colors"} -- make a pretty window border frame = Box{1,1,ww-2,wh-2; box=Boxtype.engraved} -- draw a column of numbered colors, 0-15 colors = {} for i = 0,15 do colors[i] = Box{30,15+i*20,80,20,tostring(i);color=i} end -- draw a column of named colors cblack = Box{140,15,80,20,"black";color=Color.black} cred = Box{140,35,80,20,"red";color=Color.red} cgreen = Box{140,55,80,20,"green";color=Color.green} cyellow = Box{140,75,80,20,"yellow";color=Color.yellow} cblue = Box{140,95,80,20,"blue";color=Color.blue} cmagenta = Box{140,115,80,20,"magenta";color=Color.magenta} ccyan = Box{140,135,80,20,"cyan";color=Color.cyan} cwhite = Box{140,155,80,20,"white";color=Color.white} cselection = Box{140,315,80,20,"selection";color=Color.selection} cgray = Box{140,335,80,20,"gray (default)";color=Color.gray} -- add a new color to the color table (orange) colors[16] = Color:set_color(16,255,165,0) new_color = Box{300,35,160,160,"New color (16): ";color=16,align=Align.top} -- dropdown list of numbered colors retrieve_color = Choice{300,215,160,20;when=When.release + When.not_changed} for i = 0,16 do retrieve_color:add(Menu_Entry{"Get Color "..i}) end retrieve_color.value = 0 function retrieve_color.callback() slideR.value,slideG.value,slideB.value = Color:get_color(retrieve_color.value) update_sliders() end -- color sliders, value 0-255 (see Fl_Slider.initializers for properties) slideR = Value_Slider{300,235,160,20,"R"} slideG = Value_Slider{300,255,160,20,"G"} slideB = Value_Slider{300,275,160,20,"B"} -- changes the color of new color 16 and redraws it change_color = Button{300,295,160,20,"Apply to color 16"} function change_color.callback() Color:set_color(16,slideR.value,slideG.value,slideB.value) new_color:redraw() end w:end_layout() w:show() |