Movement

I was interested in creating something that would create a map of movement which could then be applied to different objects. Tak gave me some code that can record mouse movements into a text file and then read them back into another sketch to animate something.  I got that far.  Theoretically I would have liked to create different interactions of objects based on different factors like proximity, which could lead to more complex narratives or sort of choreographies.  The video shows a few different examples of objects moving in space, the pink objects are using the recording text file, and the green object moves in relationship to the pink object, either moving away, or taking the path and using that.  It would be really cool if the movements could generate new movements, but I didn’t get this far because I couldn’t figure out how to append files that had already been written on to.  If you know how to do that, let me know!

 

Code (the parts that are supposed to write over the file are commented out):

import saito.objloader.*;

PrintWriter output;

ArrayList pointList;
ArrayList frames;
int currentFrame = 0;

float xx;
float yy;
float zz;

float sx = 250;
float sy = 250;

OBJModel model;
PImage texture1;

boolean closer = false;

float rotX, rotY;

void setup()
{
  size(800, 600, P3D);
  frameRate(12);
  model = new OBJModel(this, "p5.obj", "relative", TRIANGLES);
  model.enableDebug();
  fill(255, 0, 255);
  model.scale(100);
  model.translateToCenter();

  texture1 = loadImage("p5texture.jpg");
  model.setTexture(texture1);

  stroke(255);
  noStroke();

  model.disableMaterial();

  pointList = new ArrayList();
  frames = new ArrayList();
  importTextFile();

  //output = createWriter("positions.txt");
}

void draw()
{

//  if (mousePressed) {
//    point(mouseX, mouseY, 0);
//    // Write the coordinate to a file with a
//    // "t" (TAB character) between each entry
//    output.println(mouseX + "t" + mouseY + "t"+ 0);
//  }

  background(10);

  importTextFile();

  currentFrame++;  //--->This acts as a counter to 'get' the arraylist number to PVector v.
  if (currentFrame == pointList.size()) {
    currentFrame = 0;
  }
  PVector v = pointList.get(currentFrame);

  lights();
  pushMatrix();
  translate(v.x, v.y, 0);
  rotateX(rotY);
  rotateY(rotX);
  fill(255, 0, 255);
  //box(100);
  model.draw();
  popMatrix();

  if (dist(sx, sy, v.x, v.y) < 100) {
    println("close");
    //closer = true;
    sx++;
    sy++;
  }

  pushMatrix();
  if (closer) {
    translate(sx+v.x, sy-v.y, 10);
  } else {
  translate(sx, sy, 10);
  }
  fill(0,255,255);
  sphere(40);
  sphereDetail(0);
  popMatrix();
}

//void keyPressed()
//{
//
//   if (key == ' ') {
//    output.flush(); // Writes the remaining data to the file
//    output.close(); // Finishes the file
//    //exit(); // Stops the program
//  }
//}

void mouseDragged()
{
  rotX += (mouseX - pmouseX) * 0.01;
  rotY -= (mouseY - pmouseY) * 0.01;
}

void importTextFile() {

  String[] strLines = loadStrings("positions.txt");
  for (int i = 0; i < strLines.length; ++i) {
    String[] arrTokens = split(strLines[i], 't');
    xx = float(arrTokens[0]);
    yy = float(arrTokens[1]);
    zz = float(arrTokens[2]);
    pointList.add( new PVector(xx, yy, zz) );
  }
  //println(output);
}
Advertisements

Author: owen ribbit

poop

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s