Reference toString()

toString()

Returns the color formatted as a String.

Calling myColor.toString() can be useful for debugging, as in print(myColor.toString()). It's also helpful for using p5.js with other libraries.

The parameter, format, is optional. If a format string is passed, as in myColor.toString('#rrggbb'), it will determine how the color string is formatted. By default, color strings are formatted as 'rgba(r, g, b, a)'.

Examples

Syntax

toString([format])

Parameters

format
String:

how the color string will be formatted. Leaving this empty formats the string as rgba(r, g, b, a). '#rgb' '#rgba' '#rrggbb' and '#rrggbbaa' format as hexadecimal color codes. 'rgb' 'hsb' and 'hsl' return the color formatted in the specified color mode. 'rgba' 'hsba' and 'hsla' are the same as above but with alpha channels. 'rgb%' 'hsb%' 'hsl%' 'rgba%' 'hsba%' and 'hsla%' format as percentages.

Returns

String: the formatted string.
This page is generated from the comments in src/color/p5.Color.js . Please feel free to edit it and submit a pull request!

Related References