color[] tiles; int tileSize = 32; int tileCount = 256 / tileSize; int selectedTile = -1; float t; void setup() { size(260, 260); tiles = new color[tileCount * tileCount]; for (int i = 0; i < tileCount * tileCount; i++) { tiles[i] = color(random(255), random(255), random(255)); } framerate(30); } void draw() { if (selectedTile != -1) { color selectedColor = tiles[selectedTile]; int selectedX = selectedTile % tileCount; int selectedY = selectedTile / tileCount; for (int y = 0; y < tileCount; y++) { for (int x = 0; x < tileCount; x++) { int xDistance = x - selectedX; int yDistance = y - selectedY; int distance = (int)sqrt(xDistance * xDistance + yDistance * yDistance); float factor = constrain(t - distance, 0, 1); factor = factor / 20; int each = y * tileCount + x; color eachColor = tiles[each]; int mixRed = (int)min(255, red(selectedColor) * factor + red(eachColor) * (1 - factor)); int mixGreen = (int)min(255, green(selectedColor) * factor + green(eachColor) * (1 - factor)); int mixBlue = (int)min(255, blue(selectedColor) * factor + blue(eachColor) * (1 - factor)); tiles[each] = color(mixRed, mixGreen, mixBlue); } } } background(255); for (int y = 0; y < tileCount; y++) { for (int x = 0; x < tileCount; x++) { noStroke(); fill(tiles[y * tileCount + x]); rect(x * 32 + 4, y * tileSize + 4, 28, 28); } } t = t + 0.03; } void mousePressed() { int mouseXWithoutBorder = mouseX - 2; int mouseYWithoutBorder = mouseY - 2; int tileX = mouseXWithoutBorder / tileSize; int tileY = mouseYWithoutBorder / tileSize; tileX = (int)constrain(tileX, 0, tileCount - 1); tileY = (int)constrain(tileY, 0, tileCount - 1); selectedTile = tileY * tileCount + tileX; t = 1; }