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();
  }

【Kinetic Interface】Kinect for UE4 TPS Blueprint (Kevin Xu and Jiayi Wang)

Final Preview Build with UE4.17.2. Upward compatible until 4.18. Kinect plugin is required for the project which can be found here. The Kinect plugin is not compatible with 4.19 and any newer version by May 2018. Project download link: https://drive.google.com/file/d/19AIs7NBNx7OkzGriS_T02x3lrI_zw4wf/view?usp=sharing The final version of the blueprint is named as 3rdpersonKinect in the root directory. The final product is […]

【Kinetic Interface】Final Proposal (Kevin Xu and Jiayi Wang)

Presentation Slides:https://docs.google.com/presentation/d/1ai50ob6ezz_TZQRzUVHuS1AfxMMMpVi5pcNnVHDsvxo/edit?usp=sharing For the final project, we want to make a sidescroller style 2 player fighting game with the Kinect as the controller. Different from traditional fighting games like Street Fighter that has a lot of combo attacks, we want our game to stick with reality. Which means the characters will attack each other in the way […]

Kinetic Interfaces Final Project: Fish Artists (Oli and Harrison)

Project: Fish Artists Partner: Sihao Chen Date: 13 May Inspiration Our project, which was inspired by our midterm project, involved using the silhouettes of live fish with processing to create a real time visual painting in traditional Chinese style.  For our midterm project we used leap motion to create a pond ecosystem simulation. The user […]

import processing.video.*;
Capture video;
int blobCounter = 0;
int maxLife = 200;
color trackColor; 
float threshold = 40;
float distThreshold = 50;
ArrayList<Blob> blobs = new ArrayList<Blob>();

void setup() {
  size(640, 360);
  String[] cameras = Capture.list();
  printArray(cameras);
  video = new Capture(this, cameras[41]);
  video.start();
  // 183.0 12.0 83.0
  trackColor = color(183, 12, 83);
}

void captureEvent(Capture video) {
  video.read();
}

void keyPressed() {
  if (key == 'a') {
    distThreshold+=5;
  } else if (key == 'z') {
    distThreshold-=5;
  }
  if (key == 's') {
    threshold+=5;
  } else if (key == 'x') {
    threshold-=5;
  }
}

void draw() {
  video.loadPixels();
  image(video, 0, 0);

  ArrayList<Blob> currentBlobs = new ArrayList<Blob>();

  // Begin loop to walk through every pixel
  for (int x = 0; x < video.width; x++ ) {
    for (int y = 0; y < video.height; y++ ) {
      int loc = x + y * video.width;
      // What is current color
      color currentColor = video.pixels[loc];
      float r1 = red(currentColor);
      float g1 = green(currentColor);
      float b1 = blue(currentColor);
      float r2 = red(trackColor);
      float g2 = green(trackColor);
      float b2 = blue(trackColor);

      float d = distSq(r1, g1, b1, r2, g2, b2); 

      if (d < threshold*threshold) {

        boolean found = false;
        for (Blob b : currentBlobs) {
          if (b.isNear(x, y)) {
            b.add(x, y);
            found = true;
            break;
          }
        }

        if (!found) {
          Blob b = new Blob(x, y);
          currentBlobs.add(b);
        }
      }
    }
  }

  for (int i = currentBlobs.size()-1; i >= 0; i--) {
    if (currentBlobs.get(i).size() < 500) {
      currentBlobs.remove(i);
    }
  }

  // There are no blobs!
  if (blobs.isEmpty() && currentBlobs.size() > 0) {
    println("Adding blobs!");
    for (Blob b : currentBlobs) {
      b.id = blobCounter;
      blobs.add(b);
      blobCounter++;
    }
  } else if (blobs.size() <= currentBlobs.size()) {
    // Match whatever blobs you can match
    for (Blob b : blobs) {
      float recordD = 1000;
      Blob matched = null;
      for (Blob cb : currentBlobs) {
        PVector centerB = b.getCenter();
        PVector centerCB = cb.getCenter();         
        float d = PVector.dist(centerB, centerCB);
        if (d < recordD && !cb.taken) {
          recordD = d; 
          matched = cb;
        }
      }
      matched.taken = true;
      b.become(matched);
    }

    // Whatever is leftover make new blobs
    for (Blob b : currentBlobs) {
      if (!b.taken) {
        b.id = blobCounter;
        blobs.add(b);
        blobCounter++;
      }
    }
  } else if (blobs.size() > currentBlobs.size()) {
    for (Blob b : blobs) {
      b.taken = false;
    }


    // Match whatever blobs you can match
    for (Blob cb : currentBlobs) {
      float recordD = 1000;
      Blob matched = null;
      for (Blob b : blobs) {
        PVector centerB = b.getCenter();
        PVector centerCB = cb.getCenter();         
        float d = PVector.dist(centerB, centerCB);
        if (d < recordD && !b.taken) {
          recordD = d; 
          matched = b;
        }
      }
      if (matched != null) {
        matched.taken = true;
        matched.become(cb);
      }
    }

    for (int i = blobs.size() - 1; i >= 0; i--) {
      Blob b = blobs.get(i);
      if (!b.taken) {
        blobs.remove(i);
      }
    }
  }

  for (Blob b : blobs) {
    b.show();
  } 



  textAlign(RIGHT);
  fill(0);
  //text(currentBlobs.size(), width-10, 40);
  //text(blobs.size(), width-10, 80);
  textSize(24);
  text("color threshold: " + threshold, width-10, 50);  
  text("distance threshold: " + distThreshold, width-10, 25);
}


float distSq(float x1, float y1, float x2, float y2) {
  float d = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
  return d;
}


float distSq(float x1, float y1, float z1, float x2, float y2, float z2) {
  float d = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) +(z2-z1)*(z2-z1);
  return d;
}

void mousePressed() {
  // Save color where the mouse is clicked in trackColor variable
  int loc = mouseX + mouseY*video.width;
  trackColor = video.pixels[loc];
  println(red(trackColor), green(trackColor), blue(trackColor));
}