- Sets the draw color in the draw state.
- col
-
- The index of the color to use. Default is 6 (light gray).
- return-value
-
- The previous draw color.
The col parameter accepts a numeric color argument in the range of 0 to 15, representing a color from the 16-color PICO-8 palette. This color will be saved in the draw state to use for future draw calls. This is sometimes called the "pen color".
Many graphics functions also have an optional col parameter that behaves exactly like the one here. When this parameter is not filled, the current color in the draw state is used by default. When an actual color argument is provided to these functions, it is used, and then the draw state is updated to use that color in the future, as if color()
had been called with that value.
The previous color is returned when calling color()
, allowing it to be saved and restored if needed.
Use with patterns[]
Normally only the lo nybble of the value passed in col
matters. However, when using fill patterns (see fillp()
for details), the hi nybble represents the second color in the pattern. For example, to fill with brown and orange, call col(0x49)
.
Technical notes[]
The current pen color is memory-mapped and may be read or written directly with peek()
and poke()
:
- 0x5f25 / 24357: current pen color
Examples[]
cls()
color(7) -- white
circfill(20, 20, 10)
circfill(60, 60, 10)
color(8) -- red
circfill(20, 60, 10)
circfill(60, 20, 10)
pal(7, 10) -- white -> yellow
color(7)
circfill(20, 100, 10)
circfill(60, 100, 10)
-- get the current color from its memory-mapped address
cur_color=peek(0x5f25)