UNPKG

@ginden/blinkstick-v2

Version:
29 lines 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.morph = morph; const tsafe_1 = require("tsafe"); const clamp_1 = require("../../utils/clamp"); const simple_frame_1 = require("../frame/simple-frame"); const assert_fps_below_100_1 = require("../helpers/assert-fps-below-100"); /** * Generates intermediate frames between two RGB colors. * These don't include the start and end frames. * @category Animations */ function morph(from, to, overMs, steps = overMs / 16) { (0, tsafe_1.assert)(steps > 0, 'steps must be greater than 0'); (0, assert_fps_below_100_1.assertFpsBelow100)(overMs, steps); return { *[Symbol.iterator]() { const stepDuration = overMs / steps; for (let i = 0; i < steps; i++) { const ratio = (i + 1) / (steps + 1); const r = (0, clamp_1.clampRgb)(from[0] + (to[0] - from[0]) * ratio); const g = (0, clamp_1.clampRgb)(from[1] + (to[1] - from[1]) * ratio); const b = (0, clamp_1.clampRgb)(from[2] + (to[2] - from[2]) * ratio); yield new simple_frame_1.SimpleFrame([r, g, b], stepDuration); } }, }; } //# sourceMappingURL=morph.js.map