Name
SetPalette -- change palette (V9.0)
Synopsis
SetPalette(id[, t])
Function
This function replaces all pens in the currently active palette with the pens from palette specified by id. By default, the current display's palette is the active palette but of course only in case the current display is a palette mode display. See Palette mode displays for details. A palette can be made the active one by using the SelectPalette() command.

Alternatively, the palette specified by id can also be copied to other objects. To do so, you need to pass the optional table argument to SetPalette() and set the destination object type in the Type table tag and the object's identifier in the ID table tag. For example, to assign palette 1 to brush 2, do the following:

 
SetPalette(1, {Type = #BRUSH, ID = 2})

The following tags are supported by the optional table argument t:

Type:
Set this to the type identifier of the object you want to copy the palette to. This can be one of the following object types:

 
#ANIM
#BGPIC
#BRUSH
#DISPLAY
#LAYER
#PALETTE
#SPRITE

Note that if you use types #ANIM or #SPRITE, you also need to set the Frame tag (see below) to indicate the frame whose palette you want to modify. If you use #LAYER and the specified layer is an anim layer, you also need to set the Frame tag.

Type defaults to the type of the currently active palette selected using SelectPalette(). See SelectPalette for details.

ID:
Set this tag to the identifier of the object you want to copy the palette to. The default is the identifier of the currently active palette selected using SelectPalette(). See SelectPalette for details.

Frame:
If the palette is to be copied to an animation, sprite, or anim layer, you need to set this tag to specify the frame the palette should be copied to. Frames are counted from 1. Defaults to 1 when used with anims and sprites and to the current frame when used with anim layers.

Remap:
If this is set to True, the colors of the target object will be remapped to match the colors in the source palette as closely as possible. By default, there will be no remapping and the actual pixel data of the target object will remain untouched. If you want remapping, set this tag to True but be warned that remapping all pixels will of course take much more time than just setting a new palette without remapping. Defaults to False.

Dither:
If the Remap tag (see above) has been set to True, you can use the Dither tag to specify whether or not dithering should be used. Defaults to True which means dithering should be used.

CopyCycleTable:
Palettes can have a table containing color cycling information. If you set this tag to True, this cycle table will be copied to the target object as well. Defaults to False.

Inputs
id
id of the palette to set
t
optional: table for specifying further options (see above)
Example
@DISPLAY {Palette = #PALETTE_MONOCHROME}
SetFillStyle(#FILLCOLOR)
SetPaletteMode(#PALETTEMODE_PEN)
SetDrawPen(1)
Box(#CENTER, #CENTER, 320, 240)
WaitLeftMouse
CreatePalette(1, {#WHITE, #BLACK}, {Depth = 1})
SetPalette(1)
The code above creates a monochrome palette display with a black background and white rectangle in the center. After a mouse-click the colors of the background and the white rectangle will be reversed by setting a new palette which uses white instead of black in pen 0 and black instead of white in pen 1.

Show TOC