-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch_04.js
60 lines (49 loc) · 1.22 KB
/
sketch_04.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Create a bunch of circles highlighting their intersections
// Set up recording
let chunks = [];
let frameCount = 0;
let recorder = 0;
function exportVideo(e) {
var blob = new Blob(chunks, { type: 'video/mp4' });
var vid = document.createElement('video');
vid.id = 'recorded'
vid.controls = true;
vid.src = URL.createObjectURL(blob);
document.body.appendChild(vid);
vid.play();
}
function setup() {
// Create the canvas
createCanvas(512, 512);
// Black Background
background(0);
// Set to HSB
colorMode(HSB);
// Set Up Recording (high quality)
chunks.length = 0;
let stream = document.querySelector('canvas').captureStream(30)
recorder = new MediaRecorder(stream, { mimeType: 'video/webm;codecs=vp8,opus' });
recorder.ondataavailable = e => {
if (e.data.size) {
chunks.push(e.data);
}
};
recorder.onstop = exportVideo;
// Start Recording
recorder.start();
}
function draw() {
// End if we've done 50 circles
if (frameCount > 150) {
noLoop();
recorder.stop();
return;
}
// Draw a circle
stroke(255);
strokeWeight(1);
hue = int(random(0, 25))*10
fill(hue, 100, 100, 0.5);
circle(random(0, width), random(0, height), random(0, 100));
frameCount += 1;
}