particle_system/mini_leap.pde

135 lines
2.7 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;
PVector min_pos;
PVector max_pos;
boolean att_stdout;
void setup() {
size(800, 500);
background(0);
int particle_path_length = 20;
int nb_particle = 10;
boolean particle_stdout = true; // print particle on stdout
att_stdout = false; // print attroctor on stdout
// ...
leap = new LeapMotion(this);
particles = new Particle[nb_particle];
laser_frame = new LaserOut(particle_stdout);
// init_attractors
for (int i = 0; i < attractors.length; i++){
attractors[i] = new Attractor();
}
for (int i = 0; i < particles.length; i++){
if (particle_path_length > 0)
particles[i] = new Particle(particle_path_length); // number of previous position drawn
else
particles[i] = new Particle(); // no previous article
}
}
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);
int j = 0;
for (Finger finger : hand.getFingers()) {
att_id = i * 5 + j; // 5 => nunber of finger
PVector pos = finger.getPositionOfJointDip();
attractors[att_id].update_pos(pos);
j++;
}
i++;
}
particles_update_position();
draw_attractors();
draw_particles();
laser_frame.print_frame(); // print frame on stdout
disable_attractors();
}
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);
}
}
// 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++;
// }