Loading

Pcolor

processing

Pcolor creates colors for storing in ARGB LONG datatype.

  • RGB: The most efficient is to skip Pcolor function, using the raw ARGB format: 0x102030FF means Red 32, Green 48, Blue 255 with alpha=16/255. Alpha 0xFF means fully opaque.
  • HSB: For Hue Saturation Brightness to RGB conversion, use PcolorMode to specify HSB, then use Pcolor to convert to ARGB.

The parameters are interpreted as RGB or HSB values depending on the current PcolorMode. The default mode is RGB values from 0 to 255.

Note that if only one value is provided to Pcolor, it will be interpreted as a grayscale value. Add a second value, and it will be used for alpha transparency. When three values are specified, they are interpreted as either RGB or HSB values. Adding a fourth value applies alpha transparency.

Link to original Processing doc

Pcolor is available since version 1.0.0.

See also

Signatures

Examples

// working with RGB // @preview image 300 200 '2D' PGraphics //new image instance, 300x200 pixels 3 PstrokeWeight //stroke width 3pixels 0xff0000ff Pstroke //blue stroke (ARGB color) 0x7fff0000 Pcolor Pfill //semi transparent red fill 10 50 50 100 Prect 180 Pcolor Pfill //dark grey 60 50 50 100 Prect 180 150 Pcolor Pfill //dark grey with 150/255 opacity 110 50 50 100 Prect 0 255 255 Pcolor Pfill //cyan (green+blue) 160 50 50 100 Prect 255 0 0 127 Pcolor Pfill //red with 60/255 opacity 210 50 50 100 Prect 255 0 0 127 Pcolor 'color' STORE Pencode //render the image in a base64 format on the stack $color TYPEOF // the output of Pcolor is a long $color TOHEX // 255 0 0 127 Pcolor is 0x7fff0000.
// working with HSB // @preview image 300 200 '2D' PGraphics //new image instance, 300x200 pixels 'HSB' PcolorMode 3 PstrokeWeight //stroke width 3pixels 0xff0000ff Pstroke //blue stroke (ARGB color) 0x7fff0000 Pcolor Pfill //semi transparent red fill 10 50 50 100 Prect 180 Pcolor Pfill //dark grey 60 50 50 100 Prect 180 150 Pcolor Pfill //dark grey with 150/255 opacity 110 50 50 100 Prect 0 255 255 Pcolor Pfill //red (hue 0, saturation and brightness maximal) 160 50 50 100 Prect 255 150 120 180 Pcolor Pfill //kind of brown with 180/255 opacity 210 50 50 100 Prect 255 0 0 127 Pcolor 'color' STORE Pencode //render the image in a base64 format on the stack