Hello processing community.
My name is jules, design student, and I'm working on a code to translate live video from the webcam into sounds.
I'm taking out one pixel every 24 pixels that is then displayed bigger (and round) and is picked to be translated into a sine wave. I want this one selected pixel to appear bigger(let's say twice the scale), and then decrease its size slowly until it gets the same size as all the other squares. I'm doing this in order to display clearly where the sound is coming from/ highlight this part of the image for the moment it's played. The problem I face here is that the animation of the change of scale would take place while the normal loop of the draw is still running. And I don't know how to deal with that.
Thanks for reading
import processing.video.*;
import ddf.minim.*;
import ddf.minim.ugens.*;
Minim minim;
AudioOutput out;
Oscil wave;
Capture cam;
int pointillize = 30;
int Lx[] = {1, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300};
int Ly[] = {1, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220};
int i = 0;
void setup() {
size(1200, 1200);
cam = new Capture(this, 320, 240, 30);
cam.start();
background(0);
rectMode(CENTER);
smooth();
// initialize the minim and out objects
minim = new Minim(this);
out = minim.getLineOut();
wave = new Oscil( 440, 0.6f, Waves.SINE );
wave.patch( out );
}
void draw() {
cam.read();
int x = Lx[ (int) random(Lx.length) ];
int y = Ly[ (int) random(Ly.length) ];
int loc = x + y*cam.width;
// Look up the RGB color in the source image
loadPixels();
float r = red(cam.pixels[loc]);
float g = green(cam.pixels[loc]);
float b = blue(cam.pixels[loc]);
noStroke();
// Draw an ellipse at that location with that color
i = i + 1;
fill(r,g,b,255);
if (i == 24){
ellipse(((x+150)*2),((y+150)*2),pointillize+20,pointillize+20);
i = 0;
//getting the wavelengh = lwave
color c = color(r,g,b);
float lwave = ((hue(c))*400/360)+380;
//getting the related frequency= swave
//octave 350_718Hz
float swave = 300000000/lwave*1000000000/1099511627776L;
//play sound of it
wave.setFrequency( swave );
} else {
rect(((x+150)*2),((y+150)*2),pointillize,pointillize);
}
// bpm
delay(5);
}
Also, another question : The code runs quite slow, I putted the delay at (1) but still, I would like to have it faster. Does anyone knows why ?