configure UI and more leapmotion examples

This commit is contained in:
Sam 2023-07-19 23:05:06 +02:00
parent 9b0c8ffc86
commit ebe188592e
4 changed files with 392 additions and 1 deletions

View file

@ -0,0 +1,54 @@
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();
}
}

View file

@ -0,0 +1,40 @@
import redis.clients.jedis.Jedis;
import java.util.ArrayList;
ArrayList<PVector> points = new ArrayList<PVector>();
int rgb2int(int[] rgb) {
return color(rgb[0], rgb[1], rgb[2]);
}
void setup() {
size(640, 360);
}
void draw() {
background(51);
stroke(255);
strokeWeight(2); // adjust the thickness of the circle outline
if (mousePressed) {
PVector p = new PVector(mouseX, mouseY);
points.add(p);
noFill(); // disable filling
ellipse(p.x, p.y, 10, 10); // draw a circle with lines at the point
}
if (points.size() > 0) {
String pointList = "[";
for (int i = 0; i < points.size(); i++) {
PVector p = points.get(i);
int[] rgb = {255, 255, 255};
pointList += "(" + p.x + "," + p.y + "," + rgb2int(rgb) + "),";
}
pointList = pointList.substring(0, pointList.length() - 1); // remove the last comma
pointList += "]";
System.out.println(pointList);
Jedis jedis = new Jedis("localhost");
jedis.set("/pl/0/0", pointList);
jedis.close();
}
}

View file

@ -8,7 +8,7 @@ int rgb2int(int r, int g, int b) {
}
void setup() {
size(640, 360);
size(400, 200);
noStroke();
rectMode(CENTER);
}
@ -29,6 +29,7 @@ void draw() {
points.add(new PVector(mouseX-rect1Width/2, height/2-rect1Height/2));
points.add(new PVector(mouseX+rect1Width/2, height/2-rect1Height/2));
points.add(new PVector(mouseX+rect1Width/2, height/2+rect1Height/2));
points.add(new PVector(mouseX-rect1Width/2, height/2+rect1Height/2));
points.add(new PVector(mouseX-rect1Width/2, height/2-rect1Height/2));
// Draw second rectangle using lines
int inverseX = width-mouseX;
@ -43,6 +44,7 @@ void draw() {
points.add(new PVector(inverseX+rect2Width/2, height/2-rect2Height/2));
points.add(new PVector(inverseX+rect2Width/2, height/2+rect2Height/2));
points.add(new PVector(inverseX-rect2Width/2, height/2+rect2Height/2));
points.add(new PVector(inverseX-rect2Width/2, height/2-rect2Height/2));
if (points.size() > 0) {
println("point size : "+points.size());
println("pointlist");