Sorry I’m just discovering P5.js today and don’t understand what you are referring to.
Here below a naive implementation of the example sketch I posted earlier, hope it helps.
https://editor.p5js.org/solub/sketches/cKYLiqrCa
let cols = 16, rows = 16, size = 400, step = size / cols, grid = [];
var colors= [[255,0,0],[255,128,0],[255,255,0],[0,255,0],[0,0,255],[127,0,255],[255,102,178],[80,80,80]];
let xy = [[-1, -1], [1, -1], [1, 1], [-1, 1]];
function setup() {
createCanvas(size, size);
noStroke();
for (let x = 0; x < cols; x++) {
grid[x] = []
for (let y = 0; y < rows; y++) {
idx = x + y * cols;
s = (y%2) ? 0 : 1;
rdm = Math.floor(Math.random() * colors.length);
grid[x][y] = (idx%2 == s) ? colors[rdm] : null;
}
}
//Second Pass
for (let x = 0; x < cols; x++) {
for (let y = 0; y < rows; y++) {
//Only focusing on non-white tiles
if (grid[x][y] != null) {
let nColors = [];
//Convolution
for (let i = 0; i < xy.length; i++) {
x1 = constrain(x + xy[i][0], 0, cols - 1);
y1 = constrain(y + xy[i][1], 0, rows - 1);
nColors.push(JSON.stringify(grid[x1][y1])); //Stores neighboring colors
//If neighbor (only on diagonals) has same color values -> pick another color
if (JSON.stringify(grid[x][y]) == JSON.stringify(grid[x1][y1])) {
//Make sure to pick a new color that is not in the neighboring colors
let colrs = [];
for (let n = 0; n < colors.length; n++) {
if (!nColors.includes(JSON.stringify(colors[n])) && JSON.stringify(colors[n]) != JSON.stringify(grid[x1][y1])) {
colrs.push(colors[n])
}
}
grid[x][y] = colrs[Math.floor(Math.random(colrs.length))];
}
}
}
if (grid[x][y] != null) {
fill(grid[x][y][0], grid[x][y][1], grid[x][y][2])
}
else {
fill(255)
}
rect(x * step, y * step, step, step)
}
}
}