@ginden/blinkstick-v2
Version:
Improved Blickstick API for Node.js
36 lines • 1.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.pulse = pulse;
const simple_frame_1 = require("../frame/simple-frame");
const clamp_1 = require("../../utils/clamp");
const tsafe_1 = require("tsafe");
const assert_fps_below_100_1 = require("../helpers/assert-fps-below-100");
/**
* Pulses a color and backs off to black.
* @category Animations
*/
function pulse([r, g, b], { overMs, ...opts }) {
(0, tsafe_1.assert)(overMs > 0, 'overMs must be greater than 0');
const { steps = overMs / 34 } = opts;
(0, assert_fps_below_100_1.assertFpsBelow100)(overMs, steps);
return {
*[Symbol.iterator]() {
const stepDuration = (overMs / (steps * 2)) | 0;
for (let i = 0; i < steps; i++) {
const brightness = i * (255 / steps);
yield simple_frame_1.SimpleFrame.fromProperties({
rgb: [(0, clamp_1.clampRgb)(r * brightness), (0, clamp_1.clampRgb)(g * brightness), (0, clamp_1.clampRgb)(b * brightness)],
duration: stepDuration | 0,
});
}
for (let i = steps - 1; i >= 0; i--) {
const brightness = i * (255 / steps);
yield simple_frame_1.SimpleFrame.fromProperties({
rgb: [(0, clamp_1.clampRgb)(r * brightness), (0, clamp_1.clampRgb)(g * brightness), (0, clamp_1.clampRgb)(b * brightness)],
duration: stepDuration | 0,
});
}
},
};
}
//# sourceMappingURL=pulse.js.map