2016年3月3日 星期四

02160323_week02_class


PVector [] pt = new PVector[10];

void setup(){

size(640,480,P3D);

for(int i=0;i<10;i++)

pt[i]= new PVector(0,0,0); //設一個陣列

}

void draw(){

background(0); // 把滑鼠之前畫出來的過程用背景清除

stroke(#38E5FA);

for(int i=9;i>0;i--){ pt[i].x=pt[i-1].x;pt[i].y=pt[i-1].y;}

pt[0].x=mouseX; // 陣列裡面存滑鼠作標

pt[0].y=mouseY;

for(int i=1;i<10;i++)

line(pt[i].x,pt[i].y,pt[i].z,pt[i-1].x,pt[i-1].y,pt[i-1].z); // 把之前的滑鼠作標換到新的座標

}
先用滑鼠作出滑動會有殘影的效果

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











import de.voidplus.leapmotion.*;

LeapMotion leap;

PVector [] pt=new PVector[10];

void setup()

{

 size(600, 800, P3D);

for (int i=0; i<10; i++)

pt[i]=new PVector(0, 0, 0);

leap = new LeapMotion(this);

}

void draw()

{

background(0);

stroke(255, 25, 10);

//line(mouseX,mouseY,pmouseX,pmouseY);

for (int i=9; i>0; i--)

{

pt[i].x=pt[i-1].x;

pt[i].y=pt[i-1].y;

}

for (Hand hand : leap.getHands ()) {

for (Finger finger : hand.getFingers ()) {          //加入leapmotion用食指畫出線條

switch(finger.getType()) {

case 1:

PVector now = finger.getPosition();

pt[0].x=now.x;

pt[0].y=now.y;

break;

}

}

}

for (int i=1; i<10; i++)

line(pt[i].x, pt[i].y, pt[i].z, pt[i-1].x, pt[i-1].y, pt[i-1].z);      //依然有殘影

}

用手指作出滑動會有殘影的效果

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



import de.voidplus.leapmotion.*;

LeapMotion leap;

PVector [][] pt=new PVector[5][100];//因為不能讓線一下就消失,增加陣列

void setup()

{

size(600, 800, P3D);

for(int f=0;f<5;f++){

for (int i=0; i<100; i++)

pt[f][i]=new PVector(0, 0, 0);

}

leap = new LeapMotion(this);

colorMode(HSB,100);       //增加漸層顏色

}

void draw()

{

background(0);

stroke(255, 25, 10);

//line(mouseX,mouseY,pmouseX,pmouseY);

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[0].x=mouseX;

pt[f][0].y=now.y;//pt[0].y=mouseY;

}

}

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);

}

}

今天上課最後一個作業
偵測出五根手指頭
然後加入漸層顏色
可以在空中畫出像仙女棒的效果!!
棒棒

沒有留言:

張貼留言