LJ/examples/Processing/leapdots/leapdots.pde
2024-08-15 17:04:23 +02:00

55 lines
1.7 KiB
Plaintext

import redis.clients.jedis.Jedis;
import java.util.ArrayList;
import com.onformative.leap.LeapMotionP5;
import com.leapmotion.leap.Finger;
LeapMotionP5 leap;
ArrayList<PVector> points = new ArrayList<PVector>();
int rgb2int(int r, int g, int b) {
return (r << 16) + (g << 8) + b;
}
void setup() {
size(640, 360);
leap = new LeapMotionP5(this);
}
void draw() {
background(51);
stroke(255);
strokeWeight(2); // adjust the thickness of the circle outline
for (Finger finger : leap.getFingerList()) {
PVector fingerPos = leap.getTip(finger);
points.add(fingerPos);
}
if (points.size() > 0) {
String pointList = "["; // initialize the point list string
for (int i = 0; i < points.size(); i++) {
PVector center = points.get(i);
pointList += "(" + center.x + "," + center.y + ",0),";
int[] rgb = {254, 254, 254};
for (int j = 0; j < 15; j++) { // Update the loop to generate 30 points per circle
float angle = map(j, 0, 15, 0, TWO_PI);
float x = center.x + cos(angle) * 5;
float y = center.y + sin(angle) * 5;
pointList += "(" + x + "," + y + "," + rgb2int(rgb[0], rgb[1], rgb[2]) + "),";
if (j > 0) {
float prevX = center.x + cos(map(j - 1, 0, 15, 0, TWO_PI)) * 10;
float prevY = center.y + sin(map(j - 1, 0, 15, 0, TWO_PI)) * 10;
line(prevX, prevY, x, y);
}
}
}
points.clear();
pointList = pointList.substring(0, pointList.length() - 1); // remove the last comma
pointList += "]"; // close the point list string
//System.out.println(pointList);
Jedis jedis = new Jedis("localhost");
jedis.set("/pl/0/0", pointList);
jedis.close();
}
}