int n = 400; int nsc = 1; void setup() { size(n*nsc, n*nsc); noStroke(); noLoop(); } void mouseClicked() { redraw(); } class Point { int x, y; Point(int i, int j) { x = i; y = j; } } void draw() { background(#ffffff); int[][] grid = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { grid[i][j] = (random(1) > 0.42 ? 1 : 0); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (grid[i][j] != 1) continue; fill(color(random(255), random(255), random(255))); // Processing.js doesn't support LinkedList :( ArrayList q = new ArrayList(); q.add(new Point(i, j)); while (!q.isEmpty()) { Point p = q.remove(q.size()-1); if (p.x >= 0 && p.x < n && p.y >= 0 && p.y < n && grid[p.x][p.y] == 1) { grid[p.x][p.y] = 2; rect(nsc*p.x, nsc*p.y, nsc, nsc); q.add(new Point(p.x, p.y+1)); q.add(new Point(p.x, p.y-1)); q.add(new Point(p.x+1, p.y)); q.add(new Point(p.x-1, p.y)); } } } } }