gregorami
YaBB Newbies
Offline
Posts: 8
Re: write to array
Reply #4 - Jan 24th , 2007, 6:26am
hmm, now I am just screwing around, but it seems like I can't really get to the data ... on the max side I send the array through the max object iter (iterates through the array and sends one number at a time to processing ... Here's the code: import maxlink.*; MaxLink link = new MaxLink(this, "message_board"); // get all messages from max link object public float num1, num2, num3, num4, num5; public float [] numbers = new float[4]; public int out1, out2, out3; public int flag1; int posX, posY; String oldMessage = ""; String message = ""; int messageCount = 0; // array to contain numbers an array sent from max void setup() { size(300,300); background(20); // inlets from max to processing link.declareInlet("num1"); link.declareInlet("num2"); link.declareInlet("num3"); link.declareInlet("num4"); link.declareInlet("num5");// array from max flag1 = -1; //recievedNumber is what you get from maxlink //numbers=append(numbers, recievedNumber); //} } void draw() { drawMessage(); stroke(250); line(20, 300, 20, num1); stroke(250); line(30, 300, 30, num2); stroke(250); line(40, 300, 40, num3); // if (flag1 < 0) { // flag1 = flag1 + 1; // } // if (flag1 > 3 | num5 > 300.0) { // flag1 = -1; // } // numbers[flag1] = num5; // print("array@"+flag1); // println(" = "+num5); // println("hello" + num5); // if(flag1 >= 0) { // numbers[flag1] = num5; // print("array@"+flag1); // println(" = "+num5); // } ellipseColor(); mouseAction(); arrayFromMax(); } // this method must be public - if a message number is different than previous, then notice it! public void setMessage(String newMessage) { messageCount++; link.output(messageCount); oldMessage = message; message = newMessage; } void drawMessage() { background(20); if (oldMessage != "") text("previous message: " + oldMessage, 37, 80); } // these two circles will be white if box is checked in max and grey otherwise void ellipseColor() { if(num4==1) { fill(255); noStroke(); ellipse(200, 30, 20, 20); } else { fill(100); noStroke(); ellipse(200, 30, 20, 20); } if(num5==1) { fill(255); noStroke(); ellipse(200, 57, 20, 20); } else { fill(100); noStroke(); ellipse(200, 57, 20, 20); } } // mouseClick and x/y coordinates will be sent to maxlink object in max void mouseAction() { posX=mouseX; posY=mouseY; if(mousePressed) { out1=1; } else { out1=0; } link.output(1,out1); noStroke(); fill(255); rect(posX, posY, 20, 20); out2=posX; out3=posY; link.output(2,out2); link.output(3,out3); } void arrayFromMax() { fill(255); line(numbers[0], 50, numbers[1], 50); // println(numbers); }