Identifying white pixels.
in
Core Library Questions
•
2 years ago
Hey all,
I'm creating a project using a web cam in which the background is white, and movement that is detected is drawn as dark shapes. What I'm trying to do is generate audio when there are less white pixels on the screen (or more black pixels / movement). I've implemented an example from Processing which generates audio based on mouse location, but I was wondering how to map this audio to white pixels rather than mouse location, so that audio generates when there are less white pixels on screen.
Thanks for the help, and here's the example code (which I tweaked slightly):
EDIT: This is only the class code. If you wish to see the main code as well, which includes the setup() and draw() variables, I'd be happy to post that as well :)
- // this signal uses the mouseX and mouseY position to build a signal
- class Noise implements AudioSignal
- {
- void generate(float[] samp)
- {
- float range = map(mouseX, 0, width, 0, 1);
- float peaks = map(mouseY, 0, height, 1, 20);
- float inter = float(samp.length) / peaks;
- for ( int i = 0; i < samp.length; i += inter )
- {
- for ( int j = 0; j < inter && (i+j) < samp.length; j++ )
- {
- samp[i + j] = map(j, 0, inter, -range, range);
- }
- }
- }
- // this is a stricly mono signal
- void generate(float[] left, float[] right)
- {
- generate(left);
- generate(right);
- }
- }
1