/* This program looks at the camera and analyzes the average brightness of the red channel. If the frame average drops below the average of the last few frames, it will draw a smaller circle, indicating a contracting heart. To use, cover the camera with the tip of your thumb and shine a bright flashlight on the other side. It will calibrate itself with averaging. */ import processing.video.*; Capture video; int numPixels; int navg = 10; int[] redavg = new int[navg]; int avgptr = 0; void setup() { size(640, 480); video = new Capture(this, width, height, 15); numPixels = video.width * video.height; // Create an array to store the previously captured frame } void draw() { if (video.available()) { // When using video to manipulate the screen, use video.available() and // video.read() inside the draw() method so that it's safe to draw to the screen video.read(); // Read the new frame from the camera video.loadPixels(); // Make its pixels[] array available image(video, 0, 0); int redsum =0; for (int i = 0; i < numPixels; i++) { // For each pixel in the video frame... color currColor = video.pixels[i]; int currR = (currColor >> 16) & 0xFF; redsum += currR; } int frameavg = redsum/numPixels; redavg[avgptr] = frameavg; avgptr++; if(avgptr >= navg) avgptr=0; int p =0; for(int x=0; x