LJ/examples/Processing/leapdots/mousedot1066692289283837873...

41 lines
1.0 KiB
Plaintext

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();
}
}