Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

colours 2

Status
Not open for further replies.

qbasicking

Programmer
Aug 19, 2001
628
US
I just want some opinions on this one. I am making a program, that I think would look really cool in 16 shades of gray (screen 12). In your opinions, whats the order of the colours from lightest to darkest?
 
If you use the PALETTE USING statement you won't have to worry about that.

I think I posted a short program in the FAQ section that demonstrates it... something about 3D graphics (a deceptive title since it didn't have anything to do with 3D graphics... sorry!)
VCA.gif
 
I'm not using the PALETTE statement, I don't like using that, I am using the OUT statement
 
One thing I've found in QBasic is to try what I didn't like. For a long time I'd avoid such things at Arrays and Palette because I didn't understand them. After I game them a try and figured out how they work, they are quite a blessing.
The use of the palette feature is extremely easy. It just requires the use of a nice calculator at times.

if you want to change color 1 (blue) to a shade of grey, you would enter in the command:

palette 1, 1973970

And then whenever you used the color 1, you'd get a grey.

The second number comes from this formula

RED + (256 * GREEN) + (65536 * BLUE)

RED, GREEN, and BLUE are the values of that color between 0 and 63. Any higher or lower and you will get an error.

If you make them all the same, you get a shade of grey.

In my example above, 1973970 was the shade of grey with the value of 30.

30 + (256 * 30) + (65536 * 30) = 1973970

That's why a calculator would be nice.

If you want to make a setup that would nicely arrange the colors of grey from darkest to lightest (1 being darkest 16 being lightest)

For i = 1 to 16
palette i, (((4*i)-1) + (256*((4*i)-1)) + (65536*((4*i)-1))
next

Now the color 1 will be a dark grey, and the color 16 will be a very light grey.

the ((4*i)-1) makes it so that when i = 1 ((4*1)-1) = 3
and when i = 16 ((4*16)-1) = 63 (because it can't be equal to 64)

Well, just kinda sift through that, my own math is probably the most complex part, but the basics of the palette function are relatively simple. :)
And it would easily order your shades of grey from lightest to darkest.
You could also change it to alter the range from light to dark.
 
O, no that's not it, I know how to use the PALETTE statement, I used that for a long time, until I figured out how to make the OUT statement change them. It is much quicker and much more precise, so I always get the colour that I want, and instead of 63, i can go up to 127. But anyway. I guess speed doesn't really matter, since the differnece is so small and I am using a P4. Thanks I'll try PALETTE
 
[tt]
.
.
FOR i% = 0 TO 15
intensity% = i% * 63 \ 15
OUT &H3C8, i%
OUT &H3C9, intensity%
OUT &H3C9, intensity%
OUT &H3C9, intensity%
NEXT i%
.
.
[/tt]

Perfect 16 shades of gray from darkest possible to lightest possible.
 
That is originally what I was going to use. Does anybody know which one is faster?
Why do you use 63/15? You can go up to 127 without an error (see my post on one of the other pages)
 
You can go up to 255 without an error, but the VGA palette only uses 6 bits. There is an 8-bit mode on some cards, but it requires extensive reconfiguration. If you use 7 bits, you will end up with 0-7 being black to white, and then 8-15 being black to white a second time.
 
ohh, you can go to 255?, i can't, I get an error at 128
 
No one realy answered: does anybody know which is faster? using OUT or PALETTE?
 
[tt]OUT[/tt] :) [tt]PALETTE[/tt] wraps everything up, forces you to convert to a 32-bit value which is emulated across two 16-bit registers, and then converts back before doing the output, and is VERY slow. [tt]OUT[/tt], on the other hand, simply goes straight to the port output operation.
 
Wow! you were right! I looped each one 1000 times on my old 386: PALETTE took 15 seconds, while OUT only took half of a second.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top