Using Colors

Functions such as 'setColor' and 'fill' take an array of different values. These include names of colours, hexadecimal numbers, and RGB values.

Named Colors

The first type of colour you can set is a named colour. Only a handful of names are supported, but this includes common ones. We also picked shades we thought looked nicer then the standard ones.

The colors supported are:

These can be supplied as a symbol or a string, such as :pink or 'pink'.

fill( "black" )
setColor( :green )

A 'Red, Green, Blue' Color

Fill and setColor also support passing in three, separate colour values.

setColor( red, green, blue )

fill( 0, 0, 0 ) // black
fill( 255, 0, 0 ) // red
setColor( 255, 255, 255 ) // white
setColor( 255, 128, 0 ) // Orange

These combined make up the colour used when drawing. Each value must be between 0 and 255, where 0 is no colour and 255 is to use the full amount of that colour component.

An RRGGBB Hexadecimal Color

Web-style hexadecimal colours are also supported. These are supplied as 6 digits, in hexadecimal, each from 0 to F. They can be supplied as a symbol or as a string.

// Orange
setColor( :FF9900 )
setColor( 'FF9900 )

// black
fill( "000000" )
fill( :000000 )

RGB Hexadecimal Color

You can also supply colours in a 3 part hexadecimal value. This is the same as the previous 6 digit version, but with each scaled into a 6 colour one. For example "Fa2" would be converted into "FFaa22".

// Orange
setColor( :F90 )
setColor( 'F90 )

// black
fill( "000" )
fill( :000 )

As a Number, or using 0x

Finally you can also provide colours as a Number. It is presumed the colour is stored in the number as 3 bytes, in the RGB format. This means 0 is black whilst 16777215 is white.

You can also use the 0x prefix on a number, for it to be read as a hexadecimal value. For example 0xFFFFFF is white.

This allows you to use bit-twiddling algorithms for altering colours, as a single number.

setColor( 0xff9900 ) // orange

// black
fill( 0 )
fill( 0x0 )

// green, these are all the same number value
setColor( 0x0000FF )
setColor( 0x00FF )
setColor( 0xFF )
setColor( 255 )