@@ -46,13 +46,27 @@ export const getStrobeColor: IColorGetter = (_, time) => {
4646}
4747
4848export const getPulseColor : IColorGetter = ( _ , time ) => {
49- const cycle = settings . syncToMusic && audioState . bpm ? 60000 / audioState . bpm : 1000
50- const t = ( time * settings . effectSpeed ) % cycle
51- if ( t < lastPulse ) {
49+ const target = settings . syncToMusic && audioState . bpm ? 60000 / audioState . bpm : 1000
50+
51+ if ( ! lastPulseTime ) {
52+ lastPulseTime = time
53+ pulseCycle = target
54+ }
55+
56+ const dt = ( time - lastPulseTime ) * settings . effectSpeed
57+ lastPulseTime = time
58+
59+ const elapsed = pulsePhase * pulseCycle + dt
60+ pulseCycle = target
61+ pulsePhase = elapsed / pulseCycle
62+
63+ if ( pulsePhase >= 1 ) {
64+ const cycles = Math . floor ( pulsePhase )
65+ pulsePhase -= cycles
5266 pulseColor = hslToRgb ( Math . random ( ) * 360 , 1 , 0.5 )
5367 }
54- lastPulse = t
55- const intensity = Math . sin ( ( t / cycle ) * Math . PI )
68+
69+ const intensity = Math . sin ( pulsePhase * Math . PI )
5670 return pulseColor . map ( c => Math . round ( c * intensity ) ) as IArrColor
5771}
5872
@@ -82,7 +96,9 @@ export const getMultiPulseColor: IColorGetter = (index, time) => {
8296let strobeColor : IArrColor = [ 255 , 255 , 255 ]
8397let lastStrobe = 0
8498let pulseColor : IArrColor = [ 255 , 0 , 0 ]
85- let lastPulse = 0
99+ let pulseCycle = 1000
100+ let pulsePhase = 0
101+ let lastPulseTime = 0
86102let multiPulseColors : IArrColor [ ] = Array ( 4 )
87103 . fill ( null )
88104 . map ( ( ) => hslToRgb ( Math . random ( ) * 360 , 1 , 0.5 ) )
@@ -95,7 +111,9 @@ export function resetExtraPatterns() {
95111 strobeColor = [ 255 , 255 , 255 ]
96112 lastStrobe = 0
97113 pulseColor = [ 255 , 0 , 0 ]
98- lastPulse = 0
114+ pulseCycle = 1000
115+ pulsePhase = 0
116+ lastPulseTime = 0
99117 multiPulseColors = Array ( 4 )
100118 . fill ( null )
101119 . map ( ( ) => hslToRgb ( Math . random ( ) * 360 , 1 , 0.5 ) )
0 commit comments