File size: 5,628 Bytes
1885d21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cd88ef3
1885d21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Tempo Estimator</title>
    <!-- Bootstrap CSS -->
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
    <style>
        :root {
            --bg-color-light: #f0f0f0;
            --text-color-light: #000;
            --bg-color-dark: #2c2c2c;
            --text-color-dark: #fff;
        }
        body {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            margin: 0;
            font-family: 'Roboto', sans-serif;
            transition: background-color 0.3s, color 0.3s;
            text-align: center;
        }
        body.light-mode {
            background-color: var(--bg-color-light);
            color: var(--text-color-light);
        }
        body.dark-mode {
            background-color: var(--bg-color-dark);
            color: var(--text-color-dark);
        }
        .btn-custom {
            padding: 30px 60px;
            font-size: 36px;
            margin: 10px;
            border-radius: 50px;
            position: relative;
        }
        .btn-reset {
            padding: 15px 30px;
            font-size: 18px;
            margin: 10px;
            border-radius: 50px;
            position: relative;
        }
        #tempoDisplay {
            font-size: 36px;
            margin-bottom: 20px;
        }
        .toggle-button {
            display: flex;
            align-items: center;
            cursor: pointer;
            margin-top: 20px;
        }
        .toggle-button input {
            display: none;
        }
        .toggle-label {
            display: flex;
            align-items: center;
            background-color: #ccc;
            border-radius: 50px;
            padding: 5px;
            width: 40px;
            justify-content: space-between;
            position: relative;
        }
        .toggle-label .ball {
            background-color: #fff;
            border-radius: 50%;
            width: 20px;
            height: 20px;
            position: absolute;
            left: 0;
            transition: transform 0.3s;
        }
        input:checked + .toggle-label .ball {
            transform: translateX(20px);
        }
        .sparkle {
            position: absolute;
            width: 20px;
            height: 20px;
            background: orange;
            border-radius: 50%;
            animation: sparkle 0.5s ease-out;
        }
        @keyframes sparkle {
            from {
                transform: scale(0);
                opacity: 1;
            }
            to {
                transform: scale(1.5);
                opacity: 0;
            }
        }
    </style>
</head>
<body class="light-mode">
    <div id="tempoDisplay">-- BPM</div>
    <button id="tapButton" class="btn btn-primary btn-custom">Tap</button>
    <button id="resetButton" class="btn btn-secondary btn-reset">Reset</button>
    <div class="toggle-button">
        <input type="checkbox" id="modeToggle">
        <label for="modeToggle" class="toggle-label">
            <div class="ball"></div>
        </label>
    </div>

    <script>
        let tapTimes = [];

        document.getElementById('tapButton').addEventListener('click', (e) => {
            const currentTime = new Date().getTime();
            tapTimes.push(currentTime);

            if (tapTimes.length > 1) {
                const timeIntervals = [];
                for (let i = 1; i < tapTimes.length; i++) {
                    timeIntervals.push(tapTimes[i] - tapTimes[i - 1]);
                }

                const averageInterval = timeIntervals.reduce((a, b) => a + b) / timeIntervals.length;
                const tempo = Math.round(60000 / averageInterval);

                document.getElementById('tempoDisplay').innerText = `${tempo} BPM`;
            }

            if (tapTimes.length > 10) {
                tapTimes.shift();
            }

            // Sparkle effect
            const sparkle = document.createElement('div');
            sparkle.className = 'sparkle';
            sparkle.style.left = `${e.clientX - e.target.offsetLeft - 10}px`;
            sparkle.style.top = `${e.clientY - e.target.offsetTop - 10}px`;
            e.target.appendChild(sparkle);

            setTimeout(() => {
                sparkle.remove();
            }, 500);
        });

        document.getElementById('resetButton').addEventListener('click', () => {
            tapTimes = [];
            document.getElementById('tempoDisplay').innerText = '-- BPM';
        });

        document.getElementById('modeToggle').addEventListener('change', () => {
            const body = document.body;
            if (body.classList.contains('light-mode')) {
                body.classList.remove('light-mode');
                body.classList.add('dark-mode');
            } else {
                body.classList.remove('dark-mode');
                body.classList.add('light-mode');
            }
        });

        document.addEventListener('keydown', (event) => {
            if (event.key === ' ') {
                document.getElementById('tapButton').click();
            }
        });
    </script>
    <!-- Bootstrap JS and dependencies -->
    <script src="https://code.jquery.com/jquery-3.5.1.s