From eb176d1d5db6aff1b9da885fb03c4de176beb4b3 Mon Sep 17 00:00:00 2001 From: LalitNarayanYadav Date: Wed, 28 Oct 2026 00:47:41 +0530 Subject: [PATCH] Fix paletteLerp() returning undefined outside p5.strands --- src/strands/strands_api.js | 5 ++++- test/unit/webgl/p5.Shader.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/strands/strands_api.js b/src/strands/strands_api.js index 37d219e2f2..b820baac8a 100644 --- a/src/strands/strands_api.js +++ b/src/strands/strands_api.js @@ -1178,8 +1178,11 @@ export function initGlobalStrandsAPI(p5, fn, strandsContext) { ); return createStrandsNode(id, dimension, strandsContext); }); + const originalPaletteLerp = fn.paletteLerp; augmentFn(fn, p5, 'paletteLerp', function(stopsNode, tNode) { - if (!strandsContext.active) return; + if (!strandsContext.active) { + return originalPaletteLerp.apply(this, arguments); + } if (!Array.isArray(stopsNode)) { throw new Error( diff --git a/test/unit/webgl/p5.Shader.js b/test/unit/webgl/p5.Shader.js index a8f8f13dee..58a47fa18b 100644 --- a/test/unit/webgl/p5.Shader.js +++ b/test/unit/webgl/p5.Shader.js @@ -941,6 +941,21 @@ suite('p5.Shader', function () { assert.isArray(p5.prototype.paletteLerp.argTypes); }); + test('paletteLerp() falls back to the CPU implementation outside of strands', () => { + myp5.colorMode(myp5.RGB); + const c = myp5.paletteLerp( + [ + [myp5.color(255, 0, 0), 0], + [myp5.color(0, 0, 255), 1] + ], + 0.5 + ); + assert.isDefined(c); + assert.closeTo(c._color.coords[0] * 255, 127.5, 1); + assert.closeTo(c._color.coords[1] * 255, 0, 1); + assert.closeTo(c._color.coords[2] * 255, 127.5, 1); + }); + test('arrays outside of argTypes arguments still become vectors', () => { myp5.createCanvas(5, 5, myp5.WEBGL); // More than 4 elements would be an error if this were a vector