Skip to content

[p5.js 2.0 Bug Report]: p5.Color.toString('#rrggbb') always returns HSL string #8451

@finleyaa

Description

@finleyaa

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:

  1. Create a p5.Color instance in any color mode
  2. 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.');
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions