I have a method called received that receive udp data and save that into an array. now I want to draw a rectangle using the values on that array . how could I use an array which define in other methods than draw() ?
and consider that the array is always changing because new udp packets are coming so if I draw a rectangle ( rect(bin[0],bin[1]10,20)) the value of bin[0] and bin[1] is always changing . would the rectangle move while the values change ?
or can I use the array in other code too ?
- void setup() {
- size(400, 400);
- udp= new UDP(this, PORT_RX, HOST_IP);
- udp.log(true);
- udp.listen(true);
- super.start();
- }
- void draw() {
- background(0);
- rect(bin[0], bin[1], 5, 10);
- }
- void receive(byte[] data, String HOST_IP, int PORT_RX) {
- int j = 0 ;
- float[] bin = new float[(data.length/2)];
- while (j < data.length ) {
- if ( data[2*j+2] >= 0 ) {
- String unhx =(binary(data[2*j+3])+binary(
data[2*j+2])+binary(data[2*j+ 1])+binary(data[2*j])); - float unbin = ((float)unbinary(unhx)/100);
- bin[j/2] = unbin;
- print((j/2) + "is" + bin);
- }
- else if ( data[2*j+2] < 0 && data[2*j+3] < 0 ) {
- data[2*j] = (byte)(-data[2*j]);
- data[2*j+1] = (byte)(-data[2*j+1]);
- String unhx =(binary(data[2*j+1])+binary(
data[2*j])); - float unbin = ((-1)*(float)unbinary(unhx)/
100); - bin[j/2] = unbin;
- print((j/2) + "is" + bin);
- }
- j = j + 2;
- }
- }
1