New Spinny

This commit is contained in:
bingus_violet 2024-06-07 22:02:19 -05:00
parent 9367dbd72b
commit 343fb5b879

View file

@ -17,19 +17,25 @@ const discStatuses = {
} }
} }
const spinSpeed = 30
var pfp var pfp
var music = new Audio("/snds/Lotus Waters.ogg") var music = new Audio("/snds/Lotus Waters.ogg")
var whipLash = new Audio("/snds/johnny-test-whip-crack.mp3") music.preservesPitch = false
music.loop = true music.loop = true
music.volume = 0.45 music.playbackRate = 0
whipLash.volume = 0.25 // var whipLash = new Audio("/snds/johnny-test-whip-crack.mp3")
// whipLash.volume = 0.25
var sock var sock
var spins = 1 var spins = 0
var lastSent = 0
var globalSpins = 0 var globalSpins = 0
var spinning = false
var firsttimeDebounce = true var firsttimeDebounce = true
var spinWaiting = false var spinWaiting = false
@ -38,24 +44,36 @@ function resetPFP() {
pfp.src = "https://api.violets-purgatory.dev/v1/pfp?" + new Date().getTime() pfp.src = "https://api.violets-purgatory.dev/v1/pfp?" + new Date().getTime()
} }
function lerp(a, b, t) {
return a * (1 - t) + b * t
}
function spinLoop() { function spinLoop() {
spinWaiting = true spinWaiting = true
setTimeout(() => { setTimeout(() => {
spinWaiting = false spinWaiting = false
if (!music.paused) { if (spinning) {
music.volume = 0.5
music.playbackRate = lerp(music.playbackRate, 1, 1/spinSpeed)
if (spins > 1) { if (spins > 1) {
document.querySelector(".spinnyCount").style.display = "block" document.querySelector(".spinnyCount").style.display = "block"
document.querySelector(".localSpins").innerHTML = Math.ceil(spins - 1); document.querySelector(".localSpins").innerHTML = Math.ceil(spins - 1);
} }
spins += 0.5 spins += 1/spinSpeed / 3
if (Math.round(spins) == spins && sock && sock.OPEN) { document.querySelector(".pfp").style.rotate = (spins * 360) + "deg"
if (Math.floor(spins) != lastSent && sock && sock.OPEN) {
document.querySelector(".globalSpins").innerHTML = globalSpins + 1
lastSent = Math.floor(spins)
// resetPFP() // resetPFP()
sock.send(`{"op": 4}`) sock.send(`{"op": 4}`)
console.log("Spin Sent!") console.log("Spin Sent!")
} }
spinLoop() } else {
music.playbackRate = lerp(music.playbackRate, 0.5, 1/spinSpeed)
music.volume = lerp(music.volume, 0, 1/spinSpeed * 4)
} }
}, 1500); spinLoop()
}, 1/spinSpeed * 1000);
} }
window.onbeforeunload = function () { window.onbeforeunload = function () {
@ -67,26 +85,33 @@ window.onload = function () {
pfp = document.querySelector(".pfp") pfp = document.querySelector(".pfp")
spinLoop()
pfp.addEventListener("mousedown", () => { pfp.addEventListener("mousedown", () => {
if (!spinWaiting) { // if (!spinWaiting) {
spinLoop(); // spinLoop();
} // }
music.play() music.play()
pfp.style.animationName = "spinny" spinning = true
pfp.style.transition = ""
pfp.style.scale = "1.1" pfp.style.scale = "1.1"
}) })
document.body.onmouseup = () => { document.body.onmouseup = () => {
if (music.currentTime != 0) { if (music.currentTime != 0) {
music.currentTime = 0 // music.currentTime = 0
music.pause() // music.pause()
whipLash.currentTime = 0 // whipLash.currentTime = 0
whipLash.play() // whipLash.play()
spinning = false
pfp.style.transition = "all 3s cubic-bezier(0.39, 0.575, 0.565, 1)"
pfp.style.animationName = "unset"
pfp.style.scale = "1" pfp.style.scale = "1"
} }
} }