void setup(){
size(640,480);
}
void draw(){
line(mouseX, mouseY, pmouseX, pmouseY);
}
進一步做法,讓背景變黑色,線條有顏色
新增背景色 background(0);
線條有顏色 stroke(#F5AD1E); //顏色的代碼可進入Tools > Color Selector 選擇顏色
//PVector pt1, pt2, pt3, pt4, pt5, pt6, pt7, pt8, pt9, pt10;
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(#F5AD1E);
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);
}
利用LeapMotion控制一根手指頭畫出線條並有殘影
import de.voidplus.leapmotion.*;
LeapMotion leap;
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);
leap = new LeapMotion(this);
}
void draw(){
background(0);
stroke(#F5AD1E);
for(int i=9; i>0; i--){pt[i].x=pt[i-1].x; pt[i].y=pt[i-1].y;} //backup the old values
for(Hand hand : leap.getHands()){
for(Finger finger : hand.getFingers()){
switch(finger.getType()){
case 1: //System.out.println("index");
PVector now = finger.getPosition();
pt[0].x=now.x; //pt[0].x=mouseX;
pt[0].y=now.y; //pt[0].y=mouseY
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);
}
LeapMotion裝置控制五根手指頭畫出線條並有殘影效果
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++) pt[f][i] = new PVector(0,0,0);
}
leap = new LeapMotion(this);
colorMode(HSB,100);
}
void draw(){
background(0);
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);
}
}
沒有留言:
張貼留言