2015年3月30日 星期一

week06

import de.voidplus.leapmotion.*;
LeapMotion leap;
PImage imgAcc;
PImage imgBG;
void setup()
{
  size(800,600, P3D);
  imgBG = loadImage("bg.jpg");
  imgBG.resize(800,600);
 
  imgAcc = loadImage("accurate.png");
  leap = new LeapMotion(this);
}

void draw()
{
  background(imgBG);
  for(Hand hand : leap.getHands() ){
    hand.draw();
    myDraw(hand.getIndexFinger().getPosition());
  }
}
void myDraw(PVector pos){
  pushMatrix();
//  fill(255,0,0); sphere(20);
  image(imgAcc,pos.x-50,pos.y-50,100,100);
  popMatrix();
}



import de.voidplus.leapmotion.*;
LeapMotion leap;
PVector pos[] = new PVector[10];
void setup()
{
  size(600,600, P3D);
  leap = new LeapMotion(this);
  for(int i=0;i<10;i++) pos[i]=new PVector(60*i, -random(600));
}
float grabX=0,grabY=0;
int grade = 0;
void draw()
{
  background(128);
  for(int i=0;i<10;i++){
    ellipse(pos[i].x,pos[i].y,50,50);
    pos[i].y+=3;
    if(pos[i].y>600) pos[i].y=-random(300);
    if(dist(grabX,grabY,pos[i].x,pos[i].y)<100){
      fill(255,0,0);pos[i].y=-random(300);grade+=1000;}
      else fill(255);
    }
    for(Hand hand : leap.getHands() ){
      if(hand.isRight()){
        grabX = hand.getPosition().x;
        grabY = hand.getPosition().y;
    }
  }
  rect(grabX,grabY,100,100);
  textSize(60);fill(255,0,0);
  text("Score:"+grade,100,100);
}

沒有留言:

張貼留言