RosettaCodeData/Task/Brownian-tree/Processing/brownian-tree.processing

40 lines
795 B
Plaintext

boolean SIDESTICK = false;
boolean[][] isTaken;
void setup() {
size(512, 512);
background(0);
isTaken = new boolean[width][height];
isTaken[width/2][height/2] = true;
}
void draw() {
int x = floor(random(width));
int y = floor(random(height));
if (isTaken[x][y]) {
return;
}
while (true) {
int xp = x + floor(random(-1, 2));
int yp = y + floor(random(-1, 2));
boolean iscontained = (
0 <= xp && xp < width &&
0 <= yp && yp < height
);
if (iscontained && !isTaken[xp][yp]) {
x = xp;
y = yp;
continue;
} else {
if (SIDESTICK || (iscontained && isTaken[xp][yp])) {
isTaken[x][y] = true;
set(x, y, #FFFFFF);
}
break;
}
}
if (frameCount > width * height) {
noLoop();
}
}