-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
40 lines (35 loc) · 1.11 KB
/
sketch.js
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
const canvasSketch = require('canvas-sketch');
const glslsketch = require('./glslsketch');
const webglSketch = require('./webgl-sketch');
const webglSketch2 = require('./webgl-sketch2');
const gradientSketch = require('./gradient-sketch');
const pixelSketch = require('./pixel-sketch');
const canvasInCanvas = require('./canvas-in-canvas');
var sketches = [
canvasInCanvas,
gradientSketch,
pixelSketch,
webglSketch,
webglSketch2
];
var currSketchIndex = 0;
var manager = null;
canvasSketch(sketches[currSketchIndex].sketch, sketches[currSketchIndex].settings).then((x) => {
manager = x;
});
document.onkeydown = checkKey;
function checkKey(e) {
e = e || window.event;
if (e.keyCode == '37') {
currSketchIndex = (currSketchIndex - 1) % sketches.length;
updateSketch(sketches[currSketchIndex]);
}
else if (e.keyCode == '39') {
currSketchIndex = (currSketchIndex +1) % sketches.length;
updateSketch(sketches[currSketchIndex]);
}
}
async function updateSketch(sketch) {
manager.destroy();
manager = await canvasSketch(sketch.sketch, sketch.settings);
}