RGB SLIDERS
Posted: Fri Oct 18, 2024 9:36 pm
This simple program lets you adjust R, G, & B sliders to match a colour, and shows the RGB values to use in a program. It also prints the values on the screen in a format that you can Copy/Paste to the FILL COLOR statement of a Smart BASIC program. Because Copy/Paste does not work on the output of a program using sliders or buttons, a second program (RGB SLIDERS Part 2.sb) is required to use this function. The main program runs this 2nd program automatically. The values are copied to the 2nd program via the clipboard. (It could also be done by printing to a file).
If you don’t need the print or Copy/Paste functions, those parts can be omitted. (The values are shown next to the sliders anyway).
This program is probably easier than re-running your program over & over to get the colour you want. It is excellent for matching the colour in a picture.
This started out as a small program on my iPod, with none of the printing features. Very neat for quick reference. When I decided to post it here, I thought I should make it a bit more useful, so I added the printing of the values in the Copy/Paste format.
It's also a simple demonstration of Slider & Button programming.
No doubt improvements could be made, e.g. the clipboard output could be edited to remove extra spaces; compatibility with various devices & orientation can be programmed.
This is the main program. It requires the Part 2 program below.
This is the 2nd program, required for the Copy/Paste function
RGB SLIDERS Part 2.sb
If you don’t need the print or Copy/Paste functions, those parts can be omitted. (The values are shown next to the sliders anyway).
This program is probably easier than re-running your program over & over to get the colour you want. It is excellent for matching the colour in a picture.
This started out as a small program on my iPod, with none of the printing features. Very neat for quick reference. When I decided to post it here, I thought I should make it a bit more useful, so I added the printing of the values in the Copy/Paste format.
It's also a simple demonstration of Slider & Button programming.
No doubt improvements could be made, e.g. the clipboard output could be edited to remove extra spaces; compatibility with various devices & orientation can be programmed.
This is the main program. It requires the Part 2 program below.
Code: Select all
/* Colour Sliders - adjust sliders for desired colour. RGB values are shown on screen.
This version is for iPad. Screen positions & sizes must be modified for iPhone.
Besides being an example of the use of sliders & buttons, will show and print the
RGB values for the colour set by the sliders, both in decimal form (0-1) and
as binary (0-256) values.
Prints the 0-1 values which you can then Copy/Paste into the FILL COLOR statement of
a Smart BASIC program. Requires program "RGB SLIDERS Part 2.sb" for Copy/Paste ability.
Or just use it to experiment with making colours from mixtures of R, G, B.
Excellent for matching a colour in a picture.
Don't forget - colours may be affected by Screen Brightness.
*/
'm'
GRAPHICS
f=1 ' background colour fill
GRAPHICS CLEAR f,f,f
DRAW FONT SIZE 40
DRAW COLOR 0,0,0
DEF fn(z)= INTEG(100*z+.5)/100 'round to 2 decimal places
'c'
SLIDER "red" VALUE 0 AT 100,400 SIZE 400 'red 'Create sliders & button,
DRAW TEXT "RED" AT 100, 370 'and set all sliders to 0.
SLIDER "grn" VALUE 0 AT 100,500 SIZE 400 ' green
DRAW TEXT "GREEN" AT 100, 470
SLIDER "blue" VALUE 0 AT 100,600 SIZE 400 ' blue
DRAW TEXT "BLUE" AT 100, 570
SET BUTTONS FONT SIZE 25
BUTTON "p" TEXT "Print" AT 300,650 SIZE 170, 50
'g' ===========================================
LOOP:
IF SLIDER_CHANGED("red")=1 THEN r=SLIDER_VALUE("red") 'read sliders
IF SLIDER_CHANGED("grn")=1 THEN g=SLIDER_VALUE("grn")
IF SLIDER_CHANGED("blue")=1 THEN b=SLIDER_VALUE("blue")
'r'
REFRESH ON
FILL COLOR r,g,b ' show resulting colour on box
FILL RECT 100,100 TO 900, 200 ' size of colour box
FILL COLOR f,f,f
FILL RECT 750,500 SIZE 190 ' erase old printed values with background colour
DRAW TEXT fn(r) AT 600, 400 ! DRAW TEXT INTEG(r*256) AT 800,400 'print colour values
DRAW TEXT fn(g) AT 600, 500 ! DRAW TEXT INTEG(g*256) AT 800,500
DRAW TEXT fn(b) AT 600, 600 ! DRAW TEXT INTEG(b*256) AT 800,600
REFRESH OFF ' prevent numbers from flickering
'b' ======== Printout Section =================
IF BUTTON_PRESSED("p") THEN 'tidy up the screen for printout
SLIDER "red" HIDE ! SLIDER "grn" HIDE ! SLIDER "blue" HIDE ! BUTTON "p" HIDE
TEXT ! TEXT CLEAR
PRINT ! PRINT fn(r);", "; fn(g); ", "; fn(b); " [0-1] Format (required by Smart BASIC)"
PRINT ! PRINT INTEG(r*256);", "; INTEG(g*256); ", "; INTEG(b*256); " [0-256] Format (just in case you need it)"
PRINT ! PRINT "Press 'x' (+Return) to Exit and Run 'SLIDERS Part 2.sb' to enable Copy/Paste"
PRINT " Just press RETURN to continue adjusting colours."
INPUT zz$ 'dummy input
zz$=LOWSTR$(zz$) 'ensure lower case
'c' ============= Exit and run program "SLIDERS Part 2.sb" ====================
' ============= to allow COPY/PASTE to other programs. =============
IF zz$="x" THEN
TEXT
CLIPBOARD CLEAR
CLIPBOARD WRITE fn(r),fn(g),fn(b),INTEG(r*256),INTEG(g*256),INTEG(b*256)
RUN "RGB SLIDERS Part 2.sb" 'The filename is CASE SENSITIVE.****
END 'Exit & Run 'RGB SLIDERS Part 2.sb' program for Copy/Paste
ENDIF
'’ otherwise go back to adjusting sliders:
GRAPHICS
SLIDER "red" SHOW ! SLIDER "grn" SHOW ! SLIDER "blue" SHOW ! BUTTON "p" SHOW
ENDIF
GOTO LOOP
RGB SLIDERS Part 2.sb
Code: Select all
/*
Read Clipboard
[See Help, Input & Output section]
RGB SLIDERS.sb program writes to clipboard & runs this program.
Output can be Copy/Pasted
*/
IF CLIPBOARD_COUNT()=0 THEN 'Verify that Clipboard contains data.
PRINT ! PRINT "Clipboard is empty. Run ""RGB SLIDERS.sb"" again."
END
ENDIF
CLIPBOARD READ r,g,b, r1,g1,b1
PRINT ! PRINT r; ", ";g; ", ";b; " Decimal [0-1 Format] Required by Smart BASIC."
PRINT ! PRINT r1;g1;b1; " Binary [0-256 Format] Just in case you need it."
PRINT ! PRINT " You can now Copy/Paste the above values."
END