Removing redundant example, was renamed

This commit is contained in:
Casey Reas
2012-12-07 07:07:27 +00:00
parent e08b7e7804
commit 3090c19859
8 changed files with 5 additions and 183 deletions

View File

@@ -14,9 +14,8 @@ int[] backgroundPixels;
Capture video;
void setup() {
// Change size to 320 x 240 if too slow at 640 x 480
size(640, 480, P2D);
// Uses the default video input, see the reference if this causes an error
video = new Capture(this, width, height);
video.start();
numPixels = video.width * video.height;

View File

@@ -11,7 +11,7 @@ import processing.video.*;
Capture video;
void setup() {
size(640, 480, P2D); // Change size to 320 x 240 if too slow at 640 x 480
size(640, 480, P2D);
// Uses the default video input, see the reference if this causes an error
video = new Capture(this, width, height);
video.start();

View File

@@ -1,144 +0,0 @@
/**
* Disgrand
* by Ben Fry.
*
* Example that sorts all colors from the incoming video
* and arranges them into vertical bars.
*/
import processing.video.*;
Capture video;
boolean cheatScreen;
Tuple[] captureColors;
Tuple[] drawColors;
int[] bright;
// How many pixels to skip in either direction
int increment = 5;
void setup() {
size(800, 600, P2D);
noCursor();
// Uses the default video input, see the reference if this causes an error
video = new Capture(this, 160, 120);
video.start();
int count = (video.width * video.height) / (increment * increment);
bright = new int[count];
captureColors = new Tuple[count];
drawColors = new Tuple[count];
for (int i = 0; i < count; i++) {
captureColors[i] = new Tuple();
drawColors[i] = new Tuple(0.5, 0.5, 0.5);
}
}
void draw() {
if (video.available()) {
video.read();
video.loadPixels();
background(0);
noStroke();
int index = 0;
for (int j = 0; j < video.height; j += increment) {
for (int i = 0; i < video.width; i += increment) {
int pixelColor = video.pixels[j*video.width + i];
int r = (pixelColor >> 16) & 0xff;
int g = (pixelColor >> 8) & 0xff;
int b = pixelColor & 0xff;
// Technically would be sqrt of the following, but no need to do
// sqrt before comparing the elements since we're only ordering
bright[index] = r*r + g*g + b*b;
captureColors[index].set(r, g, b);
index++;
}
}
sort(index, bright, captureColors);
beginShape(QUAD_STRIP);
for (int i = 0; i < index; i++) {
drawColors[i].target(captureColors[i], 0.1);
drawColors[i].phil();
float x = map(i, 0, index, 0, width);
vertex(x, 0);
vertex(x, height);
}
endShape();
if (cheatScreen) {
//image(video, 0, height - video.height);
// Faster method of displaying pixels array on screen
set(0, height - video.height, video);
}
}
}
void keyPressed() {
if (key == 'g') {
saveFrame();
} else if (key == 'c') {
cheatScreen = !cheatScreen;
}
}
// Functions to handle sorting the color data
void sort(int length, int[] a, Tuple[] stuff) {
sortSub(a, stuff, 0, length - 1);
}
void sortSwap(int[] a, Tuple[] stuff, int i, int j) {
int T = a[i];
a[i] = a[j];
a[j] = T;
Tuple v = stuff[i];
stuff[i] = stuff[j];
stuff[j] = v;
}
void sortSub(int[] a, Tuple[] stuff, int lo0, int hi0) {
int lo = lo0;
int hi = hi0;
int mid;
if (hi0 > lo0) {
mid = a[(lo0 + hi0) / 2];
while (lo <= hi) {
while ((lo < hi0) && (a[lo] < mid)) {
++lo;
}
while ((hi > lo0) && (a[hi] > mid)) {
--hi;
}
if (lo <= hi) {
sortSwap(a, stuff, lo, hi);
++lo;
--hi;
}
}
if (lo0 < hi)
sortSub(a, stuff, lo0, hi);
if (lo < hi0)
sortSub(a, stuff, lo, hi0);
}
}

View File

@@ -1,29 +0,0 @@
// Simple vector class that holds an x,y,z position.
class Tuple {
float x, y, z;
Tuple() { }
Tuple(float x, float y, float z) {
set(x, y, z);
}
void set(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
}
void target(Tuple another, float amount) {
float amount1 = 1.0 - amount;
x = x*amount1 + another.x*amount;
y = y*amount1 + another.y*amount;
z = z*amount1 + another.z*amount;
}
void phil() {
fill(x, y, z);
}
}

View File

@@ -13,7 +13,7 @@ int[] previousFrame;
Capture video;
void setup() {
size(640, 480, P2D); // Change size to 320 x 240 if too slow at 640 x 480
size(640, 480, P2D);
// Uses the default video input, see the reference if this causes an error
video = new Capture(this, width, height);
video.start();

View File

@@ -27,7 +27,6 @@ void setup() {
writeRow = height - 1;
topRow = 0;
//frameRate(10);
background(0);
loadPixels();
}
@@ -52,4 +51,4 @@ void draw() {
void captureEvent(Capture c) {
c.read();
}
}

View File

@@ -17,7 +17,7 @@ Capture video;
void setup() {
size(640, 480, P2D);
//set up columns and rows
// Set up columns and rows
cols = width / cellSize;
rows = height / cellSize;
colorMode(RGB, 255, 255, 255, 100);

View File

@@ -6,9 +6,6 @@
* to the video capture height. If you would prefer otherwise,
* consider using the image copy() function rather than the
* direct pixel-accessing approach I have used here.
*
* Created December 2006.
* Updated June 2007 by fry.
*/
import processing.video.*;