🔬 This block uses Perlin noise so tips wobble smoothly instead of jittering randomly every frame. What happens if you change timeSeconds * 0.2 to timeSeconds * 2, making the noise change much faster over time?
const noiseInput = branchId * 0.35 + depth * 0.7;
const n = noise(noiseInput, timeSeconds * 0.2); // [0,1]
const noiseAmp = radians(1 + 5 * t); // up to ~6° at tips
const noiseAngle = map(n, 0, 1, -noiseAmp, noiseAmp);
🔬 Every branch currently splits into exactly two children. What happens if you add a third drawBranch() call here with angle 0 (straight ahead), turning this into a three-way split?
// Left child
drawBranch(nextLen, depth + 1, spread * 0.9, -childSpread, branchId * 2 + 1);
// Right child
drawBranch(nextLen, depth + 1, spread * 0.9, childSpread, branchId * 2 + 2);
function drawBranch(len, depth, spread, angle, branchId) {
if (depth > MAX_DEPTH || len < 2) return;
push();
// Normalized depth 0..1
const t = depth / MAX_DEPTH;
// Local sway increases toward the tips
const localSway = globalSway * (0.4 + 0.6 * t);
// Noise-based tip motion (stronger toward tips)
const noiseInput = branchId * 0.35 + depth * 0.7;
const n = noise(noiseInput, timeSeconds * 0.2); // [0,1]
const noiseAmp = radians(1 + 5 * t); // up to ~6° at tips
const noiseAngle = map(n, 0, 1, -noiseAmp, noiseAmp);
// Apply rotation for this branch
rotate(angle + localSway + noiseAngle);
// Depth-based color from dark brown → spring green
// Brownish: H≈30, S≈80, B≈40
// Spring green: H≈110, S≈60, B≈90
const hCol = lerp(30, 110, t);
const sCol = lerp(80, 60, t);
const bCol = lerp(40, 90, t);
stroke(hCol, sCol, bCol);
// Stroke weight decreases with depth
const sw = map(depth, 0, MAX_DEPTH, MAX_STROKE, MIN_STROKE);
strokeWeight(sw);
// Draw the branch segment
line(0, 0, 0, -len);
translate(0, -len);
// Compute next branch length
const nextLen = len * LENGTH_FACTOR;
// Recurse: each branch splits into two children
if (depth < MAX_DEPTH) {
const childSpread = spread;
// Left child
drawBranch(nextLen, depth + 1, spread * 0.9, -childSpread, branchId * 2 + 1);
// Right child
drawBranch(nextLen, depth + 1, spread * 0.9, childSpread, branchId * 2 + 2);
}
pop();
}