太鼓達人 Processing + Arduino
1. 複習接金幣
2. 陣列、存檔、成績排名 sort
3. 剪刀石頭布!
4. 3D畫畫過程
PVector pt;
ArrayList<PVector>history;
void setup(){
size(600, 300, P3D);
background(255);
pt = new PVector(width/2, height/2);
history = new ArrayList<PVector>(0);
}
void draw(){
for(PVector nowPt : history){
ellipse(nowPt.x, nowPt.y , 2,2);
}
}
void mouseMoved(){
history.add(new PVector(mouseX,mouseY));
}
import de.voidplus.leapmotion.*;
LeapMotion leap;
PVector pt;
ArrayList<PVector>history1;
ArrayList<PVector>history2;
ArrayList<PVector>history3;
ArrayList<PVector>history4;
ArrayList<PVector>history5;
void setup(){
size(600, 300, P3D);
background(255);
leap = new LeapMotion(this);
pt = new PVector(width/2, height/2);
history1 = new ArrayList<PVector>(0);
history2 = new ArrayList<PVector>(0);
history3 = new ArrayList<PVector>(0);
history4 = new ArrayList<PVector>(0);
history5 = new ArrayList<PVector>(0);
}
void draw(){
for(PVector nowPt : history1){
fill(255,0,0); stroke(0);
ellipse(nowPt.x, nowPt.y , 10,10);
}
for(PVector nowPt : history2){
fill(255,0,0); stroke(0);
ellipse(nowPt.x, nowPt.y , 10,10);
}
for(PVector nowPt : history3){
fill(255,0,0); stroke(0);
ellipse(nowPt.x, nowPt.y , 10,10);
}
for(PVector nowPt : history4){
fill(255,0,0); stroke(0);
ellipse(nowPt.x, nowPt.y , 10,10);
}
for(PVector nowPt : history5){
fill(255,0,0); stroke(0);
ellipse(nowPt.x, nowPt.y , 10,10);
}
for(Hand hand : leap.getHands() ){
hand.draw();
Finger finger = hand.getThumb();
Finger finger2 = hand.getIndexFinger();
Finger finger3 = hand.getMiddleFinger();
Finger finger4 = hand.getRingFinger();
Finger finger5 = hand.getPinkyFinger();
PVector pos;
pos = finger.getPosition();
history1.add(new PVector(pos.x,pos.y));
history2.add(new PVector(pos.x,pos.y));
history3.add(new PVector(pos.x,pos.y));
history4.add(new PVector(pos.x,pos.y));
history5.add(new PVector(pos.x,pos.y));
}
}
import de.voidplus.leapmotion.*;
LeapMotion leap;
PVector pt;
ArrayList<PVector> history;
ArrayList<PVector> history2;
ArrayList<PVector> history3;
ArrayList<PVector> history4;
ArrayList<PVector> history5;
void setup() {
size(640, 480, P3D);//Need P3D 3D function (ball, translate, rotate, pushMatrix,popMatrix)
leap=new LeapMotion(this);
pt=new PVector(width/2, height/2);
history=new ArrayList<PVector>(0);
history2=new ArrayList<PVector>(0);
history3=new ArrayList<PVector>(0);
history4=new ArrayList<PVector>(0);
history5=new ArrayList<PVector>(0);
}
void myBall(float x, float y, float z) {
pushMatrix();//backup translate/rotate matrix
translate(x, y, z*10);// z need to be x10
sphere(10);
popMatrix();//restore the translate/rotate matrix
}
void draw() {
background(255);
lights();// lighs will let 3D ball to look like 3D
translate(width/2, height/2);//This 3 lines (Translate, rotate, translate)
rotateY(radians(frameCount));// can let the balls rotating in the center of screen
translate(-width/2, -height/2);//
noStroke();
for (PVector nowPt : history) {
fill(255, 0, 0);
myBall(nowPt.x, nowPt.y, nowPt.z);
}
for (PVector nowPt : history2) {
fill(255, 255, 0);
myBall(nowPt.x, nowPt.y, nowPt.z);
}
for (PVector nowPt : history3) {
fill(0, 255, 0);
myBall(nowPt.x, nowPt.y, nowPt.z);
}
for (PVector nowPt : history4) {
fill(0, 0, 255);
myBall(nowPt.x, nowPt.y, nowPt.z);
}
for (PVector nowPt : history5) {
fill(255, 0, 255);
myBall(nowPt.x, nowPt.y, nowPt.z);
}
for ( Hand hand : leap.getHands() ) {
hand.draw();
Finger finger = hand.getThumb();
Finger finger2 = hand.getIndexFinger();
Finger finger3 = hand.getMiddleFinger();
Finger finger4 = hand.getRingFinger();
Finger finger5 = hand.getPinkyFinger();
PVector pos;
pos= finger.getPosition();
history.add(new PVector(pos.x, pos.y, pos.z));
pos = finger2.getPosition();
history2.add(new PVector(pos.x, pos.y, pos.z));
pos = finger3.getPosition();
history3.add(new PVector(pos.x, pos.y, pos.z));
pos = finger4.getPosition();
history4.add(new PVector(pos.x, pos.y, pos.z));
pos = finger5.getPosition();
history5.add(new PVector(pos.x, pos.y, pos.z));
}
}
//void mouseMoved(){
// history.add(new PVector(mouseX, mouseY));
//}
中心校正
import de.voidplus.leapmotion.*;
LeapMotion leap;
PVector pt;
ArrayList<PVector> history;
ArrayList<PVector> history2;
ArrayList<PVector> history3;
ArrayList<PVector> history4;
ArrayList<PVector> history5;
void setup() {
size(640, 480, P3D);//Need P3D 3D function (ball, translate, rotate, pushMatrix,popMatrix)
leap=new LeapMotion(this);
pt=new PVector(width/2, height/2);
history=new ArrayList<PVector>(0);
history2=new ArrayList<PVector>(0);
history3=new ArrayList<PVector>(0);
history4=new ArrayList<PVector>(0);
history5=new ArrayList<PVector>(0);
float max=999, min=0;
}
void myBall(float x, float y, float z) {
pushMatrix();//backup translate/rotate matrix
translate(x, y, z*4);// z need to be x10
sphere(10);
popMatrix();//restore the translate/rotate matrix
}
void draw() {
background(255);
lights();// lighs will let 3D ball to look like 3D
translate(width/2, height/2, 50);//This 3 lines (Translate, rotate, translate)
rotateY(radians(frameCount));// can let the balls rotating in the center of screen
translate(-width/2, -height/2);//
noStroke();
for (PVector nowPt : history) {
fill(255, 0, 0);
myBall(nowPt.x, nowPt.y, nowPt.z);
}
for (PVector nowPt : history2) {
fill(255, 255, 0);
myBall(nowPt.x, nowPt.y, nowPt.z);
}
for (PVector nowPt : history3) {
fill(0, 255, 0);
myBall(nowPt.x, nowPt.y, nowPt.z);
}
for (PVector nowPt : history4) {
fill(0, 0, 255);
myBall(nowPt.x, nowPt.y, nowPt.z);
}
for (PVector nowPt : history5) {
fill(255, 0, 255);
myBall(nowPt.x, nowPt.y, nowPt.z);
}
for ( Hand hand : leap.getHands() ) {
hand.draw();
Finger finger = hand.getThumb();
Finger finger2 = hand.getIndexFinger();
Finger finger3 = hand.getMiddleFinger();
Finger finger4 = hand.getRingFinger();
Finger finger5 = hand.getPinkyFinger();
PVector pos;
pos= finger.getPosition();
history.add(new PVector(pos.x, pos.y, pos.z));
pos = finger2.getPosition();
history2.add(new PVector(pos.x, pos.y, pos.z));
pos = finger3.getPosition();
history3.add(new PVector(pos.x, pos.y, pos.z));
pos = finger4.getPosition();
history4.add(new PVector(pos.x, pos.y, pos.z));
pos = finger5.getPosition();
history5.add(new PVector(pos.x, pos.y, pos.z));
}
}
//void mouseMoved(){
// history.add(new PVector(mouseX, mouseY));
//}
沒有留言:
張貼留言