Examples
From the p5.videomotion documentation
These 15 sketches each show one part of p5.videomotion. Every page runs the sketch live
and lists its full source. All of them use the webcam except Without a camera.
The examples load p5.js from a CDN, and browsers only give pages camera access over https:// or
http://localhost. Serve this folder with a local web server (see Installation)
rather than opening the files directly.
Basics
| Example | Description |
| Starter | The smallest useful sketch: webcam, adaptive background, two zones and the debug overlay. |
| Without a camera | Uses a p5.Graphics with moving shapes as the source. Useful for testing and for sketches where the input is generated or loaded rather than filmed. |
| Instance mode | The same starter written in p5 instance mode. createMotion is available on the instance as p.createMotion. |
| Camera in part of the canvas | Draws the camera into a smaller frame and uses mapTo() so zones and blobs stay in canvas pixels that line up with it. |
Zones
| Example | Description |
| Zone pads | Four zones along the top of the screen act like buttons. Each one flashes and counts when motion enters it. |
| Zone meter and threshold | Shows a zone's amount as a live meter next to its threshold. Press UP and DOWN to change the threshold and see when the zone switches. |
| Direction inside zones | A grid of zones, each drawing an arrow for the average direction of movement inside it (zone.flow). |
Blobs
| Example | Description |
| Drawing blobs | Draws each blob's convex hull, centre of mass, id and velocity yourself instead of using debug(). |
| Blob trails and events | Keeps a trail for each blob by its id, using onBlobEnter and onBlobExit to create and clean up the trails. |
Optical flow
| Example | Description |
| Flow field | Draws every vector of the optical flow grid with forEachFlow(), coloured by direction. |
| Flow particles | 1,500 particles pushed around by motion.flowAt(). Wave your hands to sweep them. |
| Swipe gestures | Detects left, right, up and down swipes from averageFlow(), with a short cooldown so one gesture fires once. |
Background and mask
| Example | Description |
| Background modes | Camera on the left, motion mask on the right. Switch modes with 1 (adaptive), 2 (static) and 3 (frame), relearn with SPACE, and change the threshold with + and -. |
| Mask ghosts | Uses motion.mask as an image: moving areas are added onto a slowly fading canvas, leaving ghost trails. |
| Example | Description |
| Resolution and manual updates | Turns off autoUpdate, times each motion.update() call and lets you change the processing resolution with a slider. |