nick /224 /camera_curves


/* data visualization for sesnon
 by nick lally
 */
PImage bufSlice;
PGraphics buf;
CameraPosition campos;
int camCount;

int numFloaters = 4; //number of lines
Floaters[] floaters = new Floaters[numFloaters]; //create array for lines
//Noise noises;

void setup() {
  size(500, 500, P3D);
  colorMode(HSB);
  fill(100);

  campos = new CameraPosition();
  buf = createGraphics(1000, 1000, P3D);
  buf.beginDraw();
  buf.smooth();
  buf.background(255);
  buf.endDraw();
  //initialize starting points of lines
  for (int i = 0; i < numFloaters; i++) {
    floaters[i] = new Floaters(100 + i*150, height/2, random(10));
  }
}

void draw() {
  for (int i = 0; i < numFloaters; i++) {
    buf.beginDraw();
    floaters[i].move();
    buf.endDraw();

  }
  campos.move(floaters[int(camCount/100)].x, floaters[int(camCount/100)].y);
  println(floaters[int(camCount/1000)].y);
  if (camCount >= (numFloaters-1) * 100) {
    camCount = 0;
  }

  camCount ++;
}

class Floaters {
  float x, y; //position
  float prevX, prevY; //previous position
  int count = 0;
  float radius;
  Noise noises;
  int direction;

  //contructor
  Floaters(float xpos, float ypos, float r) {
    x = xpos;
    y = ypos;
    prevX = x-1;
    prevY = y-1;
    radius = r;
    noises = new Noise();
    direction = 1;
  }

  //move method
  void move() {
    count++;
    prevX = x;
    prevY = y;
    radius += random(.02);
    /*if (count > 150){
     x = x + sin(radius);
     y = y + -cos(radius)+.1;
     } else {
     x = x + sin(radius);
     y = y + cos(radius)+.1;
     }
     if (count > 300) {
     count = 0;
     } */


    x = x +  (direction * sin(radius));
    y = y +  cos(radius)+.1;

    color cp;
    float b;
    //test next pixel
    if (int(prevX) != int(x) && int(prevY) != int(y)){
      cp = buf.get(int(x),int(y));
      b = brightness(cp);
      if (b < 240){
        direction = direction * -1;
        //println("change");
      }
      //println(direction);
    }

    //call Noise class
    noises.move(x,y);
    stroke(100);
    buf.point(x, y);
  }

}

class Noise {
  float x, y; //position
  float prevX, prevY; //previous position
  int count = 0;
  float radius;


  void move(float xpos, float ypos) {
    x = xpos;
    y = ypos;

    //draw tail
    stroke(random(220,240));
    buf.point(x + random(1,4), y + random(1,4));
    stroke(random(220,240));
    buf.point(x + random(1,4), y + random(1,4));
    stroke(random(220,240));
    buf.point(x - random(1,4), y - random(1,4));
    stroke(random(220,240));
    buf.point(x - random(1,4), y - random(1,4));

    color cp;
    float b;

    cp = buf.get(int(x+1),int(y));
    b = brightness(cp);
    if (b != 0){
      stroke(200);
      buf.point(x+1,y);
    }
    cp = buf.get(int(x-1),int(y));
    b = brightness(cp);
    if (b != 0){
      stroke(200);
      buf.point(x-1,y);
      buf.point(x + random(4), y+ random(4));
    }
  }
}

class CameraPosition {
  float x, y; //position
  float currentX = 0;
  float currentY = 0;
  float easing;

  void move(float destX, float destY) {
    x = destX;
    y = destY;
    easing = .2;
    currentX += (y - currentX) * easing;
    currentY += (x - currentY) * easing;

    image(getBufSlice(currentX, currentY), 0, 0); // plot current position
  }
}

PImage getBufSlice(float currentX, float currentY) {
  int x = int(currentX);
  int y = int(currentY);
  return buf.get(x, y, width, height);
}


Page Details
Contact DANM  |  Digital Arts and New Media  |  Arts Division  |  Grad Division
login