Hello everyone, here I’m trying to divide the screen with a grid, then fill each tile in a pre-determined amount of time: (this is the most simplified - even silly - example)
float timeToConsume = 7, timeToCancelBin;
int timer, counter;
ArrayList<GridPoint> points = new ArrayList<GridPoint>();
float tileWidth = 20, tileHeight = 20;
void setup() {
size(1280, 720);
noStroke();
// creo una griglia in base a width e height e alla larghezza dei riquadri tileWidth e tileHeight
// li aggiungo all'arraylist points in modo da poterli richiamare in seguito
for (float x = 0; x < width; x += tileWidth) {
for (float y = 0; y < height; y += tileHeight) {
points.add(new GridPoint(x, y, tileWidth, tileHeight));
}
}
timeToCancelBin = (timeToConsume * 1000) / points.size();
println(points.size() + " " + timeToConsume + " " + timeToCancelBin);
}
void draw() {
background(255);
// controllo se la variabile black sia vera o falsa, nel caso colora il rettangolo di nero
for (int i = 0; i < points.size(); i++) {
if (points.get(i).black) {
fill(0);
} else {
noFill();
}
points.get(i).show();
}
if (millis() - timer >= timeToCancelBin) {
ruin();
timer = millis();
}
}
void ruin() {
if (counter < points.size()) {
GridPoint p = points.get(counter);
p.black = true;
}
counter++;
if (counter == (points.size())) {
println(millis());
}
}
class GridPoint {
float x, y, tileWidth, tileHeight;
boolean black = false;
GridPoint(float x, float y, float tileWidth, float tileHeight) {
this.x = x;
this.y = y;
this.tileWidth = tileWidth;
this.tileHeight = tileHeight;
}
void show() {
rect(x, y, tileWidth, tileHeight);
}
}
My problem is that it doesn’t fill all the tiles in the given amount of time, and if you modify the width and the height (so the total number) of tiles it vary also the time…
What am I doing wrong here? Thank you