Skip to content

capture recorduntil

WenheLI edited this page Dec 4, 2018 · 1 revision

Capture Class

Manual

capture.startUntil(config)

An anchor setting to automatically stop recording when some circumstance meets.

startUntil Config

// IMPORTANT: only ONE attribute can appear 
var config = {
    frame: Integer,
    milliSecond: Integer,
    second: Integer,
    minute: Integer
};
// IMPORTANT: only ONE attribute can appear 

// if you want to set 1'30''
// we recommand you to use { second: 90 }

recorder = p5Gif.capture(config);

Example

var gif = null;
var recorder = null;

function callback(recorder) {
    recorder.finish(function (myGif) { // finish recording, a p5gif instance will be returned in the callback
        gif = myGif; // save the instance
        gif.download(); // download the gif
    });
}

function setup() {
    createCanvas(400, 400);

    p5Gif.capture().recorduntil({ frame: 10 }, callback);
    // Or p5Gif.capture().recorduntil({ milliSecond: 500 }, callback);
    // Or p5Gif.capture().recorduntil({ second: 3 }, callback);
    
}

function draw() {
    background(220);

    // an example in p5js official website to draw rotating shapes
    push();
    translate(width * 0.5, height * 0.5);
    rotate(frameCount / 200.0);
    polygon(0, 0, 100, 3);
    pop();
}

// an example in p5js official website to draw rotating shapes
function polygon(x, y, radius, npoints) {
    var angle = TWO_PI / npoints;
    beginShape();
    for (var a = 0; a < TWO_PI; a += angle) {
        var sx = x + cos(a) * radius;
        var sy = y + sin(a) * radius;
        vertex(sx, sy);
    }
    endShape(CLOSE);
}

Cheers

NHibiki

Clone this wiki locally