Hello dear community,
I made a grid of spinning lines. Now I wonder how to know when a line and is neighbours are matching in the vertical or horizontal axis to change theris colors for that moment in which the share the same position.
Here is the code I have so far for better understanding of what I need to accomplish.
Many thanks in advance!
Pulsar[] pulsars;
int columns = 5;
int rows = 5;
int total = columns*rows;
float stepX, stepY;
void setup() {
size(500, 500);
strokeWeight(2);
stepX = width/ columns;
stepY = height/ rows;
pulsars = new Pulsar[total];
int index = 0;
for (int j = 0; j < rows; j++) {
for (int i = 0; i < columns; i++) {
// Arrange lines in a grid
pulsars[index] = new Pulsar(i * stepX + (stepX/2), j * stepY + (stepY/2));
// update counter
index ++;
//reset counter
if (index == total) index = 0;
}
}
}
void draw() {
background(10);
int index = 0;
for (int j = 0; j < rows; j++) {
for (int i = 0; i < columns; i++) {
// new velocity for every line
float vel = (index + 1) * 0.003;
stroke(255);
pulsars[index].display(vel);
// update counter
index ++;
//reset counter
if (index == total) index = 0;
}
}
}
// ROTATING OBJECT
class Pulsar {
float posX, posY, vel;
float angle = 0;
Pulsar(float posX_, float posY_) {
posX = posX_;
posY = posY_;
}
void display(float vel) {
pushMatrix();
translate(posX, posY);
rotate(angle);
// draw forms
ellipse(0, 0, 4, 4);
line(-width/(rows*2), 0, height/(rows*2), 0);
// uopdate angle
angle += vel;
popMatrix();
}
}