very new to processing and only little programming experience here. I'm trying to have a 2d grid with cells that change colour once I click them. My code basically works, but the execution seems to be very glitchy. Sometimes I need to click my mouse several times until a gridcell finally constantly changes its colour. Does anyone a more reliable coding solution for this?
Ideally I should also be able to hold down the mousebutton and draw, but this doesn't work at all here.
Cell[][] grid; int cols = 20; int rows = 20; int cellsize = 20;
void setup() { size(rows*cellsize,cols*cellsize); 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*cellsize,j*cellsize,cellsize,cellsize, true, false); } } }
void draw() { background(0);
for (int i = 0; i < cols; i++) { for (int j = 0; j < rows; j++) {
class Cell { float x,y; // x,y location float w,h; // width and height boolean p; //walkable? boolean over;
// a constructor which gives initial values once class is called! Cell(float tempX, float tempY, float tempW, float tempH, boolean tempP, boolean tempOver) { x = tempX; y = tempY; w = tempW; h = tempH; p = tempP; over = tempOver;