xxxxxxxxxx
30
let fps = 30;
let capturer = new CCapture({ format: 'png', framerate: fps });
function setup() {
createCanvas(400, 400);
frameRate(fps); //set frameRate to match the CCapturer instance
}
function draw() {
if (frameCount === 1) {
// Start capturer on the first frame
capturer.start();
}
// Write your sketch
background(220);
let x = noise(frameCount*0.01)*width;
let y = height / 2;
circle(x,y,100);
// Save the current frame with CCapture
capturer.capture(document.getElementById('defaultCanvas0'));
// Stop and save the capture after a certain frame
if (frameCount > 300) { //record 10 seconds
capturer.stop();
capturer.save();
noLoop();
}
}