Instance mode
p5.videomotion example
Part of the p5.videomotion examples · Category: Basics
The same starter written in p5 instance mode. createMotion is available on the instance as p.createMotion.
Live sketch. Allow camera access when the browser asks. If nothing appears, see Troubleshooting.
Source code
Save as sketch.js next to an index.html that loads p5.js and p5.videomotion.js (see Installation).
// Instance mode: everything hangs off the p5 instance "p".
new p5(p => {
let cam, motion;
p.setup = () => {
p.createCanvas(640, 480);
cam = p.createCapture(p.VIDEO, { flipped: true });
cam.hide();
motion = p.createMotion(cam);
motion.zone('left', 40, 140, 160, 200);
motion.zone('right', 440, 140, 160, 200);
};
p.draw = () => {
p.image(cam, 0, 0, p.width, p.height);
motion.debug();
};
});
Used in this example
← Without a camera · All examples · Camera in part of the canvas →