'=========================================================================== ' Subject: 256 COLORS IN SCREEN 12 Date: 06-14-92 (14:32) ' Author: Duane Jahnke Code: QB, QBasic, PDS ' Keys: 256,COLORS,SCREEN,12 Packet: EGAVGA.ABC '=========================================================================== 'NOTE: VGA required to run this program. 'This program demonstrates how to calculate and display the 256k colors 'available in SCREEN 12. The formula used below looks kind of cryptic 'at first, but it will begin to make sense after you think about 'how colors work. 'There are 3 basic colors: red, green, and blue. 'In SCREEN 12, each of these colors has an intensity range of 0 to 63 'That gives a total of 64 shades for each one. 'Therefore, 64 * 64 * 64 = 262144 (256k) possible colors. 'Sounds good, well the down side is that BASIC can only display '16 of them at one time, oh-well. 'Red's palette begins at 0 'Green's palette begins at 256 'Blue's palette begins at 65536 'Therefore, the palette formula is: ' PalColor& = (65536 * blue%) + (256 * green%) + red% 'Enough of that, run this and see what you think. '-------------------------------------------------------------------------- ON ERROR GOTO ETrap 'set an error trap SCREEN 12 'set the screen mode PALETTE 1, 0 'assign black to color attribute #1 to use as the default w% = 100: x% = 50 'set the viewport boundry coordinate var's y% = 540: z% = 300 VIEW SCREEN (w%, x%)-(y%, z%), 0, 15 'define a viewport w/ border LINE (w%, x%)-(y%, z%), 1, BF 'draw a box, fill w/ color 1 COLOR 15 'put options on the screen LOCATE 3, 14: PRINT "PALETTE VALUE:" LOCATE 21, 14: PRINT "R = More red Red intensity:" LOCATE 22, 14: PRINT "r = Less red" LOCATE 24, 14: PRINT "G = More green Green intensity:" LOCATE 25, 14: PRINT "g = Less green" LOCATE 27, 14: PRINT "B = More blue Blue intensity:" LOCATE 28, 14: PRINT "b = Less blue" LOCATE 30, 35: PRINT "Esc = Quit"; DO 'loop here and update the palette and data w/ each key hit a& = (65536 * blue%) + (256 * green%) + red% 'calc the new palette PALETTE 1, a& 'display the new palette LOCATE 3, 28: PRINT a&; " " 'update the screen data LOCATE 21, 65: PRINT red% LOCATE 24, 65: PRINT green% LOCATE 27, 65: PRINT blue% DO: k$ = INKEY$ 'wait for a user key LOOP WHILE k$ = "" SELECT CASE k$ 'process the key CASE "R" IF red% < 63 THEN 'increment red intensity red% = red% + 1 ELSE SOUND 200, .1 END IF CASE "r" IF red% > 0 THEN 'decrement red intensity red% = red% - 1 ELSE SOUND 200, .1 END IF CASE "G" IF green% < 63 THEN 'increment green intensity green% = green% + 1 ELSE SOUND 200, .1 END IF CASE "g" IF green% > 0 THEN 'decrement green intensity green% = green% - 1 ELSE SOUND 200, .1 END IF CASE "B" IF blue% < 63 THEN 'increment blue intensity blue% = blue% + 1 ELSE SOUND 200, .1 END IF CASE "b" IF blue% > 0 THEN 'decrement blue intensity blue% = blue% - 1 ELSE SOUND 200, .1 END IF CASE CHR$(27) CASE ELSE SOUND 200, .1 END SELECT LOOP UNTIL k$ = CHR$(27) 'exit if escape is hit VIEW 'close the viewport CLS PALETTE 'reset the palette to default SCREEN 0 'print the final palette data PRINT "FINAL PALETTE VALUE :"; a& PRINT "RED INTENSITY :"; red% PRINT "GREEN INTENSITY :"; green% PRINT "BLUE INTENSITY :"; blue% Done: END ETrap: CLS 'display the error code and exit program PRINT "BASIC RUNTIME ERROR #"; ERR RESUME Done