paint method

  1. @override
void paint(
  1. Buffer buffer,
  2. Rect area,
  3. Style baseStyle
)
override

Performs direct rendering modifications to the relative buffer.

Implementation

@override
void paint(Buffer buffer, Rect area, Style baseStyle) {
  if (!isVisible) return;

  final W = area.width;
  final H = area.height;
  if (W <= 0 || H <= 0) return;

  // Spawn new particles based on density config
  for (var i = 0; i < density; i++) {
    if (_random.nextDouble() < 0.3) {
      _particles.add(
        _SparkleParticle(
          x: _random.nextInt(W),
          y: _random.nextInt(H),
          char: sparkleChars[_random.nextInt(sparkleChars.length)],
          color: colors[_random.nextInt(colors.length)],
          life: 1.0,
          decay: 0.04 + _random.nextDouble() * 0.08,
        ),
      );
    }
  }

  for (final p in _particles) {
    p.life -= p.decay;
  }

  for (final p in _particles) {
    if (p.life > 0.0) {
      final cell = buffer.getCell(p.x, p.y);
      if (cell != null) {
        // Dim the character color as life decays
        final dimmedColor = interpolateColor(Colors.black, p.color, p.life);

        cell.char = p.char;
        cell.style = cell.style.merge(
          Style(foreground: dimmedColor, modifiers: Modifier.bold),
        );
      }
    }
  }

  final remainingParticles = [
    for (final p in _particles)
      if (p.life > 0.0) p,
  ];

  _particles.clear();
  _particles.addAll(remainingParticles);
}