1. setrgbcolor

Sets the current RGB color for painting operations.

1.1. Syntax

red green blue setrgbcolor → –

1.2. Stack Effects

Table 1. Before
Level Object

2

red (0.0 to 1.0)

1

green (0.0 to 1.0)

0

blue (0.0 to 1.0)

Table 2. After
Level Object

(empty)

Color space set to DeviceRGB, color set to (r,g,b)

1.3. Description

setrgbcolor sets the color space to DeviceRGB and sets the current color using red, green, and blue components.

Each component must be in range 0.0 to 1.0: * 0.0 = none of that color * 1.0 = full intensity * Values outside range are clamped (no error)

1.4. PostScript Level

Level 1 and later

1.5. Examples

Primary colors
1 0 0 setrgbcolor  % Red
0 1 0 setrgbcolor  % Green
0 0 1 setrgbcolor  % Blue
Secondary colors
1 1 0 setrgbcolor  % Yellow
1 0 1 setrgbcolor  % Magenta
0 1 1 setrgbcolor  % Cyan
Grayscale via RGB
0 0 0 setrgbcolor    % Black
0.5 0.5 0.5 setrgbcolor  % 50% gray
1 1 1 setrgbcolor    % White
Custom colors
0.8 0.4 0.2 setrgbcolor  % Brown/orange
0.2 0.4 0.8 setrgbcolor  % Blue-ish

1.6. Common Use Cases

1.6.1. Color Graphics

gsave
  1 0 0 setrgbcolor  % Red
  drawShape fill
grestore

gsave
  0 0 1 setrgbcolor  % Blue
  drawOutline stroke
grestore

1.6.2. Color-Coded Elements

/colors [
  [1 0 0]  % Red
  [0 1 0]  % Green
  [0 0 1]  % Blue
] def

0 1 2 {
  colors exch get aload pop
  setrgbcolor
  drawElement
} for

1.7. Common Pitfalls

Changes Color Space - Switches to DeviceRGB color space.
0.5 setgray          % DeviceGray
1 0 0 setrgbcolor    % DeviceRGB (gray setting lost)
Values Clamped - Out-of-range values adjusted, not rejected.
1.5 0 0 setrgbcolor  % Becomes 1.0 0 0 (red)
Not CMYK - For print, CMYK may be more appropriate.
Use for Screen Display - RGB ideal for monitors/displays.

1.8. Error Conditions

Error Condition

[stackunderflow]

Fewer than 3 operands on stack

[typecheck]

Any operand not a number

[undefined]

Disabled in certain contexts

1.9. Implementation Notes

  • Fast color setting operation

  • Additive color model (light-based)

  • Device converts to native color space if needed

  • Default for many display devices

1.10. RGB Color Mixing

R + G = Yellow
R + B = Magenta
G + B = Cyan
R + G + B = White

1.11. See Also


Back to top

Copyright © 2025 Ribose. PostScript is a trademark of Adobe. Distributed under the MIT License.