Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/strands/strands_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1179,8 +1179,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(
Expand Down
15 changes: 15 additions & 0 deletions test/unit/webgl/p5.Shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading