-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Open
Labels
Description
Most appropriate sub-area of p5.js?
- Accessibility
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Image
- IO
- Math
- Typography
- Utilities
- WebGL
- Build process
- Unit testing
- Internationalization
- Friendly errors
- Other (specify if possible)
p5.js version
2.x
Web browser and version
Google Chrome 142.0.7444.176 (Official Build) (arm64)
Operating system
MacOSX 15.3.2 (24D81)
Steps to reproduce this
Steps:
- Create a
p5.Colorinstance in any color mode - Call
.toString('#rrggbb')or.toString('rgba(r, g, b, a)')on the p5.Color instance
Snippet:
// Taken from https://beta.p5js.org/reference/p5.color/tostring/
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.');
}Working snippet
It seems that calling .toString('hex') does work, because that's the name of the format in colorjs.io.
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('hex'), 50, 50);
describe('The text "#9932cc" written in purple on a gray background.');
}