2016年11月17日 星期四

Week 10 蕭阿火筆記


本日上課重點
- Leap Motion的使用以及複習金幣遊戲
- 陣列、存檔、成績排名、SORT計算
- 如何做剪刀石頭布的猜拳遊戲
- 運用陣列做3D畫畫過程重播示範

=======================================================================
互動技術相關實作的內容分享
小小兵技術
火材人格鬥
太鼓達人
以往電子電路設計的相關使用
======================================================================
Bullet time的飛行軌跡,透過運用陣列來列下所有的過程
運用滑鼠位置來做軌跡的實作
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));
}
========================================================================
將軌跡運用在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,3,3);
  }
  for(Hand hand : leap.getHands()){
    PVector pos = hand.getPosition();
    history.add(new PVector(pos.x,pos.y));
  }
}


=======================================================
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);具有3D功能,轉動、移動等。
  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){                  透過PUSH MATRIX用來移動,轉向
  pushMatrix();
  translate(x,y,z*10);
  sphere(10);
  popMatrix();
}


void draw() {
  background(255);
  lights();                                             打光、旋轉、移動
  translate(width/2,height/2);
  rotateY(radians(frameRate));     把Rate改成Count即可使得她在中心轉動
  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));
  }
}
//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(640, 480, 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 myBall(float x,float y,float z){
  pushMatrix();
  translate(x,y,z*10);
  sphere(10);
  popMatrix();
}
void draw() {
  background(255);
  lights();
  translate(width/2,height/2);
  rotateY(radians(frameRate));
  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));
  }
}

沒有留言:

張貼留言