UNPKG

@osbjs/osbjs

Version:

a minimalist osu! storyboarding framework

133 lines (132 loc) 6.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.wiggleScaleXY = exports.wiggleScaleY = exports.wiggleScaleX = exports.wiggleScale = exports.wiggleOpacity = exports.wiggleColor = exports.wiggleRotation = exports.wiggleY = exports.wiggleX = exports.wiggleXY = void 0; const Utils_1 = require("../Utils"); const Math_1 = require("../../Math"); function wiggleXY(commandable, frequency, amplitude, startTime, endTime, origin = new Utils_1.OsbVector2(320, 240)) { let { x, y } = origin; let t = startTime; const timestep = 1000 / frequency; do { const newX = amplitude * (0, Math_1.noise2D)(origin.x, t) + origin.x, newY = amplitude * (0, Math_1.noise2D)(origin.y, t) + origin.y; commandable.Move(t, t + timestep, new Utils_1.OsbVector2(x, y), new Utils_1.OsbVector2(newX, newY)); x = newX; y = newY; t += timestep; } while (t < endTime); } exports.wiggleXY = wiggleXY; function wiggleX(commandable, frequency, amplitude, startTime, endTime, originX = 320) { let x = originX; let t = startTime; const timestep = 1000 / frequency; do { const newX = amplitude * (0, Math_1.noise2D)(originX, t) + originX; commandable.MoveX(t, t + timestep, x, newX); x = newX; t += timestep; } while (t < endTime); } exports.wiggleX = wiggleX; function wiggleY(commandable, frequency, amplitude, startTime, endTime, originY = 240) { let y = originY; let t = startTime; const timestep = 1000 / frequency; do { const newY = amplitude * (0, Math_1.noise2D)(originY, t) + originY; commandable.MoveY(t, t + timestep, y, newY); y = newY; t += timestep; } while (t < endTime); } exports.wiggleY = wiggleY; function wiggleRotation(commandable, frequency, amplitude, startTime, endTime, originAngle = 0) { let angle = originAngle; let t = startTime; const timestep = 1000 / frequency; do { const newAngle = amplitude * (0, Math_1.noise2D)(originAngle, t) + originAngle; commandable.Rotate(t, t + timestep, angle, newAngle); angle = newAngle; t += timestep; } while (t < endTime); } exports.wiggleRotation = wiggleRotation; function wiggleColor(commandable, frequency, amplitude, startTime, endTime, minGradient, maxGradient) { const originR = Math.round((minGradient.r + maxGradient.r) / 2), originG = Math.round((minGradient.g + maxGradient.g) / 2), originB = Math.round((minGradient.b + maxGradient.b) / 2); const ampR = Math.min(Math.round(amplitude), originR), ampG = Math.min(Math.round(amplitude), originR), ampB = Math.min(Math.round(amplitude), originR); let r = originR, g = originG, b = originB; let t = startTime; const timestep = 1000 / frequency; do { const noiseR = (0, Math_1.noise2D)(originR, t), noiseG = (0, Math_1.noise2D)(originG, t), noiseB = (0, Math_1.noise2D)(originB, t); const newR = (0, Math_1.lerp)(noiseR, -1, 1, originR - ampR, originR + ampR), newG = (0, Math_1.lerp)(noiseG, -1, 1, originG - ampG, originG + ampG), newB = (0, Math_1.lerp)(noiseB, -1, 1, originB - ampB, originB + ampB); commandable.Color(t, t + timestep, new Utils_1.OsbColor(r, g, b), new Utils_1.OsbColor(newR, newG, newB)); r = newR; g = newG; b = newB; t += timestep; } while (t < endTime); } exports.wiggleColor = wiggleColor; function wiggleOpacity(commandable, frequency, amplitude, startTime, endTime, originOpacity = 0.5) { let opacity = originOpacity; let t = startTime; const timestep = 1000 / frequency; do { const newAngle = amplitude * (0, Math_1.noise2D)(originOpacity, t) + originOpacity; commandable.Fade(t, t + timestep, opacity, newAngle); opacity = newAngle; t += timestep; } while (t < endTime); } exports.wiggleOpacity = wiggleOpacity; function wiggleScale(commandable, frequency, amplitude, startTime, endTime, originScale = 0.5) { let scale = originScale; let t = startTime; const timestep = 1000 / frequency; do { const newScale = amplitude * (0, Math_1.noise2D)(originScale, t) + originScale; commandable.Scale(t, t + timestep, scale, newScale); scale = newScale; t += timestep; } while (t < endTime); } exports.wiggleScale = wiggleScale; function wiggleScaleX(commandable, frequency, amplitude, startTime, endTime, originScaleX = 0.5, scaleY = 1) { let scale = originScaleX; let t = startTime; const timestep = 1000 / frequency; do { const newScale = amplitude * (0, Math_1.noise2D)(originScaleX, t) + originScaleX; commandable.ScaleVec(t, t + timestep, new Utils_1.OsbVector2(scale, scaleY), new Utils_1.OsbVector2(newScale, scaleY)); scale = newScale; t += timestep; } while (t < endTime); } exports.wiggleScaleX = wiggleScaleX; function wiggleScaleY(commandable, frequency, amplitude, startTime, endTime, originScaleY = 0.5, scaleX = 1) { let scale = originScaleY; let t = startTime; const timestep = 1000 / frequency; do { const newScale = amplitude * (0, Math_1.noise2D)(originScaleY, t) + originScaleY; commandable.ScaleVec(t, t + timestep, new Utils_1.OsbVector2(scaleX, scale), new Utils_1.OsbVector2(scaleX, newScale)); scale = newScale; t += timestep; } while (t < endTime); } exports.wiggleScaleY = wiggleScaleY; function wiggleScaleXY(commandable, frequency, amplitude, startTime, endTime, originScaleX = 0.5, originScaleY = 0.5) { let scaleX = originScaleX, scaleY = originScaleY; let t = startTime; const timestep = 1000 / frequency; do { const newScaleX = amplitude * (0, Math_1.noise2D)(originScaleX, t) + originScaleX, newScaleY = amplitude * (0, Math_1.noise2D)(originScaleY, t) + originScaleY; commandable.ScaleVec(t, t + timestep, new Utils_1.OsbVector2(scaleX, scaleY), new Utils_1.OsbVector2(newScaleX, newScaleY)); scaleX = newScaleX; scaleY = newScaleY; t += timestep; } while (t < endTime); } exports.wiggleScaleXY = wiggleScaleXY;