forked from CodingTrain/12oclocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
39 lines (37 loc) · 1.04 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
window.addEventListener('load', function() {
var clocks = new Array(12).fill(0).map(function(_, i) {
i++;
if (i < 10) {
i = "0" + i
} else {
i = "" + i;
}
return {
container: document.getElementById("clock-" + i),
fn: window["clock" + i]
}
});
clocks.forEach(function(data) {
data.p5 = new p5(function(sketch) {
// Original sketch
data.fn(sketch);
// Override setup
var old_setup = sketch.setup || function() {};
sketch.setup = function() {
// Grab canvas element
data.canvas = sketch.createCanvas(100, 100).elt;
sketch.resize();
old_setup.apply(this, arguments);
}
sketch.resize = function() {
var container = data.canvas.getBoundingClientRect();
sketch.resizeCanvas(container.width, container.height, false);
}
// Override resize
var old_resize = sketch.windowResized || function() {};
sketch.windowResized = function() {
sketch.resize();
}
}, data.container);
});
});