LeapShodou (LeapMotion で書道?)
Post date: 2013/11/05 7:33:39
import com.onformative.leap.LeapMotionP5;
float colR=0, colG=0, colB=0;
LeapMotionP5 leap;
PVector fp;
PVector pfp;
void setup() {
size(800, 800);
leap = new LeapMotionP5(this);
background(191);
fp = leap.getTip(leap.getFinger(0));
pfp=fp;
}
void draw() {
fp = leap.getTip(leap.getFinger(0));
float thickness = 20 - fp.dist(pfp);
println("thickness="+thickness);
if(thickness > 0) {
strokeWeight(thickness);
stroke(colR, colG, colB);
line(pfp.x,pfp.y,fp.x,fp.y);
}
pfp=fp;
}
public void stop() {
leap.stop();
}
void keyPressed() {
switch(key) {
case ' ':
background(191);
break;
case 'r': // Red
colR=255; colG=0; colB=0;
break;
case 'w': // White
colR=255; colG=255; colB=255;
break;
case 'k': // Black
colR=0; colG=0; colB=0;
break;
}
}