let frog = 1;
let lily = [];
let nPad1 = 0;
let nFrogs = 1;
let pPad1 = 0;
function setup() {
c = 500;
createCanvas(c, c);
lily[0] = { x: c / 4, y: c / 4, p: [1], fill: color(100, 200, 100) };
lily[1] = { x: (3 * c) / 4, y: c / 4, p: [0, 2], fill: color(200) };
lily[2] = { x: c / 4, y: (3 * c) / 4, p: [1, 3, 3], fill: color(200) };
lily[3] = { x: (3 * c) / 4, y: (3 * c) / 4, p: [3], fill: color(100, 0, 0) };
rectMode(CENTER);
lily.forEach((L) => {
fill(L.fill);
circle(L.x, L.y, c / 4);
});
}
function draw() {
for (let i = 0; i < 1000; i++) {
stroke(255);
fill(140, 200 + random(-20, 50), 140, 20);
t2 = random(0, 2 * PI);
r2 = random(0.1, c / 10);
x2 = lily[frog].x + r2 * sin(t2);
y2 = lily[frog].y + r2 * cos(t2);
while (frog != 0 && frog != 3) {
noStroke();
x1 = x2;
y1 = y2;
circle(x1, y1, 10);
frog = random(lily[frog].p);
t2 = random(0, 2 * PI);
r2 = random(0.1, c / 10);
x2 = lily[frog].x + r2 * sin(t2);
y2 = lily[frog].y + r2 * cos(t2);
circle(x2, y2, 10);
g = random(0, 250);
stroke(g, g, g, 10);
line(x1, y1, x2, y2);
}
if (frog === 0) {
nPad1++;
}
nFrogs++;
pPad1 = nPad1 / nFrogs;
fill(255);
noStroke();
rect(c / 2, c - 40, 100, 50);
fill(0);
text("n = " + str(nFrogs), c / 2 - 40, c - 40);
text("p = " + str(round(pPad1, 6)), c / 2 - 40, c - 20);
frog = 1;
}
}