diff --git a/src/extensions/scratch3_boost/index.js b/src/extensions/scratch3_boost/index.js index b04e07827..d10535e70 100644 --- a/src/extensions/scratch3_boost/index.js +++ b/src/extensions/scratch3_boost/index.js @@ -365,16 +365,16 @@ class BoostMotor { } /** - * @param {int} value - this motor's new power level, in the range [0,100]. + * @param {int} value - this motor's new power level, in the range [10,100]. */ set power (value) { - const p = Math.max(0, Math.min(value, 100)); - // The Boost motors barely move at speed 1 - solution is to step up to 2. - if (p === 1) { - this._power = 2; - } else { - this._power = p; - } + /** + * Scale the motor power to a range between 10 and 100, + * to make sure the motors will run with something built onto them. + */ + const p = MathUtil.scale(value, 0, 100, 10, 100); + + this._power = p; } /** diff --git a/src/util/math-util.js b/src/util/math-util.js index c5b5704e8..123d7714d 100644 --- a/src/util/math-util.js +++ b/src/util/math-util.js @@ -77,6 +77,20 @@ class MathUtil { const sorted = elts.slice(0).sort((a, b) => a - b); return elts.map(e => sorted.indexOf(e)); } + + /** + * Scales a number from one range to another. + * @param {number} i number to be scaled + * @param {number} iMin input range minimum + * @param {number} iMax input range maximum + * @param {number} oMin output range minimum + * @param {number} oMax output range maximum + * @return {number} scaled number + */ + static scale (i, iMin, iMax, oMin, oMax) { + const p = (i - iMin) / (iMax - iMin); + return (p * (oMax - oMin)) + oMin; + } } module.exports = MathUtil;