GMU:Processing im Park/Emilio Aguas/sample code test08: Difference between revisions

From Medien Wiki
(Created page with "====--- Processing3.0 Code--- ==== The ball fallow the light <source lang="java"> import processing.video.*; int x, y; Capture cam; void setup () { size (640, 360); fra...")
 
 
Line 1: Line 1:
====--- Processing3.0 Code--- ====
====--- Processing3.0 Code--- ====


The ball fallow the light
The ball follow the light


<source lang="java">
<source lang="java">

Latest revision as of 17:34, 1 April 2016

--- 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);
}