ITADN

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

#8883Openfidelthomet 创建于 2026-06-08
BugArea:ColorHelp Wantedp5.js 2.0+
F
fidelthometcommented
### Most appropriate sub-area of p5.js? - [ ] Accessibility - [x] 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](https://beta.p5js.org/reference/p5/lerpColor/). This used to work in previous p5 versions and the documentation reads: The way that colors are interpolated depends on the current [colorMode()](https://beta.p5js.org/reference/p5/colorMode/). expected (p5.js 1.x): <img width="643" height="329" alt="Image" src="https://github.com/user-attachments/assets/26fdc930-4ea7-4a81-8f1e-834ef2944149" /> actual result (p5.js 2.x): <img width="507" height="344" alt="Image" src="https://github.com/user-attachments/assets/f294a01a-d8b9-4a4b-9cac-5821e5648164" /> ### 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: ```js 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.' ); } ```
4 条评论