diff --git a/group_numbers.js b/group_numbers.js index 76f057f..368ea87 100644 --- a/group_numbers.js +++ b/group_numbers.js @@ -1,4 +1,4 @@ -const display = [6,7,8,9] +const display = [5, 6,7,8,9, 10] const not_pickable = [ - 6, + 6,7,8 ] \ No newline at end of file diff --git a/script.js b/script.js index 54fab67..a17ad29 100644 --- a/script.js +++ b/script.js @@ -79,20 +79,31 @@ console.log(spinChart.options.rotation); /* --------------- Spinning Code --------------------- */ spinBtn.addEventListener("click", () => { - let spinAmount = 101; + let spinAmount = 61; spinBtn.disabled = true; text.innerHTML = `
Held og lykke!
`; - + let slowing_down = false; let pickable = spinValues.filter(item => !not_pickable.includes(item.value)) let target = pickable[Math.floor(Math.random() * pickable.length)] - target_degree = Math.floor(Math.random() * (target.maxDegree - target.minDegree - 10)) + let target_index = spinValues.findIndex(item => item.value === target.value); + target_degree = Math.floor(Math.random() * (target.maxDegree - target.minDegree - 5)) + //slowing_down_degree = Math.floor(0.5 * (spinValues[target_index + 1].maxDegree - spinValues[target_index + 1].minDegree)) + console.log(spinValues[target_index]); + //console.log(spinValues[target_index + 1]); + + let slowing_down_target = spinValues[target_index + 1]; + console.log(target) let rotationInterval = window.setInterval(() => { - spinAmount *= 0.98 - spinAmount = Math.max(1, spinAmount) + spinAmount *= 0.99 + if (slowing_down) { + spinAmount = Math.max(0.1, spinAmount) + } else { + spinAmount = Math.max(2.5, spinAmount) + } spinChart.options.rotation += spinAmount; spinChart.update(); @@ -100,14 +111,23 @@ 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) { + console.log(spinAmount + " Decreasing more") + slowing_down = true; + spinAmount *= 0.8 + + + 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; + } - if (spinAmount <= 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; } + + }, 10); }); /* --------------- End Spin Wheel --------------------- */