LJ/examples/Processing/mousedot/macos-x86_64/source/mousedot.pde

53 lines
1.5 KiB
Plaintext
Raw Normal View History

2023-07-16 23:22:27 +00:00
import redis.clients.jedis.Jedis;
import java.util.ArrayList;
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);
}
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);
}
if (points.size() > 0) {
println("point size : "+points.size());
println("pointlist");
String pointList = "["; // initialize the point list string
for (int i = 0; i < points.size(); i++) {
PVector center = points.get(i);
int[] rgb = {254, 254, 254};
for (int j = 0; j < 150; j++) {
float angle = map(j, 0, 150, 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, 150, 0, TWO_PI)) * 10;
float prevY = center.y + sin(map(j - 1, 0, 150, 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
println("point size : "+points.size());
println("pointlist");
System.out.println(pointList);
Jedis jedis = new Jedis("localhost");
jedis.set("/pl/0/0", pointList);
jedis.close();
}
}