-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathScript01.js
More file actions
30 lines (26 loc) · 832 Bytes
/
Copy pathScript01.js
File metadata and controls
30 lines (26 loc) · 832 Bytes
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
// 1. Init Editor (Monaco shown)
require(['vs/editor/editor.main'], () => {
window.editor = monaco.editor.create(document.getElementById('editor'), {
language: 'javascript',
theme: 'vs-dark'
});
});
// 2. Run button handler
document.getElementById('runBtn').onclick = () => {
const code = editor.getValue();
runSketch(code);
};
// 3. Fix button handler
document.getElementById('fixBtn').onclick = async () => {
const fixed = await fixCode(editor.getValue());
editor.setValue(fixed);
};
// 4. runSketch: teardown + instantiate p5
function runSketch(code) {
// Remove existing canvas & script
document.getElementById('canvas').innerHTML = '';
const sketch = new Function('p', code);
new p5(sketch, 'canvas');
}
// 5. fixCode: uses your chosen LM runtime
async function fixCode(src) { /* see above */ }