🔬 The lightning is drawn in three layers: outer glow (10px, alpha 50), middle (6px, alpha 100), and core (3px, alpha 200). What if you removed one of the layers? Try commenting out the first stroke/strokeWeight/drawJaggedLine call by putting // in front of it. Or what if you added a 4th layer with strokeWeight(15) and alpha 20?
stroke(255, 255, 255, 50); // White with 50 alpha
strokeWeight(10);
drawJaggedLine(startX, startY, startX, endY, displacement * 0.3, segmentLength);
stroke(255, 255, 255, 100); // White with 100 alpha
strokeWeight(6);
drawJaggedLine(startX, startY, startX, endY, displacement * 0.5, segmentLength);
// Draw the main lightning bolt (thinnest and most opaque)
stroke(255, 255, 255, 200); // White with 200 alpha
strokeWeight(3);
drawJaggedLine(startX, startY, startX, endY, displacement, segmentLength);
function drawLightningBolt() {
let startX = width / 2; // Start in the middle top of the canvas
let startY = 0;
let endY = height * 0.7; // End at the grass line
let displacement = 100; // How much the lightning can "wobble"
let segmentLength = 20; // Length of each segment in the lightning bolt
noFill();
// Draw the glow effect first (thickest and most transparent)
stroke(255, 255, 255, 50); // White with 50 alpha
strokeWeight(10);
drawJaggedLine(startX, startY, startX, endY, displacement * 0.3, segmentLength);
stroke(255, 255, 255, 100); // White with 100 alpha
strokeWeight(6);
drawJaggedLine(startX, startY, startX, endY, displacement * 0.5, segmentLength);
// Draw the main lightning bolt (thinnest and most opaque)
stroke(255, 255, 255, 200); // White with 200 alpha
strokeWeight(3);
drawJaggedLine(startX, startY, startX, endY, displacement, segmentLength);
// Add smaller branches to the lightning bolt
if (random() < 0.5) { // 50% chance for a branch to appear
let branchX = startX + random(-50, 50); // Random horizontal offset from the main bolt
let branchY = random(height * 0.2, height * 0.5); // Random point along the main bolt's path
let branchLength = random(50, 150);
// Angle towards the grass, roughly between 45 and 135 degrees (PI/4 to 3*PI/4 radians)
let branchAngle = random(PI / 4, 3 * PI / 4);
let branchEndX = branchX + branchLength * cos(branchAngle);
let branchEndY = branchY + branchLength * sin(branchAngle);
// Limit the branch end to not go below the grass line
branchEndY = min(branchEndY, endY);
stroke(255, 255, 255, 150); // White with 150 alpha
strokeWeight(2);
drawJaggedLine(branchX, branchY, branchEndX, branchEndY, displacement * 0.2, segmentLength * 0.5);
}
}