Pardon the mess, Play My Code is in beta!


sign up - lost password


This sets the current colour used when drawing. This affects every drawing operation, including Images, when they are drawn. For example you can use it draw red rectangles, green circles, or blue background images.

See the article on Using Colors for an explanation on the colour values this function can take.

setColor( color, alpha=1 )

Sets the 'color' and 'alpha' value used when drawing. If the 'alpha' is not provided, then it default to 1 (full alpha).

Alpha should be a value from 0.0 to 1.0, whilst the colour should be a named colour or other whole colour value.

setColor( color, alpha=1 ) { ... }

setColor can also take a block, where the colour and alpha values are only altered for the lifetime of the block. When the block returns, the colour is set back to what it was before this was called.

setColor( red, green, blue, alpha=1 )

Sets the drawing colour to the red, green, blue value given. The should be a number between 0 and 255. The alpha value can be optionally provided, and if it is omitted then it will default to 1.0.

setColor( red, green, blue, alpha=1 ) { ... }

Like the other version of setColor above, which also takes a block, this will only alter the drawing colour and alpha value for the lifetime of this block.

Once the block returns, the drawing colour and alpha are set back to the values they were from before this function was called.

See Also