There will be many occasions when you wish to add colors to the Graphical User Interface you create for your JB programs, such as programs created specifically for a holiday (red and green for Christmas; pink, blue, and yellow for Easter; orange and black for Halloween, etc). See the help file topic, Colors and the Graphical User Interface, for choices you have using colors. You can write code in JB to offer choices to your user, setting colors or "themes" before opening a window and, in some cases, during program execution.
When creating a WINDOW for WINDOW, you can only use the 16 named colors to designate BackgroundColor$ and ForegroundColor$. Usually these will be enough to get your users in the holiday spirit. You can also add GRAPHICBOXes to a WINDOW for WINDOW, and use over 16 million colors by specifying RGB values printed to the GRAPHICBOXes.
Where do you find RGB values? John Davidson created JB Color Pick, which you can download by clicking here, Color Pick. You can also download ColorTest by Caranoch by clicking here, ColorTest. Or you can run MS Paint, click on Colors > Edit Colors > Define Custom Colors and select from millions of possible RGB values. When you upgrade to Liberty Basic, you will also be able to use the COLORDIALOG command to open a colorbox similar to the one available with MS Paint.
Okay, I've been around the block a few times, so I'm pretty well satisfied with the named colors (satisfied=lazy). Some coders, however, would like to create their programs with "psychedelic" colors. That's your choice, keep in mind the user you intend for your program and what their preferences might be.
When you are using BackgroundColor$ and ForegroundColor$, for windows and controls, you must specify those before you open the window. You can set colors for TEXTBOXes, LISTBOXes, COMBOBOXes and TEXTEDITORs, as in the code below.
'Using COLORS in your GUI by Welopez
FOR i=1 TO 10
READ temp$ 'Read DATA strings for RGB values
colr$(i)=temp$ 'Put RGB values into colr$() array
NEXT i
NOMAINWIN
WindowWidth=400
WindowHeight=400
UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
UpperLeftY=INT((DisplayHeight-WindowHeight)/2)
BackgroundColor$="darkpink" 'Sets color of the Window FOR Window
ForegroundColor$="yellow" 'Sets color of the text in Window
TextboxColor$="darkcyan" 'Backcolor$ for tbx1
TEXTBOX #main.tbx1, 10, 80, 375, 30
TextboxColor$="red" 'Backcolor$ for tbx2
TEXTBOX #main.tbx2, 10, 120, 375, 30
TextboxColor$="pink" 'Backcolor$ for tbx3
TEXTBOX #main.tbx3, 10, 160, 375, 30
STATICTEXT #main, "Some Examples Using Colors With"+CHR$(13)+ _
"Just Basic", 10, 20, 380, 45
GRAPHICBOX #main.gb1, 50, 215, 80, 80
GRAPHICBOX #main.gb2, 150, 215, 80, 80
GRAPHICBOX #main.gb3, 250, 215, 80, 80
BUTTON #main.btn1, "Switch", [switch], UL, 50, 320, 80, 30
BUTTON #main.btn1, "Close", [quit], UL, 250, 320, 80, 30
OPEN "Using Colors" FOR WINDOW AS #main
PRINT #main, "trapclose [quit]"
PRINT #main, "font arial 12 bold" 'Sets font for WINDOW and controls
PRINT #main.tbx1, "This is a text box."
PRINT #main.tbx2, "And so is this!"
PRINT #main.tbx3, "Don't forget me! I am too!"
PRINT #main.gb1, "down"
PRINT #main.gb1, colr$(1) 'Start with first three values from colr$() array
PRINT #main.gb2, colr$(2)
PRINT #main.gb3, colr$(3)
WAIT
[switch] 'Get random RBG values from colr$() array
newColor=INT(RND(0)*10)+1
PRINT #main.gb1, colr$(newColor)
newColor=INT(RND(0)*10)+1
PRINT #main.gb2, colr$(newColor)
newColor=INT(RND(0)*10)+1
PRINT #main.gb3, colr$(newColor)
WAIT
[quit]
CLOSE #main
END
'Fill colors for graphic boxes using RGB values
DATA "fill 255 0 0", "fill 0 255 0"
DATA "fill 0 0 255", "fill 128 255 255"
DATA "fill 0 0 0", "fill 255 88 0"
DATA "fill 128 64 64", "fill 255 128 255"
DATA "fill 192 192 192", "fill 128 0 255"In the code above, I created a WINDOW for WINDOW with one STATICTEXT, three TEXTBOXes, and three GRAPHICBOXes. Colors for the WINDOW and text were assigned with the BackgroundColor$ and ForegroundColor$ before opening the window. You should at least have colors with contrast which allows for easy reading.
RGB values for 10 colors were loaded from DATA statements into colr$() array. Later in the program, the "Switch" button will branch to a block of code to get newColor values from the array and print them to the GRAPHICBOXes everytime the button is pressed. You can click and click and click the "Switch" button. Since there are 10 possible colors, and three GRAPHICBOXes, the odds are only 1 in 1000 that you'll fill all the boxes with the same color.
Colors for your Gooey are usually sent as string values to the control. This is a requirement when using BackgroundColor$ or ForegroundColor$. When using graphic controls, you can specify many additional colors for the PEN, LINE, TEXT, and FILL, using variables generated for RGB by the program. To see the DEMO by Janet Terra click here, for many examples of displaying colors, including my favorite - - Gradient Fill.
Here's a short DEMO to print "Happy Birthday!" to a GRAPHICBOX using random colors for each letter. Because we use (x+15) for the "right" coordinate of the place to print, it is necessary to use a mono-spaced font for best appearance of the printed text.
'VariColored Text Strings
GOSUB [fill]
NOMAINWIN
WindowWidth=300
WindowHeight=150
UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
UpperLeftY=INT((DisplayHeight-WindowHeight)/2)
BackgroundColor$="pink"
GRAPHICBOX #main.gbx, 20, 10, 260, 50
BUTTON #main.btn, "CLOSE", [quit], UL, 120, 75, 60, 30
OPEN "VariColored Text" FOR WINDOW AS #main
PRINT #main, "trapclose [quit]"
PRINT #main.gbx, "down"
msg$="Happy Birthday!"
PRINT #main.gbx, "font arial_new 16 bold"
WHILE 1=1
x=0 'Start point of printing
PRINT #main.gbx, "FILL 255 255 200"
PRINT #main.gbx, "backcolor 255 255 200"
FOR i=1 TO 15
GOSUB [getRGB]
PRINT #main.gbx, "color "; colr$(newColor)
x=x+15
PRINT #main.gbx, "place "; x; " 30"
PRINT #main.gbx, "\"; MID$(msg$,i,1)
TIMER 200, [cont]
WAIT
[cont]
TIMER 0
NEXT i
WEND
WAIT
[quit]
CLOSE #main
END
[getRGB]
'Choose random color for next letter to print
newColor=INT(RND(0)*10)+1
RETURN
[fill]
FOR i=1 TO 10
READ temp$ 'Read DATA strings for RGB values
colr$(i)=temp$ 'Put RGB values into colr$() array
NEXT i
RETURN
'Fill colors for graphic boxes using RGB values
DATA "255 0 0", "0 255 0"
DATA "0 0 255", "128 255 255"
DATA "0 0 0", "255 88 0"
DATA "128 64 64", "255 128 255"
DATA "192 192 192", "128 0 255"The array for colors was filled in the same manner as the previous program, using a GOSUB before opening the WINDOW. Another GOSUB for printing msg$ will choose a random color for each character. MID$(msg$,i,1) is used to get the next character for printing.
Colors for GRAPHICBOXes and WINDOW for GRAPHICS can be repeatedly changed throughout the program, according to the code you write. Colors for other controls must usually be set before the window is opened and will not be changed during program execution. (Okay, there are always exceptions. I like exceptions and will enjoy seeing methods used by other coders.)
I hope you have fun with these, and don't worry about how much paint Pablo and his crew are using. You can always download more colors! ROFL!