particle_system/mini_leap.pde

118 lines
2.2 KiB
Plaintext

import de.voidplus.leapmotion.*;
// ======================================================
// Table of Contents:
// ├─ 1. Callbacks
// ├─ 2. Hand
// ├─ 3. Arms
// ├─ 4. Fingers
// ├─ 5. Bones
// ├─ 6. Tools
// └─ 7. Devices
// ======================================================
LeapMotion leap;
LaserOut laser_frame;
int hand_id;
Attractor[] attractors = new Attractor[10];
Particle[] particles = new Particle[1];
PVector min_pos;
PVector max_pos;
boolean att_stdout;
void setup() {
size(800, 500);
background(0);
// ...
leap = new LeapMotion(this);
att_stdout = false;
boolean print_stdout = false;
laser_frame = new LaserOut(print_stdout);
// init_attractors
for (int i = 0; i < attractors.length; i++){
attractors[i] = new Attractor();
}
for (int i = 0; i < particles.length; i++){
particles[i] = new Particle(200); // number of previous position drawn
}
}
void disable_attractors(){
for (Attractor att : attractors){
att.is_active = false;
}
}
void draw_attractors(){
for (Attractor att : attractors){
if (att.is_active)
att.draw();
}
}
void draw_particles(){
for (Particle p : particles){
p.draw();
}
}
void particles_update_position(){
for (Particle p : particles){
p.update_position(attractors);
}
}
void draw() {
background(50);
// ...
int fps = leap.getFrameRate();
int i = 0;
int att_id;
for (Hand hand : leap.getHands ()) {
if (i >= 2)
{
println("\n\n\n\t\t !! MORE THAN 2 hands isn't implemented");
continue;
}
// --------------------------------------------------
// Drawing
// hand.draw();
// update attractors position and draw
att_id = i * 5 + 0; // 5 => number of finger
PVector pos = hand.getIndexFinger().getPositionOfJointDip();
attractors[att_id].update_pos(pos);
i++;
}
particles_update_position();
draw_attractors();
draw_particles();
laser_frame.print_frame(); // print frame on stdout
}
// println("finger_pos:", pos);
// // println("---");
// int j = 0;
// for (Finger finger : hand.getFingers()) {
//
// // update attractors position and draw
// att_id = i * 5 + j; // 5 => number of finger
// PVector pos = finger.getPosition();
// attractors[att_id].update_pos(pos);
// j++;
// }