var colors = ["#FFC30F", "#FF5733", "#1AC7C4"];
const GRID_SIZE = Math.min(innerWidth, innerHeight) / GRID_UNITS;
const number_of_types = colors.length;
colors.forEach((str, i) => colors[i] = color(str));
createCanvas(GRID_SIZE*GRID_UNITS, GRID_SIZE*GRID_UNITS);
for(var y = 0; y < height-2; y += GRID_SIZE) {
for(var x = 0; x < width-2; x += GRID_SIZE) {
values.push(floor(random(number_of_types)))
itensPerRow = sqrt(values.length);
for(var i = 0; i < number_of_types; i++){
for(var j = 0; j < 10; j++){
x: floor(random(itensPerRow)),
y: floor(random(itensPerRow)),
w.x = constrain(w.x + random([-1, 0, 1]), 0, itensPerRow-1);
w.y = constrain(w.y + random([-1, 0, 1]), 0, itensPerRow-1);
values[w.y * itensPerRow + w.x] = w.number;
grid = new Grid(GRID_SIZE, width, height, number_of_types, values);
grid.shapes = grid.shapes.map(shape => grid.shrinkPolygon(shape, GRID_SIZE/3));
grid.shapes.forEach(shape => {
shape.color = colors[shape.number];
strokeWeight(GRID_SIZE/8);
grid.shapes.forEach(shape => {
shape.forEach(coord => vertex(coord.x, coord.y));
textAlign(CENTER, CENTER);
values.forEach((v, index) => {
var x = index % itensPerRow + 0.5;
var y = floor(index / itensPerRow) + 0.5;
circle(x * GRID_SIZE, y * GRID_SIZE, GRID_SIZE/6);
stroke(colors[w.number]);
circle(x * GRID_SIZE, y * GRID_SIZE, GRID_SIZE/2);
function lerpColors(t, colors)
let i = Math.floor(t*(colors.length-1));
if(i < 0) return colors[0];
if(i >= colors.length-1) return colors[colors.length-1];
let percent = (t - i / (colors.length-1)) * (colors.length-1);
colors[i]._getRed() + percent*(colors[i+1]._getRed()-colors[i]._getRed()),
colors[i]._getGreen() + percent*(colors[i+1]._getGreen()-colors[i]._getGreen()),
colors[i]._getBlue() + percent*(colors[i+1]._getBlue()-colors[i]._getBlue())
x: floor(mouseX/width*itensPerRow),
y: floor(mouseY/height*itensPerRow),
x: floor(mouseX/width*itensPerRow),
y: floor(mouseY/height*itensPerRow),