@@ -46,13 +46,25 @@ 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+ pulsePhase += dt / pulseCycle
59+
60+ if ( pulsePhase >= 1 ) {
61+ pulsePhase %= 1
5262 pulseColor = hslToRgb ( Math . random ( ) * 360 , 1 , 0.5 )
5363 }
54- lastPulse = t
55- const intensity = Math . sin ( ( t / cycle ) * Math . PI )
64+
65+ pulseCycle = target
66+
67+ const intensity = Math . sin ( pulsePhase * Math . PI )
5668 return pulseColor . map ( c => Math . round ( c * intensity ) ) as IArrColor
5769}
5870
@@ -82,7 +94,9 @@ export const getMultiPulseColor: IColorGetter = (index, time) => {
8294let strobeColor : IArrColor = [ 255 , 255 , 255 ]
8395let lastStrobe = 0
8496let pulseColor : IArrColor = [ 255 , 0 , 0 ]
85- let lastPulse = 0
97+ let pulseCycle = 1000
98+ let pulsePhase = 0
99+ let lastPulseTime = 0
86100let multiPulseColors : IArrColor [ ] = Array ( 4 )
87101 . fill ( null )
88102 . map ( ( ) => hslToRgb ( Math . random ( ) * 360 , 1 , 0.5 ) )
@@ -95,7 +109,9 @@ export function resetExtraPatterns() {
95109 strobeColor = [ 255 , 255 , 255 ]
96110 lastStrobe = 0
97111 pulseColor = [ 255 , 0 , 0 ]
98- lastPulse = 0
112+ pulseCycle = 1000
113+ pulsePhase = 0
114+ lastPulseTime = 0
99115 multiPulseColors = Array ( 4 )
100116 . fill ( null )
101117 . map ( ( ) => hslToRgb ( Math . random ( ) * 360 , 1 , 0.5 ) )
0 commit comments