ScribblePerson

ScribblePerson_第1张图片
scribble person
import processing.video.*;

// Two global variables
float x;
float y;
Capture video;

void setup() {
  size(320, 240);
  smooth();
  background(255);
  video=new Capture(this, 320, 240, 15);
  video.start();

  // Start x and y in the center
  x = width/2;
  y = height/2;
}
void draw() {
  if (video.available()) {
    video.read();
  }
  video.loadPixels();

  // 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);
  int loc=(midy+1)*video.width-midx-1;
  color c=video.pixels[loc];
  
  // Draw a line from x,y to the newx,newy
  stroke(c);
  strokeWeight(4);
  line(x, y, newx, newy);
  // Save newx, newy in x,y
  x = newx;
  y = newy;
}

你可能感兴趣的:(ScribblePerson)