2016年11月17日 星期四

Week10 李彩鳳筆記

Bullet time (1:00-1:12)



歷史的軌跡 (Array list)
PVector pt;
ArrayList<PVector>history;
void setup(){
  size(600,400,P3D);
  pt=new PVector(width/2, height/2);
  history=new ArrayList<PVector>(0);
}

void draw (){
  for(PVector nowPt : history){
    ellipse(nowPt.x, nowPt.y, 3,3);
  }
}
void mouseMoved(){
  history.add(new PVector(mouseX, mouseY));

}


Add stroke
PVector pt;
ArrayList<PVector>history;
void setup(){
  size(600,400,P3D);
  pt=new PVector(width/2, height/2);
  history=new ArrayList<PVector>(0);
}

void draw (){
  background (255);
  for(PVector nowPt : history){
    fill(255,0,0); noStroke();
    ellipse(nowPt.x, nowPt.y, 10,10);                   10x10: the dot size
  }
}
void mouseMoved(){
  history.add(new PVector(mouseX, mouseY));
}


Add Leap Motion
import de.voidplus.leapmotion.*;
LeapMotion leap;
PVector pt;
ArrayList<PVector>history;
void setup() {
  size(600, 400, P3D);
  leap=new LeapMotion(this);
  pt=new PVector(width/2, height/2);
  history=new ArrayList<PVector>(0);
}

void draw () {
  background (255);
  for (PVector nowPt : history) {
    fill(255, 0, 0);
    noStroke();
    ellipse(nowPt.x, nowPt.y, 10, 10);
  }
  for ( Hand hand : leap.getHands() ) {
    hand.draw();
    PVector pos = hand.getPosition();
    history.add(new PVector(pos.x, pos.y));
  }
  //void mouseMoved(){
  //  history.add(new PVector(mouseX, mouseY));
}



五根手指頭一起移動
import de.voidplus.leapmotion.*;
LeapMotion leap;
PVector pt;
ArrayList<PVector> history;
ArrayList<PVector> history2;
ArrayList<PVector> history3;
ArrayList<PVector> history4;
ArrayList<PVector> history5;
void setup() {
  size(600, 400, P3D);
  leap=new LeapMotion(this);
  pt=new PVector(width/2, height/2);
  history=new ArrayList<PVector>(0);
  history2=new ArrayList<PVector>(0);
  history3=new ArrayList<PVector>(0);
  history4=new ArrayList<PVector>(0);
  history5=new ArrayList<PVector>(0);
}
void draw() {
  background(255);
  fill(255, 0, 0); 
  noStroke();
  for (PVector nowPt : history) {
    ellipse(nowPt.x, nowPt.y, 10, 10);
  }
  for (PVector nowPt : history2) {
    ellipse(nowPt.x, nowPt.y, 10, 10);
  }
  for (PVector nowPt : history3) {
    ellipse(nowPt.x, nowPt.y, 10, 10);
  }
  for (PVector nowPt : history4) {
    ellipse(nowPt.x, nowPt.y, 10, 10);
  }
  for (PVector nowPt : history5) {
    ellipse(nowPt.x, nowPt.y, 10, 10);
  }
  for ( Hand hand : leap.getHands() ) {
    hand.draw();
    Finger finger = hand.getThumb();
    Finger finger2 = hand.getIndexFinger();
    Finger finger3 = hand.getMiddleFinger();
    Finger finger4 = hand.getRingFinger();
    Finger finger5 = hand.getPinkyFinger();
    PVector pos;
    pos= finger.getPosition();
    history.add(new PVector(pos.x, pos.y));
    pos = finger2.getPosition();
    history2.add(new PVector(pos.x, pos.y));
    pos = finger3.getPosition();
    history3.add(new PVector(pos.x, pos.y));
    pos = finger4.getPosition();
    history4.add(new PVector(pos.x, pos.y));
    pos = finger5.getPosition();
    history5.add(new PVector(pos.x, pos.y));
  }
}


Leap motion 3D
import de.voidplus.leapmotion.*;
LeapMotion leap;
PVector pt;
ArrayList<PVector> history;
ArrayList<PVector> history2;
ArrayList<PVector> history3;
ArrayList<PVector> history4;
ArrayList<PVector> history5;
void setup() {
  size(640, 480, P3D);//Need P3D 3D function (ball, translate, rotate, pushMatrix,popMatrix)
  leap=new LeapMotion(this);
  pt=new PVector(width/2, height/2);
  history=new ArrayList<PVector>(0);
  history2=new ArrayList<PVector>(0);
  history3=new ArrayList<PVector>(0);
  history4=new ArrayList<PVector>(0);
  history5=new ArrayList<PVector>(0);
}
void myBall(float x, float y, float z) {
  pushMatrix();//backup translate/rotate matrix
  translate(x, y, z*10);// z need to be x10 
  sphere(10); 
  popMatrix();//restore the translate/rotate matrix
}
void draw() {
  background(255);
  lights();// lighs will let 3D ball to look like 3D
  translate(width/2, height/2);//This 3 lines (Translate, rotate, translate) 
  rotateY(radians(frameCount));// can let the balls rotating in the center of screen
  translate(-width/2, -height/2);//
  noStroke();
  for (PVector nowPt : history) {
    fill(255, 0, 0); 
    myBall(nowPt.x, nowPt.y, nowPt.z);
  }
  for (PVector nowPt : history2) {
    fill(255, 255, 0); 
    myBall(nowPt.x, nowPt.y, nowPt.z);
  }
  for (PVector nowPt : history3) {
    fill(0, 255, 0); 
    myBall(nowPt.x, nowPt.y, nowPt.z);
  }
  for (PVector nowPt : history4) {
    fill(0, 0, 255);
    myBall(nowPt.x, nowPt.y, nowPt.z);
  }
  for (PVector nowPt : history5) {
    fill(255, 0, 255);
    myBall(nowPt.x, nowPt.y, nowPt.z);
  }
  for ( Hand hand : leap.getHands() ) {
    hand.draw();
    Finger finger = hand.getThumb();
    Finger finger2 = hand.getIndexFinger();
    Finger finger3 = hand.getMiddleFinger();
    Finger finger4 = hand.getRingFinger();
    Finger finger5 = hand.getPinkyFinger();
    PVector pos;
    pos= finger.getPosition();
    history.add(new PVector(pos.x, pos.y, pos.z));
    pos = finger2.getPosition();
    history2.add(new PVector(pos.x, pos.y, pos.z));
    pos = finger3.getPosition();
    history3.add(new PVector(pos.x, pos.y, pos.z));
    pos = finger4.getPosition();
    history4.add(new PVector(pos.x, pos.y, pos.z));
    pos = finger5.getPosition();
    history5.add(new PVector(pos.x, pos.y, pos.z));
  }
}



沒有留言:

張貼留言