Skip to main content

generate_bolt

Function generate_bolt 

Source
pub fn generate_bolt(
    start: Vec2,
    end: Vec2,
    grid_size: usize,
    branch_prob: f32,
) -> LightningBolt
Expand description

Generate a lightning bolt from start to end using the Dielectric Breakdown Model.

The algorithm:

  1. Initialize the bolt at the start position.
  2. Solve Laplace’s equation for the potential field.
  3. Find candidate growth sites (neighbors of the bolt not yet part of it).
  4. Weight candidates by the local electric field (potential gradient).
  5. Select a growth site (deterministically using a hash for reproducibility).
  6. Extend the bolt and repeat.