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

86 lines
2.4 KiB
Java

/* autogenerated by Processing revision 1292 on 2023-07-12 */
import processing.core.*;
import processing.data.*;
import processing.event.*;
import processing.opengl.*;
import redis.clients.jedis.Jedis;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.ArrayList;
import java.io.File;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
public class mousedot extends PApplet {
ArrayList<PVector> points = new ArrayList<PVector>();
public int rgb2int(int r, int g, int b) {
return (r << 16) + (g << 8) + b;
}
public void setup() {
/* size commented out by preprocessor */;
}
public 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();
}
}
public void settings() { size(640, 360); }
static public void main(String[] passedArgs) {
String[] appletArgs = new String[] { "--full-screen", "--bgcolor=#666666", "--stop-color=#cccccc", "mousedot" };
if (passedArgs != null) {
PApplet.main(concat(appletArgs, passedArgs));
} else {
PApplet.main(appletArgs);
}
}
}