Untitled

 avatar
unknown
plain_text
2 years ago
1.7 kB
5
Indexable
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Home Run Derby</title>
    <style>
        body {
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100vh;
            margin: 0;
        }

        #pitcher {
            position: relative;
            width: 200px;
            height: 200px;
            background-color: #48a832;
            border-radius: 50%;
        }

        #ball {
            position: absolute;
            width: 20px;
            height: 20px;
            background-color: #ff4500;
            border-radius: 50%;
            transition: transform 0.5s ease;
        }
    </style>
</head>
<body>
    <div id="pitcher">
        <div id="ball"></div>
    </div>

    <script>
        const pitcher = document.getElementById('pitcher');
        const ball = document.getElementById('ball');

        ball.addEventListener('click', () => {
            hitBall();
        });

        function hitBall() {
            const randomAngle = Math.random() * 360;
            const randomDistance = Math.random() * 100 + 150;

            const x = randomDistance * Math.cos(randomAngle * (Math.PI / 180));
            const y = randomDistance * Math.sin(randomAngle * (Math.PI / 180));

            ball.style.transform = `translate(${x}px, ${y}px)`;

            setTimeout(() => {
                resetBall();
            }, 500);
        }

        function resetBall() {
            ball.style.transform = 'translate(0, 0)';
        }
    </script>
</body>
</html>
Editor is loading...
Leave a Comment