diff --git a/src/math/calculation.js b/src/math/calculation.js index 5ed489190b..da75446594 100644 --- a/src/math/calculation.js +++ b/src/math/calculation.js @@ -604,6 +604,10 @@ p5.prototype.mag = function(x, y) { */ p5.prototype.map = function(n, start1, stop1, start2, stop2, withinBounds) { p5._validateParameters('map', arguments); + // NEW: guard against zero input range to avoid division by zero + if (start1 === stop1) { + return start2; + } const newval = (n - start1) / (stop1 - start1) * (stop2 - start2) + start2; if (!withinBounds) { return newval;