CODE FOR PLAYING GUITAR

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Interactive Guitar</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            font-family: 'Arial', sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background: linear-gradient(to right, #4ca1af, #c4e0e5);
        }
        .guitar-container {
            position: relative;
            width: 300px;
            height: 600px;
            background: linear-gradient(135deg, #8B4513, #A0522D);
            border-radius: 25px;
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
            padding: 20px;
            overflow: hidden;
        }
        .head {
            width: 100px;
            height: 30px;
            background: #8B4513;
            border-radius: 10px;
            position: absolute;
            top: -30px;
            left: 100px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
        }
        .guitar-string {
            position: absolute;
            width: 2px;
            height: 100%;
            background-color: white;
            left: 50%;
            transform: translateX(-50%);
            animation: strum 0.3s ease-in-out forwards;
        }
        .guitar-string:nth-child(1) { left: 20%; }
        .guitar-string:nth-child(2) { left: 30%; }
        .guitar-string:nth-child(3) { left: 40%; }
        .guitar-string:nth-child(4) { left: 60%; }
        .guitar-string:nth-child(5) { left: 70%; }
        .guitar-string:nth-child(6) { left: 80%; }

        @keyframes strum {
            0% { transform: translateX(-50%) scaleX(1); }
            50% { transform: translateX(-50%) scaleX(1.2); }
            100% { transform: translateX(-50%) scaleX(1); }
        }

        .strum-animation {
            animation: strum 0.5s forwards;
        }
        .button-play {
            position: absolute;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            background-color: #FF6347;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
        .button-play:hover {
            background-color: #FF4500;
        }
    </style>
</head>
<body>

    <div class="guitar-container">
        <div class="head"></div>
        <div class="guitar-string" data-note="E"></div>
        <div class="guitar-string" data-note="A"></div>
        <div class="guitar-string" data-note="D"></div>
        <div class="guitar-string" data-note="G"></div>
        <div class="guitar-string" data-note="B"></div>
        <div class="guitar-string" data-note="E2"></div>
        <button class="button-play">Play All Strings</button>
    </div>

    <script>
        // Sound mapping for each string
        const sounds = {
            E: new Audio('https://www.soundjay.com/button/sounds/button-10.mp3'),
            A: new Audio('https://www.soundjay.com/button/sounds/button-09.mp3'),
            D: new Audio('https://www.soundjay.com/button/sounds/button-08.mp3'),
            G: new Audio('https://www.soundjay.com/button/sounds/button-07.mp3'),
            B: new Audio('https://www.soundjay.com/button/sounds/button-06.mp3'),
            E2: new Audio('https://www.soundjay.com/button/sounds/button-05.mp3'),
        };

        // Play individual string sound
        document.querySelectorAll('.guitar-string').forEach((string) => {
            string.addEventListener('click', () => {
                const note = string.getAttribute('data-note');
                sounds[note].currentTime = 0;
                sounds[note].play();
                string.classList.add('strum-animation');
                setTimeout(() => string.classList.remove('strum-animation'), 500);
            });
        });

        // Play all strings
        document.querySelector('.button-play').addEventListener('click', () => {
            let delay = 0;
            document.querySelectorAll('.guitar-string').forEach((string, index) => {
                setTimeout(() => {
                    const note = string.getAttribute('data-note');
                    sounds[note].currentTime = 0;
                    sounds[note].play();
                    string.classList.add('strum-animation');
                    setTimeout(() => string.classList.remove('strum-animation'), 500);
                }, delay);
                delay += 300; // Delay between string sounds
            });
        });
    </script>

</body>
</html>
HTML

Leave a Reply

Your email address will not be published. Required fields are marked *

Resize text
Scroll to Top