paint method

  1. @override
void paint(
  1. Canvas canvas,
  2. Size size,
  3. double progress,
  4. Offset center,
  5. Color color, {
  6. double radiusMultiplier = 1.0,
  7. Offset positionOffset = Offset.zero,
})
override

Implementation

@override
void paint(
    Canvas canvas, Size size, double progress, Offset center, Color color,
    {double radiusMultiplier = 1.0, Offset positionOffset = Offset.zero}) {
  final c = center + positionOffset;
  final rnd = math.Random(42);
  final shortestSide = math.min(size.width, size.height);

  final explosionRadius = shortestSide * explosionScale * radiusMultiplier;

  // sudut partikel
  final List<double> angles = List.generate(
    particleCount,
    (i) => useUniformAngle
        ? (i / particleCount) * 2 * math.pi
        : rnd.nextDouble() * 2 * math.pi,
  );

  for (int i = 0; i < particleCount; i++) {
    final delay = i * 0.02;
    final rawT = progress - delay;
    if (rawT <= 0) continue;

    // normalisasi progress partikel
    final t = (rawT / (1 - delay)).clamp(0.0, 1.0);

    final angle = angles[i];

    // ---- posisi radial ----
    double distance;
    if (t < _burstPhase) {
      final burstT = t / _burstPhase;
      distance = explosionRadius * _easeOutBack(burstT);
    } else {
      final fallT = (t - _burstPhase) / (1 - _burstPhase);
      distance = explosionRadius + (fallT * fallT * 60);
    }

    final pos = c + Offset(math.cos(angle), math.sin(angle)) * distance;

    // ---- skala & opasitas ----
    final scale = t < .1
        ? t / .1
        : t > .85
            ? (1 - t) / .15
            : 1.0;

    final opacity = t < .1
        ? t / .1
        : t > .85
            ? (1 - t) / .15
            : 1.0;

    // ---- warna ----
    Color particleColor = color;
    if (enableHueTilt) {
      final hsl = HSLColor.fromColor(color);
      final hueShiftDeg = (angle / (2 * math.pi)) * 360 * hueTiltRange;
      particleColor = hsl
          .withHue((hsl.hue + hueShiftDeg) % 360)
          .withSaturation((hsl.saturation * saturationBoost).clamp(0.0, 1.0))
          .toColor();
    }
    particleColor = particleColor.withOpacity(opacity);

    // ---- gambar ----
    final rad = circleRadius * radiusMultiplier * scale;

    // lingkaran
    canvas.drawCircle(pos, rad, Paint()..color = particleColor);

    // ekor
    final tailLen = rad * tailFactor;
    final tailStart =
        pos - Offset(math.cos(angle), math.sin(angle)) * tailLen;
    canvas.drawLine(
        tailStart,
        pos,
        Paint()
          ..color = particleColor
          ..strokeWidth = rad * .8
          ..strokeCap = StrokeCap.round);
  }
}