@@ -16,6 +16,8 @@ const rangeArea = document.getElementById('range-detected');
16
16
const waveLines = document . getElementsByClassName ( "wave-line" ) ;
17
17
const findPitchArea = document . getElementById ( "find-pitch" ) ;
18
18
19
+ const sparkleAudio = new Audio ( './audio/きらきら輝く.mp3' ) ;
20
+
19
21
let song = [
20
22
{ note : 'C4' , duration : 0.7 } ,
21
23
{ note : 'C4' , duration : 0.7 } ,
@@ -204,6 +206,15 @@ function playSong() {
204
206
oscillator . stop ( currentTime + note . duration ) ;
205
207
currentTime += note . duration ;
206
208
} ) ;
209
+
210
+ const songEndTime = currentTime ;
211
+ setTimeout ( ( ) => {
212
+ sparkleInterval = setInterval ( addStar , 50 ) ;
213
+ sparkleAudio . play ( ) ;
214
+ sparkleAudio . addEventListener ( 'ended' , function ( ) {
215
+ clearInterval ( sparkleInterval ) ;
216
+ } ) ;
217
+ } , songEndTime * 1000 ) ;
207
218
}
208
219
209
220
function main ( stream ) {
@@ -290,7 +301,7 @@ function main(stream) {
290
301
291
302
if ( deltaTime >= 1 && ! isStart ) {
292
303
pixelsPerSecond = totalShiftedPixels / deltaTime ;
293
-
304
+
294
305
isStart = true ;
295
306
startLine . style . opacity = "1" ;
296
307
startLine . style . right = pixelsPerSecond . toFixed ( 2 ) * 8 + "px" ;
@@ -556,4 +567,17 @@ function analyzePitchData() {
556
567
btnLowKeyPlay . classList = "btn btn-song-start" ;
557
568
btnPlay . classList = "btn-outline" ;
558
569
}
570
+ }
571
+
572
+ /**
573
+ * 星エフェクト
574
+ */
575
+ function addStar ( ) {
576
+ var s = document . createElement ( 'div' )
577
+ s . className = 'star'
578
+ s . style . setProperty ( '--size' , Math . random ( ) * 10 + 3 + 'vmin' )
579
+ s . style . left = Math . floor ( Math . random ( ) * 100 ) + '%'
580
+ s . style . top = Math . floor ( Math . random ( ) * 100 ) + '%'
581
+ s . onanimationend = function ( ) { this . remove ( ) }
582
+ document . body . appendChild ( s )
559
583
}
0 commit comments