diff --git a/src/song-274/fade.ts b/src/song-274/fade.ts index e1423d5..e9d14e1 100644 --- a/src/song-274/fade.ts +++ b/src/song-274/fade.ts @@ -5,6 +5,8 @@ /** Seconds of complete black at start */ export const FADE_IN_PRE = 0.4; +/** Seconds of complete black at end */ +export const FADE_OUT_POST = 0.4; /** Seconds from black to the picture at the start. 0 disables the fade-in. */ export const FADE_IN_S = 0.3; /** Seconds from the picture to black at the end. 0 disables the fade-out. */ @@ -19,6 +21,8 @@ const clamp01 = (v: number) => Math.min(1, Math.max(0, v)); */ export const blackOpacity = (t: number, lastFrameS: number): number => { const fadeIn = (t < FADE_IN_PRE) ? 1 : (FADE_IN_S > 0 ? 1 - clamp01((t - FADE_IN_PRE) / FADE_IN_S) : 0); - const fadeOut = FADE_OUT_S > 0 ? clamp01((t - (lastFrameS - FADE_OUT_S)) / FADE_OUT_S) : 0; + // Black from here to the last frame; the fade-out ramp ends exactly here. + const blackFromS = lastFrameS - FADE_OUT_POST; + const fadeOut = (t >= blackFromS) ? 1 : (FADE_OUT_S > 0 ? clamp01((t - (blackFromS - FADE_OUT_S)) / FADE_OUT_S) : 0); return Math.max(fadeIn, fadeOut); };