1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
/*
* Traqueur de luminosité
*/
import processing.video.*;
import processing.sound.*;
SinOsc sine;
int bx;
int by;
float d;
float freq=400;
float amp=0.5;
float pos;
Capture video;
void setup() {
size(640, 480);
video = new Capture(this, width, height);
video.start();
noStroke();
smooth();
sine = new SinOsc(this);
//Start the Sine Oscillator.
sine.play();
}
void draw() {
if (video.available()) {
video.read();
image(video, 0, 0, width, height);
int brightestX = 0;
int brightestY = 0;
float brightestValue = 0;
video.loadPixels();
int index = 0;
for (int y = 0; y < video.height; y++) {
for (int x = 0; x < video.width; x++) {
int pixelValue = video.pixels[index];
float pixelBrightness = brightness(pixelValue);
if (pixelBrightness > brightestValue) {
brightestValue = pixelBrightness;
brightestY = y;
brightestX = x;
}
index++;
}
}
fill(255, 0, 0, 128);
ellipse(brightestX, brightestY, 10, 10);
fill(0, 0, 0, 128);
ellipse(290, 295, 10, 10);
if (brightestX > 290) {
bx = brightestX - 290;
fill(0);
text("X = : " + bx, 10, 20);
} else {
bx = 290 - brightestX;
fill(0);
text("X = : " + bx, 10, 20);
}
if (brightestY > 295) {
by = brightestX - 295;
fill(0);
text("Y = : " + by, 10, 40);
} else {
by = 295 - brightestY;
fill(0);
text("X = : " + by, 10, 40);
}
amp=map(100, 0, height, 1.0, 0.0);
sine.amp(amp);
d= sqrt((bx*bx)+(by*by));
fill(0);
text("distance = : " + d, 10, 60);
freq=map((400-d)*2, 0, width, 80.0, 1000.0);
sine.freq(freq);
}
} |
Partager