Kinetic Interfaces – week 12 OSC weekly Assignment (Echo)

For OSC weekly assignment, I created a synchronised drawing board. The sender can be used to draw colourful lines and the drawing will be displayed on the receiver’s screen at the same time. Here is the demo:

demo1

 

import oscP5.*;
import netP5.*;


OscP5 oscP5;
NetAddress myRemoteLocation;


void setup() {
  size(400,400);
  background(100);
  
  oscP5 = new OscP5(this,12000);
  myRemoteLocation = new NetAddress("127.0.0.1",12001);
}


void draw() {
  //
}


void mouseDragged() {
  OscMessage msg = new OscMessage("/Echo");
   
  // let's send mouseX&Y positions
  float x = map(mouseX,0,width,0,1);
  float y = map(mouseY,0,height,0,1);
  float X = map(pmouseX,0,width,0,1);
  float Y = map(pmouseY,0,width,0,1);
 
  msg.add( x );
  msg.add( y );
  msg.add( X );
  msg.add( Y );

  oscP5.send( msg, myRemoteLocation );
  
  stroke(random(255),random(255),random(255));
  line(mouseX, mouseY, pmouseX, pmouseY);
}
import oscP5.*;
import netP5.*;


OscP5 oscP5;

int x,y,X,Y;
float xValue = 0;
float yValue = 0;
float XValue = 0;
float YValue = 0;

void setup() {
  size(800, 500);
  background(100);

  oscP5 = new OscP5(this, 12001);
}


void draw() {
  int x =(int)map(xValue,0,1,0,width);
  int y =(int)map(yValue,0,1,0,height);
  int X =(int)map(XValue,0,1,0,width);
  int Y =(int)map(YValue,0,1,0,height);
  stroke(random(255),random(255),random(255));
  line(x,y,X,Y);
}

void oscEvent(OscMessage msg) {
  println("___");
  println("Pattern: " + msg.addrPattern() );
  println("Typetag: " + msg.typetag() );
  println();

  xValue = msg.get(0).floatValue();
  yValue = msg.get(1).floatValue();
  XValue = msg.get(2).floatValue();
  YValue = msg.get(3).floatValue();
  println("x" + xValue);
  println("y" + yValue);
  println("X" + XValue);
  println("Y" + YValue);
  println();
  }

Leave a Reply