顯示具有 01160953_洪詩庭 標籤的文章。 顯示所有文章
顯示具有 01160953_洪詩庭 標籤的文章。 顯示所有文章

2015年6月29日 星期一

期末作業遊戲程式寫法



step1:先宣告變數



step2:將圖檔匯入程式黨裡
ps.圖要拉近data資料夾中


先將會用到的變數設為0



用control決定每個動作
control1為上
2為左
3為右
4為下




health為生命
共有五個 
失誤一次減少一個生命



使用random使箭頭隨機放下





使用n1~n5寫入分數
分別為
個十百千萬



以上是每個分數的圖檔




加入鍵盤按鍵
s為下
d為右
w為上



利用FAAST偵測骨架與做判斷

其中
W(上):右手需高於頭部15公分
S(下):右手需低於軀幹15公分D(右):右手需比軀幹右30公分


PS.玩的時候要快狠準,否則太慢的話會一直偵測測到一樣的 這樣就會容易疏






以上是我們的遊戲!!!!!!!!!!!!!!!!!!!!













期末報告:體感跳舞機

(小提醒:聲音可以關小一點........)


我們的期末報告是體感跳舞機。
藉由右手的動作,來對應箭頭的上右下。
剛開始是先設定好遊戲的分數算法,以及設定三個箭頭。
之後設定鍵盤的WSD,代表著的分別是箭頭的上下右。
讓此遊戲可以用鍵盤玩。
最後,使用Faast,讓Pocessing跟Kinect做連結,
將鍵盤的WSD鍵用身體去做定義,
最後就完成了一個可以用身體來玩遊戲的體感跳舞機。



這是我們的程式碼:
//import de.voidplus.leapmotion.*; //import SimpleOpenNI.*; import ddf.minim.*; import SimpleOpenNI.*; SimpleOpenNI openni; //SimpleOpemNI context; PImage img, img1, img2, down, right, up; PImage img7; PImage img10; PImage img11; PImage img12; PImage img13; PImage img14; PImage img15; PImage img16; PImage img17; PImage img18; PImage img19; //LeapMotion leap; AudioPlayer player; Minim minim; int [] ran=new int[50]; float [] pointY=new float[50]; //int [] pointY=new int[50]; int h1, t1, t2, start, control, score, health, ground,time; float speed; int n1, n2, n3, n4, n5, nu1, nu2, nu3, nu4, nu5; void setup() { size(800, 600, P3D); for (int i=0; i<50; i++) { pointY[i]=-1; ran[i]=0; } img = loadImage("floor.jpg"); img1 = loadImage("tree.jpg"); img2 = loadImage("floor1.jpg"); down = loadImage("down.png"); right = loadImage("right.png"); up = loadImage("up.png"); img7 = loadImage("protect.png"); img10 = loadImage("0.png"); img11 = loadImage("1.png"); img12 = loadImage("2.png"); img13 = loadImage("3.png"); img14 = loadImage("4.png"); img15 = loadImage("5.png"); img16 = loadImage("6.png"); img17 = loadImage("7.png"); img18 = loadImage("8.png"); img19 = loadImage("9.png"); minim = new Minim(this); player = minim.loadFile("music.mp3", 2048); player.play(); t1=0; t2=0; control=0; start=0; score=0; health=5; h1=0; n1=0; n2=0; n3=0; n4=0; n5=0; nu1=10; nu2=100; nu3=1000; nu4=10000; nu5=100000; ground=0; time=1; speed=1.5; // leap = new LeapMotion(this).withGestures(); } void draw() { if (health==0)ground=1; if (ground==0)background(img); else background(img2); //image(img1, 0, 510, 800, 100); if (ground==0) { for (int i=1; i<=health; i++) { image(img7, 790-i*50, 10, 50, 50); } if (control>=1&&control<=4) { for (int i=0; i<50; i++) { if (control==1) if (pointY[i]>=470&&pointY[i]<=570&&ran[i]==1) { ran[i]=0; score+=speed*10; h1=1; } if (control==2) if (pointY[i]>=470&&pointY[i]<=570&&ran[i]==2) { ran[i]=0; score+=speed*10; h1=1; } if (control==3) if (pointY[i]>=470&&pointY[i]<=570&&ran[i]==3) { ran[i]=0; score+=speed*10; h1=1; } if (control==4) if (pointY[i]>=470&&pointY[i]<=570&&ran[i]==4) { ran[i]=0; score+=speed*10; h1=1; } } if (h1==0)health--; control=0; h1=0; } t1=0; for (int i=0; i<50; i++) if (pointY[i]<=100&&pointY[i]>=0)t1=1; if (t1==1)t2=1; else t2=0; if (t2==0) { ran[start]=int(random(1, 5)); pointY[start]=0; start++; } for (int i=0; i<50; i++) { if (ran[i]==1)image(down, 350, pointY[i], 80, 80); if (ran[i]==4)image(up, 350, pointY[i], 80, 80); if (ran[i]==3)image(right, 500, pointY[i], 80, 80); } for (int i=0; i<50; i++) if (ran[i]>=1&&ran[i]<=5)pointY[i]+=speed; } for(int i=0;i<50;i++) if(ran[i]>=1&&ran[i]<=3&&pointY[i]==600){ ran[i]=0; health--; } n1=score%nu1; n2=score%nu2/10; n3=score%nu3/100; n4=score%nu4/1000; n5=score%nu4/10000; if (n1==0)image(img10, 140, 10, 40, 40); if (n1==1)image(img11, 140, 10, 40, 40); if (n1==2)image(img12, 140, 10, 40, 40); if (n1==3)image(img13, 140, 10, 40, 40); if (n1==4)image(img14, 140, 10, 40, 40); if (n1==5)image(img15, 140, 10, 40, 40); if (n1==6)image(img16, 140, 10, 40, 40); if (n1==7)image(img17, 140, 10, 40, 40); if (n1==8)image(img18, 140, 10, 40, 40); if (n1==9)image(img19, 140, 10, 40, 40); if (n2==0)image(img10, 100, 10, 40, 40); if (n2==1)image(img11, 100, 10, 40, 40); if (n2==2)image(img12, 100, 10, 40, 40); if (n2==3)image(img13, 100, 10, 40, 40); if (n2==4)image(img14, 100, 10, 40, 40); if (n2==5)image(img15, 100, 10, 40, 40); if (n2==6)image(img16, 100, 10, 40, 40); if (n2==7)image(img17, 100, 10, 40, 40); if (n2==8)image(img18, 100, 10, 40, 40); if (n2==9)image(img19, 100, 10, 40, 40); if (n3==0)image(img10, 60, 10, 40, 40); if (n3==1)image(img11, 60, 10, 40, 40); if (n3==2)image(img12, 60, 10, 40, 40); if (n3==3)image(img13, 60, 10, 40, 40); if (n3==4)image(img14, 60, 10, 40, 40); if (n3==5)image(img15, 60, 10, 40, 40); if (n3==6)image(img16, 60, 10, 40, 40); if (n3==7)image(img17, 60, 10, 40, 40); if (n3==8)image(img18, 60, 10, 40, 40); if (n3==9)image(img19, 60, 10, 40, 40); if (n4==0)image(img10, 20, 10, 40, 40); if (n4==1)image(img11, 20, 10, 40, 40); if (n4==2)image(img12, 20, 10, 40, 40); if (n4==3)image(img13, 20, 10, 40, 40); if (n4==4)image(img14, 20, 10, 40, 40); if (n4==5)image(img15, 20, 10, 40, 40); if (n4==6)image(img16, 20, 10, 40, 40); if (n4==7)image(img17, 20, 10, 40, 40); if (n4==8)image(img18, 20, 10, 40, 40); if (n4==9)image(img19, 20, 10, 40, 40); if (n5==0)image(img10, 180, 10, 40, 40); if (n5==1)image(img11, 180, 10, 40, 40); if (n5==2)image(img12, 180, 10, 40, 40); if (n5==3)image(img13, 180, 10, 40, 40); if (n5==4)image(img14, 180, 10, 40, 40); if (n5==5)image(img15, 180, 10, 40, 40); if (n5==6)image(img16, 180, 10, 40, 40); if (n5==7)image(img17, 180, 10, 40, 40); if (n5==8)image(img18, 180, 10, 40, 40); if (n5==9)image(img19, 180, 10, 40, 40); println(speed); time++; if(time%500==0)speed+=0.5; } //490 560 void keyPressed() { if (key=='s') control=1; if (key=='d') control=3; if (key=='w') control=4; }








然後跟Faast做連結,
先設定好WSD的動作定義
W(上):右手需高於頭部15公分
S(下):右手需低於軀幹15公分
D(右):右手需比軀幹右30公分
之後,點上connect,和kinect做連結後,start Emulator
就能和Processing做連結了。









設定出自己的定義:











遊戲畫面:
在箭頭到達背景圖片沙灘部位時,做出相對應的動作。
最多能夠失敗五次,
每失敗一次,右上角的藍色球球就會少一顆。
左上角是計分,會依正確次數去做累計,
正確次數越多(累計),分數將以等差去遞增上去。


2015年6月22日 星期一

期末報告進度

上星期的進度是將程式能用鍵盤玩的跳舞機遊戲。
這星期的進度則是加入Kinect,並定義怎樣為正確

上:RightHand需高於Head至少30公分
下:RightHand需低於Torso至少30公分
右:RightHand需比Torso右至少30公分

所以這星期和Faast連接上,


2015年6月15日 星期一

期末報告進度:

今天進度為將程式部分能用鍵盤玩,並設定好遊戲的分數是怎麼計算。


2015年6月8日 星期一

2015年6月1日 星期一

期末初構想

期末作業:
理念和期中作業一樣,是跳舞機。
只是這次不是手指,是身體。
用左右手表示左邊右邊跟上面。
一邊會有音樂撥放,然後隨機有箭頭落下。




我們的考量是
用手腕的高度、位置來判斷動作正確與否
例如若是向右的箭頭,右手的x值必須大於某個值;
例如若是向左的箭頭,左手的x值必須小於某個值;
例如若是向上的箭頭,右手的y值必須大於某個值。



2015年5月25日 星期一

第十四週



第一步驟:
打開FAAST ,然後設定初設定
























第二步驟:打上程式碼.跟Processing做連結。
import kinect4WinSDK.Kinect;
import kinect4WinSDK.SkeletonData;
PImage imgCar;
Kinect kinect;
ArrayList <SkeletonData> bodies;
float angle=0, dX=0, dY=0, vel=1;
void setup(){
  size(640, 480, P3D);
  background(0);
  kinect= new Kinect(this);
  smooth();
  bodies= new ArrayList<SkeletonData>();
  imgCar= loadImage("red.png");
}

void draw(){
  background(0);
  image(kinect.GetImage(), 320, 0, 320, 240);
  image(kinect.GetDepth(), 320, 240, 320, 240);
  image(kinect.GetMask(), 0, 240, 320, 240);
  for(int i=0;i<bodies.size();i++){
    drawSkeleton(bodies.get(i));
    drawPosition(bodies.get(i));
  }
  
  
  pushMatrix();
    translate(width/2, height/2);
    rotateZ(angle);
    image(imgCar, -100, -50, 200, 100);
  popMatrix();
}

void drawPosition(SkeletonData _s){
  noStroke();
  fill(0, 100, 255);
  //need to add//
}


void mouseMoved(){
  int x= mouseX-pmouseX;
  int y= mouseY-pmouseY;
  if(x>0) angle+=1/40.0;
  if(x<0) angle-=1/40.0;
}

void keyPressed(){
  if(key=='l') angle++;
  if(key=='r') angle--;
  if(keyCode==UP) vel*=1.1;
  if(keyCode==DOWN) vel*=0.9;
  println("vel:"+vel);
}

2015年5月18日 星期一

第十三週


題目:水果忍者



第一階段:先做出一堆會自由跑來跑去的球(水果)
以下是程式碼:

------------------------------------------------------------------------

import SimpleOpenNI.*;
SimpleOpenNI openni;
class Fruit{
  float X,Y,VX,VY;
  Fruit(float x, float y, float vx, float vy){
    X=x; Y=y; VX=vx; VY=vy;
  }
  void draw(){
    ellipse(X,Y,50,50);
  }
  void update(){
    X+=VX; Y+=VY; VY+=1.98;
    if(X<-100 || X>740 || Y<-100 || Y>580){
      X=random(640); Y=random(240); VX=random(30)-15; VY=-random(30);
    }
  }
}

Fruit fruit[]= new Fruit[20];
void setup(){
  size(640,480);
  openni = new SimpleOpenNI(this);
  openni.enableDepth();
  openni.enableUser();
  for(int i=0; i<20; i++)
    fruit[i] = new Fruit(random(640), random(240), random(30)-15, -random(30));
}

void draw(){
  openni.update();
  image(openni.userImage(),0,0);
  for(int i=0; i<20; i++){
    fruit[i].draw();
    fruit[i].update();
  }
}



================================================================




第二階段:是做出一個隨著滑鼠移動的紅線,紅線碰到球體(水果)後球體會從白變紅
以下是程式碼:

------------------------------------------------------------------------

import SimpleOpenNI.*;
SimpleOpenNI openni;
class Fruit{
  float X,Y,VX,VY;
  boolean dead= false;
  Fruit(float x, float y, float vx, float vy){
    X=x; Y=y; VX=vx; VY=vy;
  }
  void draw(){
    if(dead) fill(255,0,0);
    else fill(255);
    ellipse(X,Y,50,50);
  }
  void update(){
    X+=VX; Y+=VY; VY+=1.98;
    if(X<-100 || X>740 || Y<-100 || Y>580){
      X=random(640); Y=random(240); VX=random(30)-15; VY=-random(30); dead=false;
    }
     if( dist(X, Y, mouseX, mouseY)<50) dead=true;
  }
}
void mouseMoved(){
  strokeWeight(20);
  stroke(255,0,0);
  line(mouseX, mouseY, pmouseX, pmouseY);
  strokeWeight(1);
  stroke(0);
}

Fruit fruit[]= new Fruit[20];
void setup(){
  size(640,480);
  openni = new SimpleOpenNI(this);
  openni.enableDepth();
  openni.enableUser();
  for(int i=0; i<20; i++)
    fruit[i] = new Fruit(random(640), random(240), random(30)-15, -random(30));
}

void draw(){
  openni.update();
  image(openni.userImage(),0,0);
  for(int i=0; i<20; i++){
    fruit[i].draw();
    fruit[i].update();
  }
}



==============================================================




第三階段:用身體碰觸就能使球體發生碰撞事件
以下是程式碼:

------------------------------------------------------------------------

import SimpleOpenNI.*;
SimpleOpenNI openni;
class Fruit{
  float X,Y,VX,VY;
  boolean dead= false;
  Fruit(float x, float y, float vx, float vy){
    X=x; Y=y; VX=vx; VY=vy; dead=false;
  }
  void draw(){
    if(dead) fill(255,0,0);
    else fill(255);
    ellipse(X,Y,50,50);
  }
  void update(){
    X+=VX; Y+=VY; VY+=1.98;
    if(X<-100 || X>740 || Y<-100 || Y>580){
      X=random(640); Y=random(240); VX=random(30)-15; VY=-random(30); dead=false;
    }
     if( dist(X, Y, mouseX, mouseY)<50) dead=true;
     if(X>0 && X<640 && Y>0 && Y<480 &&openni.userImage().pixels[int(X)+int(Y)*640]==color(0,0,255)) dead=true;
  }
}
void mouseMoved(){
  strokeWeight(20);
  stroke(255,0,0);
  line(mouseX, mouseY, pmouseX, pmouseY);
  strokeWeight(1);
  stroke(0);
}
Fruit fruit[]= new Fruit[20];
void setup(){
  size(640,480);
  openni = new SimpleOpenNI(this);
  openni.enableDepth();
  openni.enableUser();
  for(int i=0; i<20; i++)
    fruit[i] = new Fruit(random(640), random(240), random(30)-15, -random(30));
}

void draw(){
  openni.update();
  image(openni.userImage(),0,0);
  for(int i=0; i<20; i++){
    fruit[i].draw();
    fruit[i].update();
  }
}



==============================================================



































第四階段:用滑鼠畫線,被切到的球就會分裂了
以下是程式碼:

------------------------------------------------------------------------

import SimpleOpenNI.*;
SimpleOpenNI openni;
PImage imgUser;
class Fruit{
  float X,Y,VX,VY, split=0, angle=0;
  boolean dead= false;
  Fruit(float x, float y, float vx, float vy){
    X=x; Y=y; VX=vx; VY=vy; dead=false;
  }
  void draw(){
    if(dead) {fill(255,0,0);
      arc(X+split,Y,50,50,angle,angle+PI,CHORD);
      arc(X-split,Y,50,50,angle+PI,angle*2,CHORD);
  }
    else{
      fill(255);
      ellipse(X,Y,50,50);
    }
  }
  void update(){
    X+=VX; Y+=VY; VY+=0.68;
    if(X<-100 || X>740 || Y<-100 || Y>580){
      X=random(640); Y=random(240); VX=random(10)-5; VY=-random(10); dead=false; split=0;
    }
     if( dist(X, Y, mouseX, mouseY)<50) {
     dead=true;
     angle= atan2(mouseY-pmouseY,mouseX-pmouseX);
    }
     if(X>0 && X<640 && Y>0 && Y<480 &&openni.userImage().pixels[int(X)+int(Y)*640]==color(0,0,255)) {
       dead=true;
     }
     if(dead) split+=2;
  }
}
void mouseMoved(){
  strokeWeight(20);
  stroke(255,0,0);
  line(mouseX, mouseY, pmouseX, pmouseY);
  strokeWeight(1);
  stroke(0);
}
Fruit fruit[]= new Fruit[20];
void setup(){
  size(640,480);
  openni = new SimpleOpenNI(this);
  openni.enableDepth();
  openni.enableUser();
  for(int i=0; i<20; i++)
    fruit[i] = new Fruit(random(640), random(240), random(10)-15, -random(10));
}

void draw(){
  openni.update();
  image(openni.userImage(),0,0);
  for(int i=0; i<20; i++){
    fruit[i].draw();
    fruit[i].update();
  }
}

2015年4月27日 星期一

期中作業:手指跳舞機

影片位置:(建議將喇叭音量調小再點開)
https://www.youtube.com/watch?v=m1-bHjUTskg


簡介:
設計理念是會有音樂播放,然後會有箭頭落下。依落下的方向用手揮動來代表上下左右。




程式:
//import de.voidplus.leapmotion.*;
import de.voidplus.leapmotion.*;
//LeapMotion leap;
import ddf.minim.*;
PImage img, img1, img2,img3,img4, down, left, right, fly;
PImage img7;
PImage img10;
PImage img11;
PImage img12;
PImage img13;
PImage img14;
PImage img15;
PImage img16;
PImage img17;
PImage img18;
PImage img19;
LeapMotion leap;
AudioPlayer player;
Minim minim;
int [] ran=new int[50];
float [] pointY=new float[50];
//int [] pointY=new int[50];
int h1, t1, t2, start, control, score, health, ground, time;
float speed, centerx, centery;
int n1, n2, n3, n4, n5, nu1, nu2, nu3, nu4, nu5, keys, cx, cy,count;

void setup() {
  size(800, 600, P3D);
  for (int i=0; i<50; i++) {
    pointY[i]=-1;
    ran[i]=0;
  }
  img = loadImage("floor.jpg");
  fly = loadImage("fly.png");
  img1 = loadImage("tree.jpg");
  img2 = loadImage("floor1.jpg");
  img3 = loadImage("floor2.jpg");
  img4 = loadImage("floor3.jpg");
  down = loadImage("down.png");
  left = loadImage("left.png");
  right = loadImage("right.png");
  img7 = loadImage("protect.png");
  img10 = loadImage("0.png");
  img11 = loadImage("1.png");
  img12 = loadImage("2.png");
  img13 = loadImage("3.png");
  img14 = loadImage("4.png");
  img15 = loadImage("5.png");
  img16 = loadImage("6.png");
  img17 = loadImage("7.png");
  img18 = loadImage("8.png");
  img19 = loadImage("9.png");
  minim = new Minim(this);
  player = minim.loadFile("Lala.mp3", 2048);
  player.play();
  t1=0;
  t2=0;
  control=0;
  start=0;
  score=0;
  health=10;
  h1=0;
  n1=0;
  n2=0;
  n3=0;
  n4=0;
  n5=0;
  nu1=10;
  nu2=100;
  nu3=1000;
  nu4=10000;
  nu5=100000;
  keys=0;
  ground=0;
  time=1;
  speed=1.5;
  leap = new LeapMotion(this);
  leap = new LeapMotion(this).withGestures();
  centerx=400;
  centery=300;
  count=0;
}

void draw() {
  if (health==0)ground=1;
 
  if (ground!=0)background(img2);
  //image(img1, 0, 510, 800, 100);
  if (ground==0) {


    int fps = leap.getFrameRate();
    for (Hand hand : leap.getHands ()) {
      //hand.draw();
      int     hand_id          = hand.getId();
      PVector hand_position    = hand.getPosition();

      int n=hand.countFingers();

      if (keys==0)
        if (hand_position.x>=300&&hand_position.x<=500&&hand_position.y>=225&&hand_position.y<=375)
        {
          keys=1;
        }
      if (hand_position.x>=300&&hand_position.x<=500&&hand_position.y<=375)
      {
        centerx=hand_position.x;
        centery=hand_position.y;
        image(fly, centerx, centery, 60, 60);
        background(img3);
        } else background(img4);
        if (keys==1)
        {
          if (hand_position.y>=375) {
            control=1;
            keys=0;
          }
          if (hand_position.x<=300) {
            control=2;
            keys=0;
          }
          if (hand_position.x>=500) {
            control=3;
            keys=0;
          }
        }
      println("x:" + hand_position.x + " Y:" + hand_position.y + "   +   " + control);
    }
    for (int i=1; i<=health; i++) {
      image(img7, 790-i*50, 10, 50, 50);
    }

    if (control>=1&&control<=3) {
      for (int i=0; i<50; i++)
      {
        if (control==1)
          if (pointY[i]>=470&&pointY[i]<=570&&ran[i]==1) {
            ran[i]=0;
            score+=speed*10;
            h1=1;
            control=0;
          }
        if (control==2)
          if (pointY[i]>=470&&pointY[i]<=570&&ran[i]==2) {
            ran[i]=0;
            score+=speed*10;
            h1=1;
            control=0;
          }
        if (control==3)
          if (pointY[i]>=470&&pointY[i]<=570&&ran[i]==3) {
            ran[i]=0;
            score+=speed*10;
            h1=1;
            control=0;
          }
      }

      if (h1==0)health--;
      control=0;
      h1=0;
    }


    t1=0;
    for (int i=0; i<50; i++)
      if (pointY[i]<=100&&pointY[i]>=0)t1=1;

    if (t1==1)t2=1;
    else t2=0;

    if (t2==0)
    {
      if(start==50)start=0;
      ran[start]=int(random(1, 5));
      pointY[start]=0;
      start++;
    }
    for (int i=0; i<50; i++)
    {
      if (ran[i]==1)image(down, 350, pointY[i], 80, 80);
      if (ran[i]==2)image(left, 200, pointY[i], 80, 80);
      if (ran[i]==3)image(right, 500, pointY[i], 80, 80);
    }

    for (int i=0; i<50; i++)
      if (ran[i]>=1&&ran[i]<=5)pointY[i]+=speed;
  }
if(score>=9999)background(img);

  for (int i=0; i<50; i++)
    if (ran[i]>=1&&ran[i]<=3&&pointY[i]==600) {
      ran[i]=0;
      health--;
    }
  n1=score%nu1;
  n2=score%nu2/10;
  n3=score%nu3/100;
  n4=score%nu4/1000;

  if (n1==0)image(img10, 140, 10, 40, 40);
  if (n1==1)image(img11, 140, 10, 40, 40);
  if (n1==2)image(img12, 140, 10, 40, 40);
  if (n1==3)image(img13, 140, 10, 40, 40);
  if (n1==4)image(img14, 140, 10, 40, 40);
  if (n1==5)image(img15, 140, 10, 40, 40);
  if (n1==6)image(img16, 140, 10, 40, 40);
  if (n1==7)image(img17, 140, 10, 40, 40);
  if (n1==8)image(img18, 140, 10, 40, 40);
  if (n1==9)image(img19, 140, 10, 40, 40);


  if (n2==0)image(img10, 100, 10, 40, 40);
  if (n2==1)image(img11, 100, 10, 40, 40);
  if (n2==2)image(img12, 100, 10, 40, 40);
  if (n2==3)image(img13, 100, 10, 40, 40);
  if (n2==4)image(img14, 100, 10, 40, 40);
  if (n2==5)image(img15, 100, 10, 40, 40);
  if (n2==6)image(img16, 100, 10, 40, 40);
  if (n2==7)image(img17, 100, 10, 40, 40);
  if (n2==8)image(img18, 100, 10, 40, 40);
  if (n2==9)image(img19, 100, 10, 40, 40);



  if (n3==0)image(img10, 60, 10, 40, 40);
  if (n3==1)image(img11, 60, 10, 40, 40);
  if (n3==2)image(img12, 60, 10, 40, 40);
  if (n3==3)image(img13, 60, 10, 40, 40);
  if (n3==4)image(img14, 60, 10, 40, 40);
  if (n3==5)image(img15, 60, 10, 40, 40);
  if (n3==6)image(img16, 60, 10, 40, 40);
  if (n3==7)image(img17, 60, 10, 40, 40);
  if (n3==8)image(img18, 60, 10, 40, 40);
  if (n3==9)image(img19, 60, 10, 40, 40);


  if (n4==0)image(img10, 20, 10, 40, 40);
  if (n4==1)image(img11, 20, 10, 40, 40);
  if (n4==2)image(img12, 20, 10, 40, 40);
  if (n4==3)image(img13, 20, 10, 40, 40);
  if (n4==4)image(img14, 20, 10, 40, 40);
  if (n4==5)image(img15, 20, 10, 40, 40);
  if (n4==6)image(img16, 20, 10, 40, 40);
  if (n4==7)image(img17, 20, 10, 40, 40);
  if (n4==8)image(img18, 20, 10, 40, 40);
  if (n4==9)image(img19, 20, 10, 40, 40);
  //println(speed);
  time++;
  if (time%500==0)speed+=0.5;
  //println("x:" + hand_position.x + " Y:" + hand_position.y);
}
//490 560

//void keyPressed() {
/*if (key=='s') control=1;
 if (key=='a') control=2;
 if (key=='d') control=3;
 */
// if (key=='s') keys=0;
// else keys=1;
//}

/*
void leapOnSwipeGesture(SwipeGesture g, int state) {
 int     id               = g.getId();
 Finger  finger           = g.getFinger();
 PVector position         = g.getPosition();
 PVector position_start   = g.getStartPosition();
 PVector direction        = g.getDirection();
 float   aspeed            = g.getSpeed();
 long    duration         = g.getDuration();
 float   duration_seconds = g.getDurationInSeconds();


 switch(state) {
 case 1:  // Start
 break;
 case 2: // Update
 break;
 case 3: // Stop
 println("SwipeGesture: "+id);
 // if (keys==0){  
 if (position.y-position_start.y<position.x-position_start.x) {  
 if (position.x>position_start.x) {
 control = 3;
 println("right");
 } else if (position.x<position_start.x)
 {
 control = 1;
 println("left");
 }
 } else if (position.y>position_start.y) {
 control = 2;
 println("down");
 }
 //  }
 }
 }
 */

2015年3月30日 星期一

第六週




碰撞測試



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)); } int grade=0; float grabX=0, grabY=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); }

2015年3月23日 星期一

期中作業設計:手指頭跳舞機

分組:洪詩庭 張芷瑜
題目:手指頭跳舞機





上圖為大概的設計界面(圖是網路上找的)
設計理念是會有音樂播放,然後會有箭頭落下。依落下的方向用手揮動來代表上下左右。
如果對的話一個箭頭得十分;錯的話一個箭頭扣五分;若都沒有動則不會得分。



第五週



用滑鼠畫畫:


int []X=new int[1000];
int []Y=new int[1000];
int now=0;
void setup(){
  size(800,800,P3D);
}
void draw(){
  background(255);
  for(int i=1;i<now;i++){
    line(X[i],Y[i],X[i-1],Y[i-1]);
  }
}
void mouseDragged(){
  X[now]=mouseX;
  Y[now]=mouseY;
  now++;
}

2015年3月9日 星期一

第二週


畫出手掌中心。
(先去Sketch>Library>Add librar,然後下載Leap Motion)
(下載好之後,去File>Example,打開e1_basic)

程式碼:
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
  size(600,600, P3D);
  leap = new LeapMotion(this);
}
void draw(){
  background(255);
  for(Hand hand : leap.getHands()){
    hand.draw();
    PVector pos=hand.getPosition();
    translate(pos.x, pos.y);
    fill(255,0,0); box(50);
  }
}


-------------------------------------------------------------------------------------------------------------------------





畫出手指的關節。


程式碼:
import de.voidplus.leapmotion.*;
LeapMotion leap;

void setup(){
  size(800,600,P3D);
  leap=new LeapMotion(this);
}

void draw(){
  background(255);
  for(Hand hand : leap.getHands()){
    hand.draw();
    myDraw(hand.getPosition());
    myDraw(hand.getThumb().getPosition());
    myDraw(hand.getIndexFinger().getPosition());
    myDraw(hand.getMiddleFinger().getPosition());
    myDraw(hand.getRingFinger().getPosition());
    myDraw(hand.getPinkyFinger().getPosition());
  }
}

void myDraw(PVector pos){
  pushMatrix();
  translate(pos.x, pos.y);
  fill(255, 0 , 0); sphere(20);
  popMatrix();
}


-------------------------------------------------------------------------------------------------------------------------





畫出可以用手操控就能讓方塊旋轉的...操控。


程式碼:
import de.voidplus.leapmotion.*;
LeapMotion lp;

void setup(){
  size(800,600,P3D);
  lp=new LeapMotion(this);
}
void draw(){
 background(255);
  for(Hand hand :lp.getHands()){
    println("yaw:"+hand.getYaw());
    pushMatrix();
    translate(400,400);
    rotateY(-radians(hand.getYaw()));
    stroke(0);
    fill(0,100,50);
    box(100);
    popMatrix();
 
 
 
    hand.draw();
    myDraw(hand.getPosition());
    myDraw(hand.getThumb().getPosition());
    myDraw(hand.getIndexFinger().getPosition());
    myDraw(hand.getMiddleFinger().getPosition());
    myDraw(hand.getRingFinger().getPosition());
    myDraw(hand.getPinkyFinger().getPosition());
}
}
void myDraw(PVector pos){
  pushMatrix();
  translate(pos.x,pos.y);
  fill(255,0,255);sphere(20);
  popMatrix();
}









2015年3月2日 星期一

第一週

 第一週進度為體驗LeepMotion;

https://drive.google.com/file/d/0ByYbu0zjxrp1NVNfb1NGMDB6X2c/view?usp=sharing
>解壓縮




























寫出簡短的能偵測到十根手指頭的小程式。
程式碼如下:














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

void draw()
{
  background(255);
  for(Hand hand : lp.getHands())
 {
     hand.draw();
  }
}