{{fbdoc item="title" value="PALETTE"}}----
Customizes colors in modes with paletted colors

{{fbdoc item="syntax"}}##
	**Palette** [Get] [//index//, //color//]
	**Palette** [Get] [//index//, //r//, //g//, //b//]
	**Palette** [Get] Using //arrayname(idx)//
##
{{fbdoc item="param"}}
	##Get##
		indicates getting palette information rather than setting palette information
	##//index//##
		palette index
	##//color//##
		color attribute
	##//r//##
		red color component
	##//g//##
		green color component
	##//b//##
		blue color component
	##Using##
		indicates using array of color values
	##//arrayname(idx)//##
		array and index to get/set color attributes

{{fbdoc item="desc"}}
	The ##**Palette**## statement is used to retrieve or customize the current palette for graphics modes with a color depth of up to 8bpp; using ##**Palette**## while in a mode with a higher color depth will have no effect. Calling ##**Palette**## with no argument restores the default palette for current graphics mode, as set by the ##[[KeyPgScreengraphics|Screen (Graphics)]]## statement.
	The [[GfxLib]] sets a [[GfxDefPalettes|default palette]] when a ##[[KeyPgScreengraphics|Screen]]## mode is initialized.
	
	==First form==
		If you specify index and color, these are dependent on the current mode:
		{{table columns="3" cellpadding="1" cells="Screen mode;index range;color range;1;0-3;0-15;2;0-1;0-15;7,8;0-15;0-15;9;0-15;0-63;11;0-1;see below;12;0-15;see below;13 to 21;0-255; see below"}}
		In screen modes ##1##, ##2##, ##7##, ##8## and ##9## you can assign to each color index one of the colors in the available range. In other screen modes, the color must be specified in the form ##&h//BBGGRR//##, where ##//BB//##, ##//GG//## and ##//RR//## are the blue, green and red components ranging ##&h0##-##&h3F## in hexadecimal (##0##-##63## in decimal). If you don't like hexadecimal form, you can use the following formula to compute the integer value to pass to this parameter:
		##color = red [[KeyPgOpOr|or]] (green [[KeyPgOpShiftLeft|shl]] 8) [[KeyPgOpOr|or]] (blue [[KeyPgOpShiftLeft|shl]] 16)##
		Where red, green and blue must range ##0##-##63##. Please note that color values accepted by ##**Palette**## are **not** the in the same form as returned by the ##[[KeyPgRgb|RGB]]## macro (the red and blue fields are inverted, and the range is different); this is for backward compatibility with QB.
		
	==Second form==
		In the second form, you specify the red, green and blue components for a palette entry directly, by calling ##**Palette**## with 4 parameters. In this case ##//r//##, ##//g//## and ##//b//## must be in the range ##0##-##255##.
		
	==Third form==
		Calling ##**Palette Using**## allows to set a list of color values all at once; you should pass an array holding enough elements as the color indices available for your current graphics mode color depth (2 for 1bpp, 4 for 2bpp, 16 for 4bpp or 256 for 8bpp). The array elements must be integer color values in the form described above. The colors stored into ##//arrayname//## starting with given ##//idx//## index are then assigned to each palette index, starting with index ##0##.
	
	Form 1 and 3 are for backward compatibility with QB; form 2 is meant to ease palette handling. Any change to the palette is immediately visible on screen.
	
	If the ##**Get**## option is specified, ##**Palette**## retrieves instead of setting color values for the current palette. The parameters have the same meaning as specified for the form being used, but in this case color, ##//r//##, ##//g//## and ##//b//## must be variables passed by reference that will hold the color RGB values on function exit.

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/gfx/palette.bas"}}%%(freebasic)
' Setting a single color, form 1.
screen 15
locate 1,1: color 15
print "Press any key to change my color!"
sleep
' Now change color 15 hues to bright red
palette 15, &h00003F
sleep
%%

{{fbdoc item="filename" value="examples/manual/gfx/palette2.bas"}}%%(freebasic)
' Getting a single color, form 2.
dim as integer r, g, b
screen 13
palette get 32, r, g, b
print "Color 32 hues:"
print using "Red:### Green:### Blue:###"; r; g; b
sleep
%%

{{fbdoc item="filename" value="examples/manual/gfx/palette3.bas"}}%%(freebasic)
' Getting whole palette, form 3.
dim pal(0 to 255) as integer
screen 13
palette get using pal
for i as integer = 0 to 15
	print using "Color ## = &"; i; hex(pal(i), 6)
next i
sleep
%%

{{fbdoc item="diff"}}
	- ""QBasic"" did not support PALETTE GET to retrieve a palette.
	- ""QBasic"" did not allow passing individual red/green/blue values.

{{fbdoc item="see"}}
	- ##[[KeyPgScreengraphics|Screen (Graphics)]]##
	- ##[[KeyPgColor|Color]]##
	- ##[[KeyPgUsing|Using]]##
	- [[GfxInternalFormats|Internal Pixel Formats]]
	- [[GfxDefPalettes|Default Palettes]]

{{fbdoc item="back" value="CatPgGfx2D|2D Drawing Functions"}}