diff --git a/script.js b/script.js index a17ad29..5ccab8c 100644 --- a/script.js +++ b/script.js @@ -97,12 +97,14 @@ spinBtn.addEventListener("click", () => { console.log(target) + let degrees = 360 / display.length; + let rotationInterval = window.setInterval(() => { spinAmount *= 0.99 if (slowing_down) { spinAmount = Math.max(0.1, spinAmount) } else { - spinAmount = Math.max(2.5, spinAmount) + spinAmount = Math.max(4, spinAmount) } spinChart.options.rotation += spinAmount; @@ -111,18 +113,20 @@ spinBtn.addEventListener("click", () => { if (spinChart.options.rotation >= 360) { spinChart.options.rotation -= 360; } - if (spinAmount <= 4 && target.minDegree - 20 <= 360-spinChart.options.rotation && 360-spinChart.options.rotation < target.maxDegree-target_degree) { + if (spinAmount <= 5 && target.minDegree <= 360-spinChart.options.rotation && 360-spinChart.options.rotation < target.maxDegree - target_degree + (degrees/2) ) { + //console.log(target_degree); console.log(spinAmount + " Decreasing more") slowing_down = true; - spinAmount *= 0.8 - + spinAmount *= 0.9 if (spinAmount <= 0.1 && target.minDegree <= 360-spinChart.options.rotation && 360-spinChart.options.rotation < target.maxDegree-target_degree) { - // spinChart.options.rotation = target_degree spinChart.update() text.innerHTML = `
Gruppe nummer ${target.value} skal præsentere!
`; clearInterval(rotationInterval); spinBtn.disabled = false; + } else if (target.minDegree + 1 > 360-spinChart.options.rotation) { + spinAmount = 0; + console.log("halting"); } }