256 colours

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Andrew Dance
Coder
Posts: 18
Joined: Mon Dec 17, 2007 8:41 pm
Contact:

256 colours

Post by Andrew Dance »

i'm sure it's a simple question, but where can i find or learn the 256 colour palate with the colour codes? I know of the 0-15 from http://www.petesqbsite.com/sections/tut ... raphix.txt but i would prefer a larger variety to use.
Edit: and yes, im using screen 13 to use the 256 colours :P

-Andrew
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

There is a standard VGA palette but it isn't exactly "named" in any way. Furthermore, you can customize it to your liking with little effort as long as you understand the "6 bit rule"...that is, 6 bits for each color index, or 0-63. Each color in the VGA palette is made up of 6 bits of R, G, and B. You can then set the color using this formula:

color = 65536 * BLUE + 256 * GREEN + RED

Take that color and feed it to the PALETTE keyword. Be sure to look it up in the QB help system.

You can also use INP and OUT to do palette stuff, but that is a relatively advanced topic.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

The color palette actually has 64 ^ 3 color shades for some QB screens.

What do you want to do? In SCREEN 12 you can only make 16 colors and 13 can make 256. Any color attribute can be changed using the PALETTE or OUT statements in QB. I prefer OUT because of the math involved using PALETTE:

Code: Select all

OUT &H3C8, 0    'sets the attribute number for black
OUT &H3C9, 0    'red value 0 to 63
OUT &H3C9, 0    'green value 0 to 63
OUT &H3C9, 20  'blue value 0 to 63
The above code changes black to dark blue. Neither 12 or 13 support background colors normally. Play with the values to see how it works!
PALETTE alone will restore all colors to default.

To see all of the screen 13 colors use a print loop.

Code: Select all

FOR c = 1 TO 255 
     COLOR c: PRINT c;
NEXT
You will find that many colors are drab or blackish. But you can change any of them.

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

Or if you want to see them visually...

Code: Select all

DIM palLoop AS INTEGER
SCREEN 13
FOR palLoop = 0 TO 255
LINE (palLoop,0)-(palLoop,64), palLoop
NEXT palLoop
DO: LOOP WHILE INKEY$ = ""
END
User avatar
Kiyotewolf
Veteran
Posts: 96
Joined: Tue Apr 01, 2008 11:38 pm

Creating colors

Post by Kiyotewolf »

In SCREEN 13, the standard group of colors you get is what the default is when you initalize a &HA000 screen in mode &H19 of the BIOS.. aka QBasic mode 13.

The nice thing is there is a range of gray scale colors in there, a complete rainbow almost, a darker copy of the rainbow, and some other variations in there.

What I did was use a palette editor that let me save the colors I wanted, and I even went so far as to name the colors I created.

The colors I made were created from looking through the close up pixel snapshots in Nintendo Powers, and other game magazines, so I named them after things like "Princess Peach skin color", "Zelda Purple", "Mario 2 Green", etc..

I took the long integer value that was created from the 0-63 numbers and wrote it down with the nickname beside it.

If you want to save a palette color as a single number, you have to use the precision it calls for.

ColorValue& = clng(blue)*65536& + clng(green)*256& + clng(red)

After you create this number, you can use the palette command to change your colors.

Palette 16, ColorValue&

Why did I put a & after the number? Cause it designated it as a long-int value so it would not try to attempt to calculate the values as regular integer values and have an overflow error.

clng () is "convert to long-int"

REDIM Colors&(255) as Long

Colors&(0)=0
Colors&(16)=ColorValue&

etc etc..

Now that I can access Super VGA and full 8 bit depth of color, I still convert downwards to the 6-bit only level of variation by dividing and subtracting to get back to 6 - bit color again. That way if I swap from SuperVGA to MCGA(screen 13) in the middle of my code, the colors are the correct precision in counting bits.
Banana phone! We need more lemon pledge. * exploding fist of iced tea! * I see your psycho cat and counter with a duck that has a broken leg, in a cast.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

APRIL FOOL

Post by burger2227 »

That's what we need here! A braggart!

Great how you picked April Fools day to join!
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
Kiyotewolf
Veteran
Posts: 96
Joined: Tue Apr 01, 2008 11:38 pm

Question, Answered completely with bonus code to boot.

Post by Kiyotewolf »

I put no mention of self inflation in that article and if you have a dictionary and a thesarus by you, you surely can check every word and every other definition of every word and find I did not elevate myself on a golden pedestal at all in that forum article reply.

^.^' ;;

Have a nice day.

<3---------<<<<


Kiyote!

And... to make this post have some meaning in the way of being QBasic oriented..

P.S.S.



To find out what colors they are exactly, you are going to have to make a program to print them out, and along side them show the RGB values of the colors as well.

The palette you are wanting exists every time you create a fresh SCREEN 13 screen, and only exists until you change them using PALETTE commands.

This palette will stay in effect even if you don't change the colors at all using any commands, PALETTE, OUT, INP, BLOAD.. ETC..

but..

there is of course a catch..

I code in QBasic, I go to full screen, or a program grabs Windows focus and pulls the program down minimized or to a window, you get back to your program and the colors are ALL changed up. They are not what they used to be, any colors you drew with are going to look all wrong, etc..

What I advise, if you plan on using this color palette without changing anything, is to back up the palette using the INP and OUT commands to an array, BSAVE the array, and be able to recall it if Windows goes *boink* on you and your colors get goofed up, that way either your program can refresh on it's own using the colors to reset it's own palette, or taking a page from browsers, you can include a button to refresh the screen colors if Windows takes your program for a wild ride.

I don't find this happening too often, because ..

1. I have disabled all my screen savers.
2. I don't usually run background programs while QBasic is running cause QBasic is a resource hog anyway and doesn't let much run simultaneously anyway.
3. I change screen modes often in my programs, so things come back to normal on their own very shortly anyway. I usually switch from EGA to VGA and back and forth, and sometimes get into SVGA and back. Depends on which editor I'm using.

You should be able to find tutorials on getting the RGB values from the palette registers. It is a hardware table located in the DAC RAM of your video card, and is defaulted to the color palette you are wanting so badly. Backing up these registers is a matter of accessing the port directly and controlling the DAC register to query it's data bank where the RGB colors are stored.

If you really really want,.. i'll post the code but I'd have to go digging and would take me longer.. plus paperclip guy would call me an even bigger braggard for some odd reason,.. <<'

Once you get used to using the existing colors, you will find you don't have a color you might want, and you will have to decide which colors go and which colors stay.

I have created a palette of my own, made of colors I have derived on my own using a palette editor from "QBasic Games & More" by Fred S. Jr. You can Amazon dot com the book and buy it, cause it would help you enourmously. It helped me for a long time.

The trick to picking colors you need vs colors you want vs colors that are necessary, is to point out what you are doing.

How detailed is your graphics going to be? Is it going to resemble NES, with it's bold color changes, or more like GBA with subtle color variations, or more like a photo? If you want one vs the other vs the other, you are going to have to create a static batch of colors that are specific to your sprites, as well as a tiny gradient that ranges both color and intensity, and compare your final output to the number of colors left after you have developed all those colors already.

It took me a few months to get my colors picked out and finalized, and I have since grown attached to my color palette, like a painter to his paint I suppose, and..

My colors came from the base colors you are after. I inserted my colors into one of the rainbow areas, and added three gradients of my own, SKIN TONE, GOLD SHINY, BLUE WATER, BROWN WOOD, ok.. that was four, but you get the idea, and kept 99% of the remaining colors that existed in the standard palette you are handed when you open a SCREEN 13 page.

Ok.. hands tired.. paperclip boy ready to bomb me with more water balloons I'm sure..

I can type alot.. so beware I guess...

Kudos..

** goes and downloads a copy of QBasic cause I'm not on standard computer.. free terminal.. gotta love college computers.. **

1 -> 15 : Standard Windows Colors
16 -> 31 : Gray from Black to White in gradient
32 -> 47 : Bright Blue to Bright Green Rainbow Gradient
48 -> 63 : Bright Green to Bright Pink Rainbow Gradient
64 -> 79 : Bright Pastel Pink to Bright Pastel Blue Gradient
80 -> 95 : Bright Pastel Violet to Bright Pastel Green Gradient
96 ->111: 1st Half [Bright Green Pastel to Bright Blue Pastel] 2nd Half [ Dark Blue to Dark Red Gradient ]
112->127: Dark Orange to Dark Blue Rainbow Gradient
128->143: Dark Green Pastel to Dark Blue Pastel to Dark Pink Pastel Rainbow Gradient
144->159: Dark Pastel Pink to Dark Pastel Blue Rainbow Gradient
160->175: Repeat pattern from 2nd Half of (96->111) to color num 159, only now even darker, and starting at the left instead of the middle, from number 160 to color number 247, with 248 through 255 black only.
176->191: ... repeat pattern
192->207: ... repeat pattern
208->223: ... repeat pattern
224->239: ... repeat pattern
240->255: ... [end of pattern][Last 8 colors are BLACK -- NO COLOR -- UNDEFINED -- RIPE FOR PUTTING YOUR OWN COLORS INTO USING PALETTE.]



REM --------------------- WORKING CODE TO MAKE COLOR FINDOUT THINGY -------

REM CODED BY KIYOTEWOLF APR_08
WHILE INKEY$ <> "": WEND
WHILE INKEY$ = "": WEND
WHILE INKEY$ <> "": WEND
PRINT "AT EACH DISPLAY, HIT ALT-PRTSCRN & COPY TO PAINT THEN PRINT OUT"
PRINT "YOU WILL HAVE A COMPLETE MAP CODED IN HEX AS TO THE COLORS YOU "
PRINT "WANT. MAKE SURE WHEN PRINTING THE COLOR MAP YOU FIRST DO A "
PRINT "FLOOD FILL TO MAKE THE BACKGROUND WHITE SO YOU DON'T WASTE AN"
PRINT "ENTIRE INK CARTRIDGE DRAWING THE BLACK BACKGROUND WITH YOUR"
PRINT "PRINTER"

WHILE INKEY$ <> "": WEND
WHILE INKEY$ = "": WEND
WHILE INKEY$ <> "": WEND


SCREEN 0
WIDTH 80, 25
COLOR 7, 0
CLS

PRINT "HEX LOOKUP TABLE"
FOR Y = 0 TO 15
FOR X = 0 TO 15
PRINT RIGHT$("00" + HEX$(X + Y * 16), 2); " ";
NEXT X
PRINT
NEXT Y

WHILE INKEY$ <> "": WEND
WHILE INKEY$ = "": WEND
WHILE INKEY$ <> "": WEND

CLS

PRINT "DECIMAL LOOKUP TABLE"
FOR Y = 0 TO 15
FOR X = 0 TO 15
PRINT RIGHT$("000" + LTRIM$(STR$((X + Y * 16))), 3); " ";
NEXT X
PRINT
NEXT Y

WHILE INKEY$ <> "": WEND
WHILE INKEY$ = "": WEND
WHILE INKEY$ <> "": WEND


SCREEN 13
LOCATE 1, 1
PRINT "COLOR TABLE"
FOR X = 0 TO 15
FOR Y = 0 TO 15
LINE (10 + X * 8, 10 + Y * 8)-(10 + X * 8 + 6, 10 + Y * 8 + 6), X + Y * 16, BF
LINE (10 + X * 8, 10 + Y * 8)-(10 + X * 8 + 7, 10 + Y * 8 + 7), 8, B
NEXT Y
NEXT X
LOCATE 1, 1

WHILE INKEY$ <> "": WEND
WHILE INKEY$ = "": WEND
WHILE INKEY$ <> "": WEND

REM --------------------- WORKING CODE TO MAKE COLOR FINDOUT THINGY ------- ENDOF
Last edited by Kiyotewolf on Tue Apr 08, 2008 11:03 am, edited 2 times in total.
Banana phone! We need more lemon pledge. * exploding fist of iced tea! * I see your psycho cat and counter with a duck that has a broken leg, in a cast.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Read the post dates silly! They were from last year kiddo.

THIS THREAD WAS OVER LONG AGO! LOL
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
Kiyotewolf
Veteran
Posts: 96
Joined: Tue Apr 01, 2008 11:38 pm

so what?

Post by Kiyotewolf »

so what?

At least the article is finalized once and for all, and anyone who is a n00b can read it.

plus..

if i'm such the n00b and posting in expired forum questions.. why are you posting in them as well if they are expired?

I found these articles to submit to on Pete's "what's new -- forum posting advertisement" on the right column on his site.

If I shouldn't post on an old article.. which I couldn't care either way,.. then why are you doing the goofy thing and following suit and posting after I do?

Let sleeping dogs lie, and if I don't read a date properly that's my fault..

You did the same thing I did just now by posting after me on the SAME THREAD.

IF 1=0 THEN

:: PRINT "Posting on expired threads is silly."

END IF




.... wait a sec.. that post was from late 2007..

That's so far behind? I still remember Christmas THANK YOU.. You might've moved on already.. Sheesh..

No winning with you is there?




Kiyote!
Banana phone! We need more lemon pledge. * exploding fist of iced tea! * I see your psycho cat and counter with a duck that has a broken leg, in a cast.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

LOL

Post by burger2227 »

I noticed because you answered about 10 old threads on the same day!

Other than that, I saw your ideas about image Arrays and you are DEAD wrong! PUT and GET are more reasonable graphic methods usually.

I will not say that you are a bad programmer, but apparently you are a NOOB here. And your comments seem to brag about your expertise and say little about the questions.

How else are you going to save custom colors if you don't BSAVE that information too? And Yes, that is why arrays come in handy when dealing with 768 different RGB color values. The BUFFER will NEVER tell you that!

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
Kiyotewolf
Veteran
Posts: 96
Joined: Tue Apr 01, 2008 11:38 pm

Posting

Post by Kiyotewolf »

You have it out for me, and from what I've seen have it out for every other person who joins the forum.

I don't CARE what you think of me, and don't care what you say about me.

I don't have time to worry about you, I have much more important things to do.

I am going to hereby post in the forum as much as I can, just to annoy you.

So there.

I will avoid necroposting though.. cause that is just wrong.. ^.^''



Kiyote!

P.S. Consider your posts in reply to me unread, because I am not going to waste my time reading your childish posts anymore.
Banana phone! We need more lemon pledge. * exploding fist of iced tea! * I see your psycho cat and counter with a duck that has a broken leg, in a cast.
Yazar
Coder
Posts: 11
Joined: Sat May 24, 2008 10:51 pm

Post by Yazar »

Code: Select all

DECLARE FUNCTION Get.Red$ (Col%)
DECLARE FUNCTION Get.GRe$ (Col%)
DECLARE FUNCTION Get.Blu$ (Col%)

'Getting absolute 5 bit value of color component

'Declare Function Get.Red$(col%)
'Declare Function Get.Gre$(col%)
'Declare Function Get.Blu$(col%)

SCREEN 13
FOR x = 0 TO 15
   FOR y = 0 TO 15
      LINE (80 + x * 10, 20 + y * 10)-(80 + x * 10 + 10, 20 + y * 10 + 10), x + y * 16, BF
   NEXT
NEXT




INPUT "Color Number"; c%

r$ = Get.Red(c%)
b$ = Get.GRe(c%)
g$ = Get.Blu(c%)

PRINT "The Color "; c%; " is "
PRINT r$; ","; g$; ","; b$
END



FUNCTION Get.Blu$ (Col%)
OUT &HC37, Col%    'it is &hc7, not &h3c8 to get the palette
r% = INP(&H3C9)
r% = INP(&H3C9)
r% = INP(&H3C9)
Get.Blu$ = LTRIM$(RTRIM$(STR$(r%)))
END FUNCTION

FUNCTION Get.GRe$ (Col%)
OUT &H3C7, Col%    'it is &h3C7, not &h3C8 to get the palette
r% = INP(&H3C9)
r% = INP(&H3C9)
Get.GRe$ = LTRIM$(RTRIM$(STR$(r%)))
END FUNCTION

FUNCTION Get.Red$ (Col%)
OUT &HC37, Col%    'it is &hc7, not &h3c8 to get the palette
r% = INP(&H3C9)
Get.Red$ = LTRIM$(RTRIM$(STR$(r%)))
END FUNCTION


Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas

Post by Ralph »

I must say that I have gained from each of the above posts! :D In particular, I love burger2227's very simple code for the 256 colors in SCREEN 13, and kiyotewolf's color-number table, with group descriptions.

I noticed that there are three repeating groups of 72 numbers each, namely:
1st group: 32 to 103
2nd group: 104 to 175 =32+72 to 103+72 (same as 32 to 103, but darker)
3rd group: 176 to 247 =32+144 to 103+144 (same as 32 to 103, but darker yet).

Even though Andrew Dance, the OP, hasn't posted back as yet, I do believe he now has not only a good answer to his question, but much more! When he reads the posts, Andrew will probably Dance for joy!
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish
Post Reply