quick question
in
Programming Questions
•
1 year ago
Cell[][] grid;
// Number of columns and rows in the grid
int cols = 100;
int rows = 100;
void setup() {
size(500, 500);
grid = new Cell[cols][rows];
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
// Initialize each object
grid[i][j] = new Cell(i*5, j*5, 10, 10, i+j);
}
}
}
void draw() {
fill(0);
background(0);
// The counter variables i and j are also the column and row numbers and
// are used as arguments to the constructor for each object in the grid.
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
// Oscillate and display each object
grid[i][j].display();
}
}
}
// A Cell object
class Cell {
// A cell object knows about its location in the grid as well as its size with the variables x,y,w,h.
float x, y; // x,y location
float w, h; // width and height
// Cell Constructor
Cell(float tempX, float tempY, float tempW, float tempH, float tempAngle) {
x = tempX;
y = tempY;
w = tempW;
h = tempH;
}
// Oscillation means increase angle
void display() {
// Color calculated using sine wave
fill(random(0, 255));
noLoop();
rect(x, y, 50, 50);
}
}
// Number of columns and rows in the grid
int cols = 100;
int rows = 100;
void setup() {
size(500, 500);
grid = new Cell[cols][rows];
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
// Initialize each object
grid[i][j] = new Cell(i*5, j*5, 10, 10, i+j);
}
}
}
void draw() {
fill(0);
background(0);
// The counter variables i and j are also the column and row numbers and
// are used as arguments to the constructor for each object in the grid.
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
// Oscillate and display each object
grid[i][j].display();
}
}
}
// A Cell object
class Cell {
// A cell object knows about its location in the grid as well as its size with the variables x,y,w,h.
float x, y; // x,y location
float w, h; // width and height
// Cell Constructor
Cell(float tempX, float tempY, float tempW, float tempH, float tempAngle) {
x = tempX;
y = tempY;
w = tempW;
h = tempH;
}
// Oscillation means increase angle
void display() {
// Color calculated using sine wave
fill(random(0, 255));
noLoop();
rect(x, y, 50, 50);
}
}
how can i make it that, when the mouse is clicked, the whole thing re-runs and the pixels all change
1