1. setrgbcolor
Sets the current RGB color for painting operations.
1.2. Stack Effects
| Level | Object |
|---|---|
2 |
|
1 |
|
0 |
|
| 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.5. Examples
1 0 0 setrgbcolor % Red
0 1 0 setrgbcolor % Green
0 0 1 setrgbcolor % Blue
1 1 0 setrgbcolor % Yellow
1 0 1 setrgbcolor % Magenta
0 1 1 setrgbcolor % Cyan
0 0 0 setrgbcolor % Black
0.5 0.5 0.5 setrgbcolor % 50% gray
1 1 1 setrgbcolor % White
0.8 0.4 0.2 setrgbcolor % Brown/orange
0.2 0.4 0.8 setrgbcolor % Blue-ish
1.6. Common Use Cases
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 |
|---|---|
[ |
Fewer than 3 operands on stack |
[ |
Any operand not a number |
[ |
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.11. See Also
-
setgray- Set grayscale -
setcmykcolor- Set CMYK (Level 2) -
sethsbcolor- Set HSB -
currentrgbcolor- Get RGB color