easy examples in different languagess
This commit is contained in:
parent
e45ab18f5d
commit
9b0c8ffc86
224 changed files with 11562 additions and 133 deletions
65
examples/Processing/squares/squares.pde
Normal file
65
examples/Processing/squares/squares.pde
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
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);
|
||||
noStroke();
|
||||
rectMode(CENTER);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(51);
|
||||
stroke(255, 204);
|
||||
|
||||
// Draw first rectangle using lines
|
||||
noFill();
|
||||
|
||||
int rect1Width = mouseY/2+10;
|
||||
int rect1Height = mouseY/2+10;
|
||||
line(mouseX-rect1Width/2, height/2-rect1Height/2, mouseX+rect1Width/2, height/2-rect1Height/2);
|
||||
line(mouseX+rect1Width/2, height/2-rect1Height/2, mouseX+rect1Width/2, height/2+rect1Height/2);
|
||||
line(mouseX+rect1Width/2, height/2+rect1Height/2, mouseX-rect1Width/2, height/2+rect1Height/2);
|
||||
line(mouseX-rect1Width/2, height/2+rect1Height/2, 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;
|
||||
int inverseY = height-mouseY;
|
||||
int rect2Width = (inverseY/2)+10;
|
||||
int rect2Height = (inverseY/2)+10;
|
||||
line(inverseX-rect2Width/2, height/2-rect2Height/2, inverseX+rect2Width/2, height/2-rect2Height/2);
|
||||
line(inverseX+rect2Width/2, height/2-rect2Height/2, inverseX+rect2Width/2, height/2+rect2Height/2);
|
||||
line(inverseX+rect2Width/2, height/2+rect2Height/2, inverseX-rect2Width/2, height/2+rect2Height/2);
|
||||
line(inverseX-rect2Width/2, height/2+rect2Height/2, 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));
|
||||
points.add(new PVector(inverseX-rect2Width/2, height/2+rect2Height/2));
|
||||
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 p = points.get(i);
|
||||
int[] rgb = {255, 255, 255};
|
||||
pointList += "(" + p.x + "," + p.y + "," + rgb2int(rgb[0], rgb[1], rgb[2]) + "),";
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue