xxxxxxxxxx
int w = 120;
int cols = 0, rows = 0;
float angle = 0;
boolean saved = false;
Curve[][] curves;
void setup() {
fullScreen(P2D);
cols = width / w - 1;
rows = height / w - 2;
curves = new Curve[cols][rows];
for(int x = 0; x < cols; x++) {
for(int y = 0; y < rows; y++) {
curves[x][y] = new Curve();
}
}
}
void draw() {
noFill();
background(0);
float d = w - 10;
float rad = d / 2;
for(int c = 0; c < cols; c++) {
for(int r = 0; r < rows; r++) {
float cx = w + c * w + w / 2;
float cy = w / 2;
stroke(255);
strokeWeight(1);
ellipse(cx, cy, d, d);
stroke(255, 0, 0, 255);
strokeWeight(8);
float x = cx + rad * cos((c + 1) * angle - PI / 2);
float y = cy + rad * sin((c + 1)* angle - PI / 2);
point(x, y);
strokeWeight(1);
stroke(255, 0, 0, 10);
line(x, 0, x, height);
curves[c][r].setX(x);
}
}
for(int c = 0; c < cols; c++) {
for(int r = 0; r < rows; r++) {
float cx = w / 2;
float cy = w + r * w + w / 2;
stroke(255);
strokeWeight(1);
ellipse(cx, cy, d, d);
stroke(255, 0, 0, 255);
strokeWeight(8);
float x = cx + rad * cos((r + 1) * angle - PI / 2);
float y = cy + rad * sin((r + 1)* angle - PI / 2);
point(x, y);
strokeWeight(1);
stroke(255, 0, 0, 10);
line(0, y, width, y);
curves[c][r].setY(y);
}
}
for(int i = 0; i < cols; i++) {
for(int j = 0; j < rows; j++) {
curves[i][j].addPoint();
curves[i][j].show();
}
}
angle += 0.01;
if(angle >= TWO_PI) {
save("lissajous_" + w + ".png");
noLoop();
}
}
void mousePressed() {
for(int i = 0; i < cols; i++) {
for(int j = 0; j < rows; j++) {
curves[i][j].reset();
}
}
angle = 0;
loop();
}