Name
SetPen -- change pen color (V9.0)
Synopsis
SetPen(pen, color[, t])
Function
This function sets the color of the pen specified by pen to the color specified by color. The change will be done in the currently active palette. 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, you can also make SetPen() change pens in a different palette object. To do so, you need to pass the optional table argument t to SetPen() and specify the Type and ID tags. See below for an example.

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

Type:
Set this to the type identifier of the object whose pen you want to modify. 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 pen 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 whose pen you want to modify. The default is the identifier of the currently active palette selected using SelectPalette(). See SelectPalette for details.

Frame:
If the target type is an animation, sprite, or anim layer, you need to set this tag to specify the frame whose pen you want to modify. Frames are counted from 1. Defaults to 1 when used with anims and sprites and to the current frame when used with anim layers.

Inputs
pen
pen you want to modify (starting from 0)
color
new color for the pen, must be specified as an RGB color
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
SetPen(0, #WHITE)
SetPen(1, #BLACK)
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 pen 0 to white and pen 1 to black.


SetPen(4, #RED, {Type = #BRUSH, ID = 2})
The code changes pen 4 in brush 2 to red.

Show TOC