Skip to content

[p5.js 2.0+ Bug Report]: lerpColor() not affected by colorMode() #8883

@fidelthomet

Description

@fidelthomet

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • WebGPU
  • p5.strands
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

2.3.0

Web browser and version

browser independent, tested on Safari Version 26.5 (21624.2.5.11.4)

Operating system

MacOS

Steps to reproduce this

setting the colorMode() to anything other than RGB doesn't seem to affect lerpColor. This used to work in previous p5 versions and the documentation reads:

The way that colors are interpolated depends on the current colorMode().

expected (p5.js 1.x):

Image

actual result (p5.js 2.x):

Image

Steps:

  1. Copy the code snippet into a p5.js 2.0+ version
  2. Compare result with running the code in p5.js 1.x

Snippet:

function setup() {
  createCanvas(100, 100);

  background(200);

  // Create p5.Color objects to interpolate between.
  let from = color(218, 165, 32);
  let to = color(72, 61, 139);

  colorMode(HSB)
  
  // Create intermediate colors.
  let interA = lerpColor(from, to, 0.33);
  let interB = lerpColor(from, to, 0.66);

  // Draw the left rectangle.
  noStroke();
  fill(from);
  rect(10, 20, 20, 60);

  // Draw the left-center rectangle.
  fill(interA);
  rect(30, 20, 20, 60);

  // Draw the right-center rectangle.
  fill(interB);
  rect(50, 20, 20, 60);

  // Draw the right rectangle.
  fill(to);
  rect(70, 20, 20, 60);

  describe(
    'Four rectangles. From left to right, the rectangles are tan, brown, brownish purple, and purple.'
  );
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions