Hi hello!
Recently I coded a grid system to create typography. My question, how can I change the color of individual tiles??
Here’s the code, feel free to play around!!
int amount = 10;
int[][] state = new int[amount][amount];
color fg = (200);
int mx, my;
void setup() {
size(800, 800);
for (int x = 0; x < amount; x++) {
for (int y = 0; y < amount; y++) {
}
}
}
void draw() {
if (keyPressed){
if (key == ‘b’);
background(0,255,0);
} else {
background(0,0,255,0);
}
background(0);
cursor(CROSS);
float tileW = width/amount;
float tileH = height/amount;
fill(fg);
noStroke();
ellipseMode(CORNER);
// Check where the mouse is
mx = int(map(mouseX, 0, width, 0, amount));
my = int(map(mouseY, 0, height, 0, amount));
// Draw the visual
for (int x = 0; x < amount; x++) {
for (int y = 0; y < amount; y++) {
if (state[x][y] == 0) {
pushMatrix();
translate(x*tileW, y*tileH);
rect(0, 0, tileW, tileH);
popMatrix();
} else if (state[x][y] == 2) {
pushMatrix();
translate(x*tileW, y*tileH);
triangle(tileW, tileH, 0, tileW, tileH, 0);
popMatrix();
} else if (state[x][y] == 5) {
pushMatrix();
translate(x*tileW, y*tileH);
triangle(0, 0, tileW, tileH, 0, tileW);
popMatrix();
} else if (state[x][y] == 3) {
pushMatrix();
translate(x*tileW, y*tileH);
triangle(tileW, tileH, tileW, 0, 0, 0);
popMatrix();
} else if (state[x][y] == 4) {
pushMatrix();
translate(x*tileW, y*tileH);
triangle(tileW, 0, 0, 0, 0, tileH);
popMatrix();
} else if (state[x][y] == 5) {
int sx = int(tileW*x);
int sy = int(tileH*y);
int sw = int(tileW);
int sh = int(tileH);
int dx = sx;
int dy = sy;
int dw = sw;
int dh = sh;
copy(sx, sy, sw, sh, dx, dy, dw, dh);
} else if (state[x][y] == 4) {
int sx = int(tileW*x);
int sy = int(tileH*y);
int sw = int(tileW);
int sh = int(tileH);
int dx = sx;
int dy = sy;
int dw = sw;
int dh = sh;
copy(sx, sy, sw, sh, dx, dy, dw, dh);
}
}
}
}
void countUp(int x, int y) {
if (state[x][y] < 5) {
state[x][y]++;
} else {
state[x][y] = 0;
}
}
void keyPressed() {
countUp(mx,my);
}