Какая функция мне нужна, чтобы измерить, как далеко пользователь находился от зеленого кармана на рулетке с помощью углов? - PullRequest
0 голосов
/ 18 июня 2020

Это мой код для рулетки. Он вращается и останавливается с помощью кнопки, но мне нужно что-то, чтобы сказать мне, как далеко пользователь был от зеленого кармана после того, как нажал кнопку остановки. Его нужно измерять в углах.

<html>
    <head>
        <body>
            <input type="button" value="START" style="bottom: auto" onClick="spinning()">
            <input type="button" value="STOP" style="bottom: auto" onClick="stop()">
            <p>
                Spin the roulette and try to get it to land on the green pocket as accurately as possible.
            </p>
            <canvas id="newCanvas" width="1000" height="1000"></canvas>
            <script>
                "use strict";
                var a = document.getElementById("newCanvas");
                var c = a.getContext("2d");
                var increaseAngle=0;
                c.beginPath();
                c.arc(200,200,195,0,2*Math.PI);
                c.fillStyle="black"
                c.fill();
                spinning();
                function spinning() {
                    increaseAngle+=0.08;
                    for (var i=0; i<20; i++) {
                        var angleSize=2*Math.PI/20;
                        c.beginPath();
                        c.moveTo(200,200);
                        c.arc(200,200,180, angleSize * i+increaseAngle, angleSize * (i+1)+increaseAngle);
                        c.lineTo(200,200);
                        c.fillStyle="black"
                        c.fill();
                        if (i%2 == 0) {
                            c.fillStyle="red"
                            c.fill();
                        }
                    }
                    if (i%2==0){
                        c.fillStyle="green"
                        c.fill();
                    }
                    angleSize++;
                    pause = window.setTimeout(spinning,17)
                }
                var pause;
                function stop() {
                    clearTimeout(pause);
                }
                //arrow
                c.beginPath();
                c.rect(190,0,25,60);
                c.fillStyle="yellow";
                c.fill();
            </script>
        </body>
    </head>
</html>

Мне просто нужно добавить к этому функцию, которая может измерять расстояние.

...