@@ -47,14 +47,20 @@ function setup() { |
| 47 | 47 | let homeBranchY = random(height * 0.7, height * 0.85); |
| 48 | 48 | let homeBranchThickness = 25; |
| 49 | 49 | |
| 50 | | - // Generate twigs and leaves once during setup |
| 50 | + // Calculate start and end positions ONCE |
| 51 | + let branchStartX = homeBranchSide === 'left' ? -20 : width + 20; |
| 52 | + let branchEndX = homeBranchSide === 'left' ? homeBranchLength : width - homeBranchLength; |
| 53 | + |
| 54 | + // Generate twigs with FIXED positions |
| 51 | 55 | let twigs = []; |
| 52 | 56 | let numTwigs = 5; |
| 53 | 57 | for (let i = 0; i < numTwigs; i++) { |
| 58 | + let t = 0.2 + (0.6 * i / (numTwigs - 1)); // Evenly distributed |
| 59 | + let x = lerp(branchStartX, branchEndX, t); // Calculate actual X position |
| 54 | 60 | twigs.push({ |
| 55 | | - t: random(0.2, 0.8), |
| 56 | | - length: random(20, 40), |
| 57 | | - angle: random(-PI/3, -PI/6) * (homeBranchSide === 'right' ? -1 : 1), |
| 61 | + x: x, // Store actual position, not percentage |
| 62 | + length: 20 + (i * 4), // Vary length slightly |
| 63 | + angle: (-PI/4 + (i * PI/20)) * (homeBranchSide === 'right' ? -1 : 1), |
| 58 | 64 | subTwigs: [ |
| 59 | 65 | { pos: 0.7, length: 5, angle: -5 }, |
| 60 | 66 | { pos: 0.5, length: 4, angle: 4 } |
@@ -62,36 +68,38 @@ function setup() { |
| 62 | 68 | }); |
| 63 | 69 | } |
| 64 | 70 | |
| 71 | + // Generate leaves with FIXED positions |
| 65 | 72 | let leaves = []; |
| 66 | 73 | for (let i = 0; i < 3; i++) { |
| 74 | + let t = 0.3 + (0.4 * i / 2); // Distribute between 0.3 and 0.7 |
| 75 | + let x = lerp(branchStartX, branchEndX, t); |
| 67 | 76 | leaves.push({ |
| 68 | | - t: random(0.3, 0.7), |
| 69 | | - yOffset: random(-homeBranchThickness, -homeBranchThickness * 2), |
| 70 | | - rotation: random(-PI/4, PI/4), |
| 77 | + x: x, // Store actual position |
| 78 | + yOffset: -homeBranchThickness - (i * 10), |
| 79 | + rotation: -PI/6 + (i * PI/6), |
| 71 | 80 | width: 15, |
| 72 | 81 | height: 8 |
| 73 | 82 | }); |
| 74 | 83 | } |
| 75 | 84 | |
| 85 | + // Generate bark textures with FIXED positions |
| 76 | 86 | let barkTextures = []; |
| 77 | | - let startX = homeBranchSide === 'left' ? -20 : width + 20; |
| 78 | | - let endX = homeBranchSide === 'left' ? homeBranchLength : width - homeBranchLength; |
| 79 | | - for (let x = Math.min(startX, endX); x < Math.max(startX, endX); x += 20) { |
| 87 | + for (let x = Math.min(branchStartX, branchEndX); x < Math.max(branchStartX, branchEndX); x += 20) { |
| 80 | 88 | barkTextures.push({ |
| 81 | 89 | x: x, |
| 82 | | - yOff: random(-homeBranchThickness/3, homeBranchThickness/3), |
| 83 | | - endYOff: random(-5, 5) |
| 90 | + yOff: -5 + (x % 10), // Deterministic offset based on position |
| 91 | + endYOff: -2 + (x % 5) |
| 84 | 92 | }); |
| 85 | 93 | } |
| 86 | 94 | |
| 87 | 95 | // Store home branch info for rendering |
| 88 | 96 | window.homeBranch = { |
| 89 | 97 | side: homeBranchSide, |
| 90 | | - startX: startX, |
| 91 | | - endX: endX, |
| 98 | + startX: branchStartX, |
| 99 | + endX: branchEndX, |
| 92 | 100 | y: homeBranchY, |
| 93 | 101 | thickness: homeBranchThickness, |
| 94 | | - angle: random(-0.1, 0.1), // Slight angle for natural look |
| 102 | + angle: homeBranchSide === 'left' ? 0.05 : -0.05, // Fixed slight angle |
| 95 | 103 | twigs: twigs, |
| 96 | 104 | leaves: leaves, |
| 97 | 105 | barkTextures: barkTextures |
@@ -329,77 +337,167 @@ function drawSkyGradient() { |
| 329 | 337 | push(); |
| 330 | 338 | let branch = window.homeBranch; |
| 331 | 339 | |
| 332 | | - // Main branch |
| 333 | | - strokeWeight(branch.thickness); |
| 334 | | - if (gamePhase === 'NIGHT') { |
| 335 | | - stroke(30, 15, 0); |
| 336 | | - } else { |
| 337 | | - stroke(101, 67, 33); |
| 338 | | - } |
| 339 | | - |
| 340 | | - // Draw main branch with slight curve |
| 340 | + // Branch shadow |
| 341 | 341 | push(); |
| 342 | | - translate(0, branch.y); |
| 342 | + translate(0, branch.y + 5); |
| 343 | 343 | rotate(branch.angle); |
| 344 | + noStroke(); |
| 345 | + fill(0, 0, 0, 30); |
| 344 | 346 | |
| 345 | | - let startX = branch.startX; |
| 346 | | - let endX = branch.endX; |
| 347 | | - let midX = (startX + endX) / 2; |
| 348 | | - let midY = sin(PI * 0.5) * 15; // Slight sag in middle |
| 349 | | - |
| 350 | | - noFill(); |
| 347 | + // Shadow with taper |
| 351 | 348 | beginShape(); |
| 352 | | - curveVertex(startX, 0); |
| 353 | | - curveVertex(startX, 0); |
| 354 | | - curveVertex(midX, midY); |
| 355 | | - curveVertex(endX, 0); |
| 356 | | - curveVertex(endX, 0); |
| 357 | | - endShape(); |
| 349 | + vertex(branch.startX, 10); |
| 350 | + bezierVertex( |
| 351 | + branch.startX + (branch.endX - branch.startX) * 0.3, 8, |
| 352 | + branch.startX + (branch.endX - branch.startX) * 0.7, 5, |
| 353 | + branch.endX, 3 |
| 354 | + ); |
| 355 | + vertex(branch.endX, -3); |
| 356 | + bezierVertex( |
| 357 | + branch.startX + (branch.endX - branch.startX) * 0.7, -5, |
| 358 | + branch.startX + (branch.endX - branch.startX) * 0.3, -8, |
| 359 | + branch.startX, -10 |
| 360 | + ); |
| 361 | + endShape(CLOSE); |
| 358 | 362 | pop(); |
| 359 | 363 | |
| 360 | | - // Add texture and smaller branches |
| 364 | + // Main branch with organic shape and taper |
| 361 | 365 | push(); |
| 362 | 366 | translate(0, branch.y); |
| 363 | 367 | rotate(branch.angle); |
| 364 | 368 | |
| 365 | | - // Bark texture (using pre-generated positions) |
| 366 | | - stroke(80, 50, 20, 100); |
| 367 | | - strokeWeight(2); |
| 368 | | - for (let texture of branch.barkTextures) { |
| 369 | | - line(texture.x, texture.yOff, texture.x + 10, texture.yOff + texture.endYOff); |
| 369 | + // Dark brown base |
| 370 | + noStroke(); |
| 371 | + if (gamePhase === 'NIGHT') { |
| 372 | + fill(30, 15, 5); |
| 373 | + } else { |
| 374 | + fill(92, 51, 23); |
| 370 | 375 | } |
| 371 | 376 | |
| 372 | | - // Small twigs (using pre-generated positions) |
| 377 | + // Create tapered, organic branch shape |
| 378 | + beginShape(); |
| 379 | + // Top edge with bumps and curves |
| 380 | + vertex(branch.startX, -branch.thickness); |
| 381 | + bezierVertex( |
| 382 | + branch.startX + (branch.endX - branch.startX) * 0.2, -branch.thickness + 3, |
| 383 | + branch.startX + (branch.endX - branch.startX) * 0.4, -branch.thickness * 0.8 + 2, |
| 384 | + branch.startX + (branch.endX - branch.startX) * 0.6, -branch.thickness * 0.6 |
| 385 | + ); |
| 386 | + bezierVertex( |
| 387 | + branch.startX + (branch.endX - branch.startX) * 0.8, -branch.thickness * 0.4, |
| 388 | + branch.endX - 20, -branch.thickness * 0.3, |
| 389 | + branch.endX, -branch.thickness * 0.2 |
| 390 | + ); |
| 391 | + |
| 392 | + // Bottom edge with natural irregularities |
| 393 | + vertex(branch.endX, branch.thickness * 0.2); |
| 394 | + bezierVertex( |
| 395 | + branch.endX - 20, branch.thickness * 0.3, |
| 396 | + branch.startX + (branch.endX - branch.startX) * 0.8, branch.thickness * 0.4 + 2, |
| 397 | + branch.startX + (branch.endX - branch.startX) * 0.6, branch.thickness * 0.6 |
| 398 | + ); |
| 399 | + bezierVertex( |
| 400 | + branch.startX + (branch.endX - branch.startX) * 0.4, branch.thickness * 0.8, |
| 401 | + branch.startX + (branch.endX - branch.startX) * 0.2, branch.thickness - 3, |
| 402 | + branch.startX, branch.thickness |
| 403 | + ); |
| 404 | + endShape(CLOSE); |
| 405 | + |
| 406 | + // Add lighter brown highlights |
| 407 | + if (gamePhase === 'NIGHT') { |
| 408 | + fill(50, 25, 10, 150); |
| 409 | + } else { |
| 410 | + fill(139, 90, 43, 150); |
| 411 | + } |
| 412 | + |
| 413 | + // Top highlight |
| 414 | + beginShape(); |
| 415 | + vertex(branch.startX + 10, -branch.thickness + 5); |
| 416 | + bezierVertex( |
| 417 | + branch.startX + (branch.endX - branch.startX) * 0.3, -branch.thickness * 0.7, |
| 418 | + branch.startX + (branch.endX - branch.startX) * 0.6, -branch.thickness * 0.5, |
| 419 | + branch.endX - 30, -branch.thickness * 0.2 + 2 |
| 420 | + ); |
| 421 | + vertex(branch.endX - 30, 0); |
| 422 | + bezierVertex( |
| 423 | + branch.startX + (branch.endX - branch.startX) * 0.6, -2, |
| 424 | + branch.startX + (branch.endX - branch.startX) * 0.3, -5, |
| 425 | + branch.startX + 10, -8 |
| 426 | + ); |
| 427 | + endShape(CLOSE); |
| 428 | + |
| 429 | + // Bark texture with grooves |
| 430 | + stroke(60, 30, 10, 100); |
| 431 | + strokeWeight(1); |
| 432 | + for (let i = 0; i < branch.barkTextures.length; i += 2) { |
| 433 | + let texture = branch.barkTextures[i]; |
| 434 | + // Vertical grooves |
| 435 | + line(texture.x, texture.yOff - 5, texture.x + 3, texture.yOff + 8); |
| 436 | + // Horizontal texture |
| 437 | + if (i % 4 === 0) { |
| 438 | + line(texture.x - 5, texture.yOff, texture.x + 15, texture.yOff + 2); |
| 439 | + } |
| 440 | + } |
| 441 | + |
| 442 | + // Add knots and bumps |
| 443 | + noStroke(); |
| 444 | + if (gamePhase === 'NIGHT') { |
| 445 | + fill(40, 20, 5); |
| 446 | + } else { |
| 447 | + fill(80, 40, 15); |
| 448 | + } |
| 449 | + |
| 450 | + // A couple of knots |
| 451 | + ellipse(branch.startX + (branch.endX - branch.startX) * 0.3, -3, 15, 12); |
| 452 | + ellipse(branch.startX + (branch.endX - branch.startX) * 0.7, 2, 10, 8); |
| 453 | + |
| 454 | + // Small twigs with organic angles |
| 373 | 455 | stroke(gamePhase === 'NIGHT' ? color(40, 20, 0) : color(101, 67, 33)); |
| 374 | | - strokeWeight(3); |
| 375 | 456 | for (let twig of branch.twigs) { |
| 376 | | - let twigX = lerp(startX, endX, twig.t); |
| 377 | | - |
| 378 | 457 | push(); |
| 379 | | - translate(twigX, 0); |
| 380 | | - rotate(twig.angle); |
| 381 | | - line(0, 0, twig.length, 0); |
| 458 | + translate(twig.x, 0); |
| 459 | + |
| 460 | + // Make twigs thicker at base |
| 461 | + strokeWeight(4); |
| 462 | + line(0, 0, twig.length * 0.3, twig.length * 0.1); |
| 463 | + strokeWeight(3); |
| 464 | + line(twig.length * 0.3, twig.length * 0.1, twig.length * 0.6, twig.length * 0.15); |
| 465 | + strokeWeight(2); |
| 466 | + line(twig.length * 0.6, twig.length * 0.15, twig.length, twig.length * 0.2); |
| 382 | 467 | |
| 383 | 468 | // Tiny sub-twigs |
| 384 | 469 | strokeWeight(1); |
| 385 | 470 | for (let subTwig of twig.subTwigs) { |
| 386 | | - line(twig.length * subTwig.pos, 0, |
| 471 | + line(twig.length * subTwig.pos, twig.length * 0.15, |
| 387 | 472 | twig.length * subTwig.pos + subTwig.length, |
| 388 | | - subTwig.angle); |
| 473 | + twig.length * 0.15 + subTwig.angle); |
| 389 | 474 | } |
| 390 | 475 | pop(); |
| 391 | 476 | } |
| 392 | 477 | |
| 393 | | - // Add leaves (using pre-generated positions) |
| 394 | | - fill(gamePhase === 'NIGHT' ? color(20, 40, 20) : color(34, 139, 34)); |
| 395 | | - noStroke(); |
| 478 | + // Add leaves with more natural placement |
| 396 | 479 | for (let leaf of branch.leaves) { |
| 397 | | - let leafX = lerp(startX, endX, leaf.t); |
| 398 | | - |
| 399 | 480 | push(); |
| 400 | | - translate(leafX, leaf.yOffset); |
| 481 | + translate(leaf.x, leaf.yOffset); |
| 401 | 482 | rotate(leaf.rotation); |
| 483 | + |
| 484 | + // Leaf shadow |
| 485 | + noStroke(); |
| 486 | + fill(0, 0, 0, 20); |
| 487 | + ellipse(2, 2, leaf.width, leaf.height); |
| 488 | + |
| 489 | + // Leaf body |
| 490 | + if (gamePhase === 'NIGHT') { |
| 491 | + fill(20, 40, 20); |
| 492 | + } else { |
| 493 | + fill(34, 139, 34); |
| 494 | + } |
| 402 | 495 | ellipse(0, 0, leaf.width, leaf.height); |
| 496 | + |
| 497 | + // Leaf vein |
| 498 | + stroke(25, 100, 25, 100); |
| 499 | + strokeWeight(0.5); |
| 500 | + line(-leaf.width/2 + 2, 0, leaf.width/2 - 2, 0); |
| 403 | 501 | pop(); |
| 404 | 502 | } |
| 405 | 503 | |