how to send x and y position to pure data
in
Contributed Library Questions
•
3 years ago
I am extremely new to processing but have used OSC on several projects before. I seem to be struggling to understand how to send the x and y positions to pure data.
So far I have managed to get pure data and processing to talk to each other. I know that the message needs to be sent in the void draw part of the code and the OscP5 needs to be told which message to pass on.
Should I be asking for
for (int y = 0; y < video.height; y++) {
for (int x = 0; x < video.width; x++) {
to be sent ......
please can anyone help in my confusion..I realise this is a bit like trying to spell before learning the alphabet...but i really cant contain my excitement at being able to achieve this
thanks
import oscP5.*;
import netP5.*;
import processing.video.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
Capture video;
void setup() {
size(640, 480);
video = new Capture(this, width, height, 30);
noStroke();
smooth();
oscP5 = new OscP5(this,40000);
myRemoteLocation = new NetAddress("127.0.0.1",12000);
}
void draw() {
if (video.available()) {
video.read();
image(video, 0, 0, width, height);
int brightestX = 0;
int brightestY = 0;
float brightestValue = 0; //
I was thinking my OSCp5 message may need to go here using int brightestX and Y as the send message
video.loadPixels();
int index = 0;
for (int y = 0; y < video.height; y++) {
for (int x = 0; x < video.width; x++) {
// Get the color stored in the pixel
int pixelValue = video.pixels[index];
float pixelBrightness = brightness(pixelValue);
if (pixelBrightness > brightestValue) {
brightestValue = pixelBrightness;
brightestY = y;
brightestX = x;
}
index++;
}
}
fill(255, 204, 0, 128);
ellipse(brightestX, brightestY, 200, 200);
}
}
this is where i seem to be confused
OscMessage myMessage = new OscMessage("/test");
myMessage.add(new int[] {brightnesX});
oscP5.send(myMessage, myRemoteLocation);
}
3