GMU:Processing im Park/Emilio Aguas/sample code test08

From Medien Wiki
< GMU:Processing im Park‎ | Emilio Aguas
Revision as of 17:34, 1 April 2016 by EmilioAguas (talk | contribs) (→‎--- Processing3.0 Code---)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

--- Processing3.0 Code---

The ball follow the light

import processing.video.*;
int x, y;


Capture cam;

void setup () {
  size (640, 360);
  frameRate(30);
  background(0);
  cam = new Capture (this, 640, 360, "FaceTime HD Camera (Built-in)", 30);
  cam.start();
  //printArray(Capture.list());
}

void draw() {
  if (cam.available()) {
    cam.read();
    cam.loadPixels();

    float theLight = 0;
    int brightnessPix =0;

    for (int i=0; i<cam.pixels.length; i++) {
      if (brightness(cam.pixels[i]) > theLight) {
        theLight= brightness (cam.pixels[i]);
        brightnessPix = i;
      }
    }
    x = brightnessPix % cam.width; 
    y = brightnessPix / cam.width;
  }
  println (x,y);
  image (cam, 0, 0);
  fill(0, 255, 0);
  ellipse (x, y, 20, 20);
}