Skip to content

Commit ff4da82

Browse files
committed
add sparkle star
1 parent 4455184 commit ff4da82

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

audio/きらきら輝く.mp3

119 KB
Binary file not shown.

js/song-script.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const rangeArea = document.getElementById('range-detected');
1616
const waveLines = document.getElementsByClassName("wave-line");
1717
const findPitchArea = document.getElementById("find-pitch");
1818

19+
const sparkleAudio = new Audio('./audio/きらきら輝く.mp3');
20+
1921
let song = [
2022
{ note: 'C4', duration: 0.7 },
2123
{ note: 'C4', duration: 0.7 },
@@ -204,6 +206,15 @@ function playSong() {
204206
oscillator.stop(currentTime + note.duration);
205207
currentTime += note.duration;
206208
});
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);
207218
}
208219

209220
function main(stream) {
@@ -290,7 +301,7 @@ function main(stream) {
290301

291302
if (deltaTime >= 1 && !isStart) {
292303
pixelsPerSecond = totalShiftedPixels / deltaTime;
293-
304+
294305
isStart = true;
295306
startLine.style.opacity = "1";
296307
startLine.style.right = pixelsPerSecond.toFixed(2) * 8 + "px";
@@ -556,4 +567,17 @@ function analyzePitchData() {
556567
btnLowKeyPlay.classList = "btn btn-song-start";
557568
btnPlay.classList = "btn-outline";
558569
}
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)
559583
}

0 commit comments

Comments
 (0)