上課拉!
期中作品=>排球撞擊遊戲!
今天要把手變3D的!!!
複習上週2D的手!
import de.voidplus.leapmotion.*;LeapMotion leap;
PVector [][] pt=new PVector[5][100];
void setup(){
size(640,480,P3D);//視窗大小(前面不能有程式!會有錯誤!)
for(int f=0;f<5;f++){ //五隻手指頭
for(int i=0;i<100;i++) //每隻手指頭有100個點
pt[f][i]=new PVector(0,0,0);
}
leap=new LeapMotion(this);
colorMode(HSB,100);
}
void draw(){
background(0);
stroke(#63F0E5);
for(int f=0;f<5;f++){
for(int i=99;i>0;i--){ pt[f][i].x=pt[f][i-1].x; pt[f][i].y=pt[f][i-1].y;}
}
for(Hand hand:leap.getHands()){
for(Finger finger:hand.getFingers()){
int f=finger.getType();
PVector now=finger.getPosition();
pt[f][0].x=now.x;
pt[f][0].y=now.y;
}
}
for(int f=0;f<5;f++){
stroke(f*20,100,100);
for(int i=1;i<100;i++)
line(pt[f][i].x,pt[f][i].y,pt[f][i].z,pt[f][i-1].x,pt[f][i-1].y,pt[f][i-1].z);
}
}
要變3D拉!!!!
import de.voidplus.leapmotion.*;
LeapMotion leap;
PVector [][] pt=new PVector[5][100];
void setup(){
size(640,480,P3D);//視窗大小(前面不能有程式!會有錯誤!)
for(int f=0;f<5;f++){ //五隻手指頭
for(int i=0;i<100;i++) //每隻手指頭有100個點
pt[f][i]=new PVector(0,0,0);
}
leap=new LeapMotion(this);
colorMode(HSB,100);
}
void draw(){
background(0);
stroke(#63F0E5);
for(int f=0;f<5;f++){
for(int i=99;i>0;i--){ pt[f][i].x=pt[f][i-1].x; pt[f][i].y=pt[f][i-1].y;}
}
for(Hand hand:leap.getHands()){
for(Finger finger:hand.getFingers()){
int f=finger.getType();
PVector now=finger.getPosition();
pt[f][0].x=now.x;
pt[f][0].y=now.y;
if(f==1) println(now);
}
}
translate(width/2,height/2);
rotateY(radians(frameCount));
translate(-width/2,-height/2);
for(int f=0;f<5;f++){
stroke(f*20,100,100);
for(int i=1;i<100;i++)
line(pt[f][i].x,pt[f][i].y,pt[f][i].z,pt[f][i-1].x,pt[f][i-1].y,pt[f][i-1].z);
}
}
LeapMotion leap;
PVector [][] pt=new PVector[5][100];
void setup(){
size(640,480,P3D);//視窗大小(前面不能有程式!會有錯誤!)
for(int f=0;f<5;f++){ //五隻手指頭
for(int i=0;i<100;i++) //每隻手指頭有100個點
pt[f][i]=new PVector(0,0,0);
}
leap=new LeapMotion(this);
colorMode(HSB,100);
}
void draw(){
background(0);
stroke(#63F0E5);
for(int f=0;f<5;f++){
for(int i=99;i>0;i--){ pt[f][i].x=pt[f][i-1].x; pt[f][i].y=pt[f][i-1].y;}
}
for(Hand hand:leap.getHands()){
for(Finger finger:hand.getFingers()){
int f=finger.getType();
PVector now=finger.getPosition();
pt[f][0].x=now.x;
pt[f][0].y=now.y;
if(f==1) println(now);
}
}
translate(width/2,height/2);
rotateY(radians(frameCount));
translate(-width/2,-height/2);
for(int f=0;f<5;f++){
stroke(f*20,100,100);
for(int i=1;i<100;i++)
line(pt[f][i].x,pt[f][i].y,pt[f][i].z,pt[f][i-1].x,pt[f][i-1].y,pt[f][i-1].z);
}
}
import de.voidplus.leapmotion.*;
LeapMotion leap;
PVector [][] pt=new PVector[5][100];
void setup(){
size(640,480,P3D);//視窗大小(前面不能有程式!會有錯誤!)
for(int f=0;f<5;f++){ //五隻手指頭
for(int i=0;i<100;i++) //每隻手指頭有100個點
pt[f][i]=new PVector(0,0,0);
}
leap=new LeapMotion(this);
colorMode(HSB,100);
}
void draw(){
background(0);
stroke(#63F0E5);
for(int f=0;f<5;f++){
for(int i=99;i>0;i--){ pt[f][i].x=pt[f][i-1].x; pt[f][i].y=pt[f][i-1].y;}
}
for(Hand hand:leap.getHands()){
for(Finger finger:hand.getFingers()){
int f=finger.getType();
PVector now=finger.getPosition();
pt[f][0].x=now.x;
pt[f][0].y=now.y;
if(f==1) println(now);
}
}
translate(width/2,height/2);
rotateY(radians(frameCount));
translate(-width/2,-height/2);
for(int f=0;f<5;f++){
for(int i=1;i<100;i++){
stroke(f*20,100,100);
line(pt[f][i].x,pt[f][i].y,pt[f][i].z,pt[f][i-1].x,pt[f][i-1].y,pt[f][i-1].z);
}
}
stroke(60,100,100);
for(int i=0;i<640;i+=20)
for(int j=0;j<480;j+=20) {
noFill();
rect(i,j,20,20);
}
}
挖賽!
調色盤欸!
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
size(640,480,P3D);
leap=new LeapMotion(this);
}
void draw(){
background(225);
for(Hand hand :leap.getHands()){
PVector pos=hand.getPosition();
if(hand.isLeft()){
ellipse(pos.x,pos.y,200,100);
}else if(hand.isRight()){
rect(pos.x,pos.y,10,100);
}
}
}
目前還沒加上顏色!
挖賽!可以調色欸!
可是有點bug,就是要先左手在右手拉哈哈
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
size(640,480,P3D);
leap=new LeapMotion(this);
}
color nowColor=color(255,0,0);
PVector leftPos;
void draw(){
background(225);
for(Hand hand :leap.getHands()){
PVector pos=hand.getPosition();
if(hand.isLeft() ){
noFill(); ellipse(pos.x,pos.y,200,100);
fill(255,0,0); ellipse(pos.x+150,pos.y,60,50);
fill(255,255,0); ellipse(pos.x+120,pos.y-40,60,50);
fill(0,255,0); ellipse(pos.x+90,pos.y-60,60,50);
fill(0,0,255); ellipse(pos.x+30,pos.y-60,60,50);
fill(255,0,255); ellipse(pos.x-20,pos.y-60,60,50);
leftPos=pos;
}else if(hand.isRight()){
fill(nowColor); rect(pos.x,pos.y,10,100);
println(leftPos);
println(pos);
if(dist(pos.x,pos.y,leftPos.x+120,leftPos.y-40)<30){
nowColor=color(255,255,0);
}
}
}
}
沒有留言:
張貼留言