rgb color components

Every color on a computer screen is made by mixing red, green, and blue light. Each of the three colors can be adjusted to 256 intensities, from 0 to 255, which makes a total of

256 × 256 × 256 = 16777216 possible colors.

The rgb function

The rgb function can be used to create a color code that can be used with dot or pen or fill:

dot rgb(176, 224, 230), 150

The program above specifies a light blueish-greenish color that includes red with intensity 176, green with intensity 224, and blue with intensity 230.

Hex RGB color codes

Another way to write an RGB color is to use a CSS hex color code. Convert each of the components to a two-digit base-16 number, and then put them together in a string with a #:

decimalbase-16
Red176b0
Green224e0
Blue230e6
totalrgb(176,224,230)#b0e0e6

Adding light colors can sometimes be unintuitive: for example, red and green make yellow. For an alternative to rgb, see hsl, which allows you to specify colors by hue.

Partial transparency using rgba

The rgba function can be used to create a partially transparent color code. The fourth component "a", or "alpha" value is an opacity level from 0.0 to 1.0 that determines how the color is mixed with the colors "underneath".

So, for example, if a green dot is drawn with alpha 0.5, it is blended with the colors behind it:

bk 100
dot red, 200
fd 200
dot blue, 200
bk 100
dot(
  rgba(0, 255, 0, 0.5),
  200)