[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
QbasicFAQ_ChangeColors
How do I change colors?
Back to QBasic FAQ Main Page.
To use one of your new-found colors is very simple. Simply choose a color ATTRIBUTE to replace with your new color VALUE.
Like this... PALETTE Color_To_Replace%, RGB_Value!
Where, Color_To_Replace% is the Attribute and, RGB_Value! is the Value.
Example, (Replace color attribute 5, magenta, with a value of 1572894, a color that looks like a red-violet on my monitor...
PALETTE 5, 1571894
There is another faster but yet more complicated way to change the RGB values right in the VGA itself. Here is how its done:
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
QbasicFAQ_ChangeColors
How do I change colors?
Back to QBasic FAQ Main Page.
To use one of your new-found colors is very simple. Simply choose a color ATTRIBUTE to replace with your new color VALUE.
Like this... PALETTE Color_To_Replace%, RGB_Value!
Where, Color_To_Replace% is the Attribute and, RGB_Value! is the Value.
Example, (Replace color attribute 5, magenta, with a value of 1572894, a color that looks like a red-violet on my monitor...
PALETTE 5, 1571894
There is another faster but yet more complicated way to change the RGB values right in the VGA itself. Here is how its done:
' ' UnderWARE's FADER SUB... A complete fader routine for saving the ' current palette, fading out, in, and resetting the palette. ' ALL IN ONE SUB-ROUTINE! ' --------------------------------------------------------------------- ' NOTE: You must have a VGA card to use FADER. ' --------------------------------------------------------------------- ' How it works... (If you don't want to know just yet... skip down below) ' ' Every machine equipped with a VGA card, stores it's current palette ' values so that they may be relaced and retrieved easily. Many of you ' may have noticed when using Windows(tm), that the screen colors ' sometimes "swap out" when loading certain programs. That's because ' these particular programs have changed the current VGA palette in some ' manner. ' To access the VGA, you must know it's INPut address in hexidecimal, ' and the bit(s) to change. The OUTput address (in this case), is the ' same as the INPut. ' The VGA, (Video Graphics Adapter), stores it's information at two ' consectutive adresses, one for the color attribute, and one for the ' RGB, (Red, Green, Blue), components. The VGA will allow you "adjust" ' each component individually through the range of 0 to 63. This then ' allows for up to 262,144 different combinations! ' So how do you keep track of them? Well the truth beknowst... ' YOU don't have to! The VGA does it. All your colors were set BEFORE ' you started QBasic weren't they? That's because the VGA has already ' been using it's default RGB colors. ' Now the trick is... to get those colors and save them for later. ' And that's just what this sub does with it's first option... Gets the ' current default palette and saves it in a small array for later, so that ' it can be used to restore the same colors back to the VGA. ' ' The rest is pretty straight forward... Calling the VGA, for each ' color attribute, and decreasing/increasing it for each component, ' (RGB), until all the colors have maxed out. (to full color or to black). ' If you look at the GOSUB's in the SUB routine, you may understand now. ' ' << Skip to here for HOW to USE >> ' ' SYNTAX: ' ' Fade FadeType%, DelayAmt! ' ' WHERE: FadeType% is one of the following four choices... ' ' 0 = Get the current default palette. (See below) ' 1 = Reset the palette back to original. ' 2 = Fade in the screen. (If it's faded out). ' 3 = Fade out the screen. (If it's not already faded). ' ' AND: DelayAmt! is the approximate amount of time in seconds that ' you want the fade to last. (Yes you can use decimals). ' ' How to make these sub's work for you... ' ' Very simple... ' ' FIRST! (You gotta do this first)... ' ' First you call the VGA and store the current palette settings. That ' way you can later restore them. (If you don't, you're not gonna be able ' to reset the palette!) EX: Fade 0, 0 ' A DelayAmt! is not necessary for options 1 and 2. ' ' Then when you want to fade out a screen... Fade 3, 3 ' (Fades out the screen in approx 3 seconds total). ' ' To restore the screen either fade in.... Fade 2, 3 ' OR reset the palette... Fade 1, 0 ' ' SIMPLE ENOUGH? ' ' I'll say it ONE MORE TIME.... first get your default settings BEFORE ' calling for a fade... otherwise you have nothing to set back to! ' ' Well enough said... ' If you still want to know more about colors in QBasic, download my ' Color Finder Utility from my Web Page. You can find it at: ' ' http://members.aol.com/uwlabs/index.html ' ' Send questions or comments to any of the following addresses: ' ' steelcharm@aol.com steelcharm@twave.net uwlabs@aol.com ' ' DECLARE SUB Delay (Amount!) DECLARE SUB Fade (FadeType%, DelayAmt!) Dim ColorAttrib%(255, 3) Screen 13 Cls LOCATE 10, 10 Color 9: Print " Under"; Color 11: Print "WARE "; Color 1: Print "Labs"; Color 7: Print "(c)"; Color 8: Print "1998 " LOCATE 11, 10 Color 4: Print " ____"; Color 12: Print "____"; Color 14: Print "__"; Color 15: Print "_"; Color 14: Print "__"; Color 12: Print "____"; Color 4: Print "____ "; Color 15 LOCATE 13, 10: Print " Palette Fader Routine " Line (10, 0)-(310, 64), 15, BF Line (10, 108)-(310, 240), 15, BF a% = 0 For i% = 16 To 31 a% = a% + 8 Line (a%, 108)-(a% + 8, 240), i%, BF Line (a%, 0)-(a% + 8, 64), i%, BF Next i% a% = 319 For i% = 16 To 31 a% = a% - 8 Line (a%, 108)-(a% + 8, 240), i%, BF Line (a%, 0)-(a% + 8, 64), i%, BF Next i% SLEEP 1 Fade 0, 0 Fade 3, 3 Fade 2, 3 SYSTEM: End
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
