Raxol.Demo.Particles (Raxol v2.6.0)

View Source

Particle system for animated demo effects. Supports sparkles, explosions, trails, and floating elements.

Summary

Functions

Creates a new particle at the given position.

Creates a cascading explosion particle that spawns children.

Creates an explosion particle (radiates outward).

Creates a rain particle (falls down).

Creates a rain particle with phase for sine wave motion.

Creates a ring of particles expanding outward. Y is compressed for terminal aspect ratio.

Creates a rising rocket particle with trail.

Creates a particle with size-based character selection. Size can be :small, :medium, or :large.

Creates an explosion particle with size distribution. 70% small, 25% medium, 5% large.

Creates a sparkle particle (rising, fading).

Creates a trail particle (slow fade, minimal movement).

Creates a particle with trail tracking enabled.

Returns a random color from a specific palette.

Filters out dead particles.

Returns a random color from the available palettes.

Renders particles to a frame buffer, returns ANSI escape sequences.

Renders particles with their trail history. Trail chars fade from bright to dim.

Updates a particle's position and life.

Updates cascading particles and returns {updated_particle, spawned_children}. Call this when you need cascade behavior.

Updates particle without gravity (for floating effects).

Updates particle and maintains position history for trail effect. Keeps last 4 positions.

Types

particle()

@type particle() :: %{
  :x => float(),
  :y => float(),
  :vx => float(),
  :vy => float(),
  :char => String.t(),
  :color => non_neg_integer(),
  :life => integer(),
  :history => [{float(), float()}],
  :generation => non_neg_integer(),
  :spawn_at_life => non_neg_integer(),
  optional(:phase) => float()
}

Functions

create(x, y, opts \\ [])

@spec create(float(), float(), keyword()) :: particle()

Creates a new particle at the given position.

create_cascade_explosion(x, y, generation)

@spec create_cascade_explosion(float(), float(), integer()) :: particle()

Creates a cascading explosion particle that spawns children.

create_explosion(x, y)

@spec create_explosion(float(), float()) :: particle()

Creates an explosion particle (radiates outward).

create_rain(x, y, color)

@spec create_rain(float(), float(), non_neg_integer()) :: particle()

Creates a rain particle (falls down).

create_rain_with_phase(x, y, color, phase)

@spec create_rain_with_phase(float(), float(), non_neg_integer(), float()) ::
  particle()

Creates a rain particle with phase for sine wave motion.

create_ring_burst(center_x, center_y, count \\ 24, opts \\ [])

@spec create_ring_burst(float(), float(), integer(), keyword()) :: [particle()]

Creates a ring of particles expanding outward. Y is compressed for terminal aspect ratio.

create_rocket(x, y, opts \\ [])

@spec create_rocket(float(), float(), keyword()) :: particle()

Creates a rising rocket particle with trail.

create_sized(x, y, size, opts \\ [])

@spec create_sized(float(), float(), atom(), keyword()) :: particle()

Creates a particle with size-based character selection. Size can be :small, :medium, or :large.

create_sized_explosion(x, y)

@spec create_sized_explosion(float(), float()) :: particle()

Creates an explosion particle with size distribution. 70% small, 25% medium, 5% large.

create_sparkle(x, y)

@spec create_sparkle(float(), float()) :: particle()

Creates a sparkle particle (rising, fading).

create_trail(x, y, color)

@spec create_trail(float(), float(), non_neg_integer()) :: particle()

Creates a trail particle (slow fade, minimal movement).

create_with_trail(x, y, opts \\ [])

@spec create_with_trail(float(), float(), keyword()) :: particle()

Creates a particle with trail tracking enabled.

palette_color(atom)

@spec palette_color(atom()) :: non_neg_integer()

Returns a random color from a specific palette.

prune(particles)

@spec prune([particle()]) :: [particle()]

Filters out dead particles.

random_color()

@spec random_color() :: non_neg_integer()

Returns a random color from the available palettes.

render(particles, width, height)

@spec render([particle()], non_neg_integer(), non_neg_integer()) :: String.t()

Renders particles to a frame buffer, returns ANSI escape sequences.

render_with_trails(particles, width, height)

@spec render_with_trails(
  [particle()],
  non_neg_integer(),
  non_neg_integer()
) :: String.t()

Renders particles with their trail history. Trail chars fade from bright to dim.

update(particle, opts \\ [])

@spec update(
  particle(),
  keyword()
) :: particle()

Updates a particle's position and life.

update_cascade(particle, opts \\ [])

@spec update_cascade(
  particle(),
  keyword()
) :: {particle(), [particle()]}

Updates cascading particles and returns {updated_particle, spawned_children}. Call this when you need cascade behavior.

update_float(particle)

@spec update_float(particle()) :: particle()

Updates particle without gravity (for floating effects).

update_with_trail(particle, opts \\ [])

@spec update_with_trail(
  particle(),
  keyword()
) :: particle()

Updates particle and maintains position history for trail effect. Keeps last 4 positions.