diff --git a/script.js b/script.js index 6252905..dcccbe5 100644 --- a/script.js +++ b/script.js @@ -56,7 +56,29 @@ function resetGrid() { } +function rotateKnob(e) { + const knobBounds = rangeKnob.getBoundingClientRect(); + const knobCenter = { + x: knobBounds.left + knobBounds.width/2, + y: knobBounds.top + knobBounds.height/2 + }; + let angle = Math.atan2(e.pageX - knobCenter.x, - (e.pageY - knobCenter.y) )*(180 / Math.PI); + const degrees = angle * (180 / Math.PI); + const sliderValue = Math.round((degrees / 360) * (rangeKnob.max - rangeKnob.min) + parseFloat(rangeKnob.min)); + + rangeKnob.style.transform = `rotate(${angle}deg)`; + rangeKnob.value = sliderValue; +} + + function getGridDimensions() { + const min = gridSlider.min; + const max = gridSlider.max; + const value = gridSlider.value; + const percentage = ((value - min) / (max - min)) * 100; + + rangeKnob.style.transform = `rotate(${percentage}deg)`; + numGrid = gridSlider.value; while (container.firstChild) { @@ -98,18 +120,6 @@ function createGrid() { } -function rotateKnob(e) { - const knobBounds = rangeKnob.getBoundingClientRect(); - const knobCenter = { - x: knobBounds.left + knobBounds.width/2, - y: knobBounds.top + knobBounds.height/2 - }; - let angle = Math.atan2(e.pageX - knobCenter.x, - (e.pageY - knobCenter.y) )*(180 / Math.PI); - - rangeKnob.style.transform = `rotate(${angle}deg)`; -} - - function toggleGridView(gridItem) { if (gridItem.classList.contains("grid-on")){ gridItem.classList.remove("grid-on");