2015年4月13日 星期一

week6


Draw a box on your hand's center:

import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
  size(600, 600, P3D);
  leap= new LeapMotion(this);
}
void draw(){
  background(255); //background redraw
  for(Hand hand: leap.getHands()){
    hand.draw();
    float angle= hand.getYaw(); //hand's angle
    PVector pos= hand.getPosition(); //hand's position
    translate(pos.x, pos.y, pos.z);
    rotateY(-radians(angle));
    fill(0, 100, 150);
    stroke(0);
    box(100);
  }
}





Fly to right, ground translate to left:

import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
  size(600, 600, P3D);
  leap= new LeapMotion(this);
}
float groundDir=0;
void draw(){
  background(255); //background redraw
  //draw ground's box
  for(int i=-10;i<=10;i++){
    for(int j=-10;j<=10;j++){
      pushMatrix(); //matrix
      translate(300, 400); //ground's original x&y
      rotateX(radians(70));
      rotateZ(radians(groundDir));
      translate(i*30, j*30);
      fill(0, 150, 100);
      box(30);
      popMatrix(); //matrix
    }
  }
  for(Hand hand: leap.getHands()){
    hand.draw();
    float angle= hand.getYaw(); //hand's angle
    PVector pos= hand.getPosition(); //hand's position
    translate(pos.x, pos.y, pos.z);
    rotateY(-radians(angle));
    fill(0, 100, 150);
    stroke(0);
    box(100);
    
    groundDir= -angle;
  }
}










plane's motion:
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
  size(600, 600, P3D);
  leap= new LeapMotion(this);
}
float nowX=0, nowY=0, nowA=0;
void draw(){
  nowY+=cos(nowA); nowX+=sin(nowA);
  background(0, 150, 200, 100); //background redraw
  //draw ground's box
  for(int i=-10;i<=10;i++){
    for(int j=-10;j<=10;j++){
      pushMatrix(); //matrix
      translate(300, 500); //ground's original x&y
      rotateX(radians(70));
      rotateZ(radians(nowA));
      translate(i*200+nowX, j*200+nowY, -50);
      fill(0, 150, 100); box(200); //ground's color and box's size
      popMatrix(); //matrix
    }
  }
  for(Hand hand: leap.getHands()){
    hand.draw();
    float angle= hand.getYaw(); //hand's angle
    PVector pos= hand.getPosition(); //hand's position
    nowA+= radians(-angle/40);
    translate(pos.x, pos.y, pos.z);
    rotateY(-radians(angle));
    fill(181, 181, 181); stroke(0); box(100);
  }
}










期中作業討論:
彈鋼琴
彈力球
貪吃蛇
賽車
下棋
停車
1010!




import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup() {
  size(600, 600, P3D);
  leap = new LeapMotion(this);
}

float nowX=0,nowY=0,nowA=0;
void draw() {
  background(255);
  nowY+=cos(nowA);nowX+=sin(nowA);
  for (int i=-10; i<=10; i++) {
    for (int j=-10; j<=10; j++)
    {
      pushMatrix();
      translate(300, 300);
      rotateX(radians(70));
      rotateZ(nowA);
      translate(i*200+nowX, j*200+nowY,0);
      fill(255);box(200);
      popMatrix();
    }
  }


  for (Hand hand : leap.getHands ()) {
    hand.draw();
    float angle= hand.getYaw();
    PVector pos =hand.getPosition();
    nowA+=radians(-angle/40);
    translate(pos.x, pos.y, pos.z);
    rotateY(-radians(angle));
    fill(128);
    stroke(0);
    box(100);
  }
}





import de.voidplus.leapmotion.*;
PImage img0, img2, img5;
LeapMotion leap;
void setup() {
  size(600, 600, P3D);
  leap = new LeapMotion(this);
  img0=loadImage("s.jpg");
  img2=loadImage("j.jpg");
  img5=loadImage("b.jpg");
}
void draw() {
  background(255);
  println(leap.getHands().size());
  fill(255, 0, 0);
  textSize(40);
  for (Hand hand : leap.getHands ()) {
    int n=hand.getOutstrechtedFingers().size();
    if (hand.isRight()) {
      if (n==0) image(img0, 300, 300);
      else if (n<=2) image(img2, 300, 300);
      else image(img5, 300, 300);
    } else
      if (n==0) image(img0, 0, 300);
    else if (n<=2) image(img2, 0, 300);
    else image(img5, 0, 300);
  }
}


沒有留言:

張貼留言