| 170 | } |
| 171 | |
| 172 | function updateEquation() { |
| 173 | try { |
| 174 | state.fn = new MathParser(eqnInput.value).parseExpression(); |
| 175 | state.points = []; |
| 176 | for (let i = 0; i <= 500; i++) { |
| 177 | let x = i * (state.viewport.xMax / 500); |
| 178 | state.points.push({ x, y: state.fn(x) }); |
| 179 | } |
| 180 | document.getElementById("errorMsg").style.display = "none"; |
| 181 | |
| 182 | // Auto-pause scan if equation is changed to prevent weird behavior |
| 183 | state.isScanning = false; |
| 184 | playBtn.innerText = "Play"; |
| 185 | } catch (e) { |
| 186 | document.getElementById("errorMsg").style.display = "block"; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | function resize() { |
| 191 | const dpr = window.devicePixelRatio || 1; |