// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Example 16-10: The scribbler mirror

import processing.video.*;

// Two global variables
float x;
float y;

// Variable to hold onto Capture object
Capture video;

void setup() {
  // Start x and y in the center
  x = width/2;
  y = height/2;
  // Start the capture process
  // If the window were larger (say 800 x 600), we might want to introduce a videoScale variable so that we do not have to capture such a large image.
  video = new Capture(this,width,height,15); 

void draw() {
  // Read image from the camera
  if (video.available()) {
  // Pick a new x and y
  float newx = constrain(x + random(-20,20),0,width-1);
  float newy = constrain(y + random(-20,20),0,height-1);
  // Find the midpoint of the line
  int midx = int((newx + x) / 2);
  int midy = int((newy + y) / 2);
  // Pick the color from the video, reversing x
  color c = video.pixels[(width-1-midx) + midy*video.width];
  // Draw a line from x,y to the newx,newy
  // Save newx, newy in x,y
  x = newx;
  y = newy;
  • Yahya

    An unexpected, and fun, effect – good stuff!

  • Sam Foster

    I’m new at Processing and my class has been assigned to make a piece of generative art. I want to meld this into my final project, but instead of a Movie I want to draw a picture that is taken (via Photobooth or even Processing if possible) very two minutes or so. I think I know how to do everything except import/load a picture. Any help would be greatly appreciated, thanks.