Skip to content

Commit 25d5416

Browse files
committed
Lerping Color Correctly
1 parent 3b81277 commit 25d5416

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/p5.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,17 +2103,17 @@ amdclean['colorcreating_reading'] = function (require, core, p5Color) {
21032103
if (c1 instanceof Array) {
21042104
var c = [];
21052105
for (var i = 0; i < c1.length; i++) {
2106-
c.push(p5.prototype.lerp(c1[i], c2[i], amt));
2106+
c.push(Math.sqrt(p5.prototype.lerp(c1[i]*c1[i], c2[i]*c2[i], amt)));
21072107
}
21082108
return c;
21092109
} else if (c1 instanceof p5.Color) {
21102110
var pc = [];
21112111
for (var j = 0; j < 4; j++) {
2112-
pc.push(p5.prototype.lerp(c1.rgba[j], c2.rgba[j], amt));
2112+
pc.push(Math.sqrt(p5.prototype.lerp(c1.rgba[j]*c1.rgba[j], c2.rgba[j]*c2.rgba[j], amt)));
21132113
}
21142114
return new p5.Color(this, pc);
21152115
} else {
2116-
return p5.prototype.lerp(c1, c2, amt);
2116+
return Math.sqrt(p5.prototype.lerp(c1*c1, c2*c2, amt));
21172117
}
21182118
};
21192119
p5.prototype.red = function (c) {

0 commit comments

Comments
 (0)