http://wiki.roberttwomey.com/index.php?title=Dance_in_the_Dark.pde&feed=atom&action=history
Dance in the Dark.pde - Revision history
2024-03-29T06:15:30Z
Revision history for this page on the wiki
MediaWiki 1.27.1
http://wiki.roberttwomey.com/index.php?title=Dance_in_the_Dark.pde&diff=4040&oldid=prev
Elenyui: New page: //Dance in the Dark import processing.video.*; Capture video; PGraphics buffer; PImage img; int brightestX = 0; // X-coordinate of the brightest video pixel int brightestY = 0; // Y-coor...
2010-06-05T23:13:44Z
<p>New page: //Dance in the Dark import processing.video.*; Capture video; PGraphics buffer; PImage img; int brightestX = 0; // X-coordinate of the brightest video pixel int brightestY = 0; // Y-coor...</p>
<p><b>New page</b></p><div>//Dance in the Dark<br />
<br />
import processing.video.*;<br />
Capture video;<br />
PGraphics buffer;<br />
PImage img;<br />
<br />
int brightestX = 0; // X-coordinate of the brightest video pixel<br />
int brightestY = 0; // Y-coordinate of the brightest video pixel<br />
int lastX, lastY;<br />
<br />
int currentFrame = 0; <br />
PImage[] frames = new PImage[12]; <br />
int lastTime = 0; <br />
<br />
<br />
<br />
<br />
void setup() <br />
{ <br />
size(700, 500, P3D); <br />
video = new Capture(this, width, height, 30);<br />
noStroke(); <br />
smooth(); <br />
buffer = createGraphics(700, 500, P3D);<br />
<br />
background(102); <br />
<br />
for (int i = 0; i < frames.length; i++) { <br />
frames[i] = get(); // Create a blank frame <br />
} <br />
<br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
void draw() <br />
{ <br />
background(0);<br />
<br />
int currentTime = millis(); <br />
if (currentTime > lastTime+30) { <br />
<br />
lastTime = currentTime; //Setting the refresh rate of the recording<br />
}<br />
<br />
//replaces mousepressing line drawing<br />
if (video.available()) {<br />
int threshold = 1; <br />
video.read();<br />
image(video, 0, 0, width, height); // Draw the webcam video onto the screen<br />
<br />
img=buffer.get();<br />
image(buffer, 0, 0, 700, 500); // RDT: draw the offscreen buffer on top of the webcam video<br />
nextFrame(); <br />
<br />
//filter(BLUR, 2);<br />
float brightestValue = 0; // Brightness of the brightest video pixel<br />
// Search for the brightest pixel: For each row of pixels in the video image and<br />
// for each pixel in the yth row, compute each pixel's index in the video<br />
video.loadPixels();<br />
int index = 0;<br />
<br />
<br />
<br />
lastX = brightestX;<br />
lastY = brightestY;<br />
<br />
for (int y = 0; y < video.height; y++) {<br />
for (int x = 0; x < video.width; x++) {<br />
// Get the color stored in the pixel<br />
int pixelValue = video.pixels[index];<br />
// Determine the brightness of the pixel<br />
float pixelBrightness = brightness(pixelValue);<br />
// If that value is brighter than any previous, then store the<br />
// brightness of that pixel, as well as its (x,y) location<br />
if (pixelBrightness > brightestValue) {<br />
brightestValue = pixelBrightness;<br />
brightestY = y;<br />
brightestX = x;<br />
}<br />
index++;<br />
}<br />
} <br />
<br />
<br />
//fill(255, 100, 50, 70);<br />
if (brightestValue > threshold) { // If the test location is brighter than<br />
noStroke();<br />
//fill (255);<br />
// the threshold set the fill to black<br />
<br />
variableEllipse(lastX, lastY, brightestX, brightestY); <br />
nextFrame();<br />
} <br />
else { // Otherwise,<br />
noStroke();<br />
//fill(255,0); // set the fill to random<br />
variableEllipse(lastX, lastY, brightestX, brightestY); <br />
nextFrame();<br />
}<br />
<br />
}<br />
<br />
} <br />
<br />
void nextFrame() <br />
{ <br />
frames[currentFrame] = buffer.get(); // Get the display window <br />
currentFrame++; // Increment to next frame <br />
if (currentFrame >= frames.length) { <br />
currentFrame = 0; <br />
} <br />
image(frames[currentFrame], 0, 0); <br />
} <br />
<br />
<br />
<br />
void variableEllipse(int x, int y, int px, int py) <br />
{<br />
float speed = abs(x-px) + abs(y-py);<br />
<br />
stroke(speed);<br />
<br />
// RDT: draw to the offscreen buffer<br />
buffer.beginDraw();<br />
buffer.noStroke();<br />
buffer.fill(random(0,255), random(0,255), random(0,255), 160);<br />
buffer.ellipse(px, py, speed/4, speed/4);<br />
buffer.endDraw();<br />
<br />
}<br />
<br />
if mouseClicked(){<br />
setup();<br />
}</div>
Elenyui