Referencia 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)'.

Sintaxis

toString([format])

Parámetros

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.
function setup() { createCanvas(100, 100); background(200); // Create a p5.Color object. let myColor = color('darkorchid'); // Style the text. textAlign(CENTER); textSize(16); // Display the text. text(myColor.toString('#rrggbb'), 50, 50); describe('The text "#9932cc" written in purple on a gray background.'); }
Notice any errors or typos? Please let us know. Please feel free to edit src/color/p5.Color.js and open a pull request!

Referencias Relacionadas