instantiateParticle method

  1. @override
AnimatedParticle instantiateParticle(
  1. Size surfaceSize
)
override

Abstract method to be implemented by subclasses to define particle emission behavior.

This method is called upon particle emission and is responsible for instantiating particles and setting their initial properties, positions, and trajectories. Use the provided surfaceSize parameter to determine the available animation area and customize particle behavior accordingly.

Example:

AnimatedParticle instantiateParticle(Size surfaceSize) {
  // Implement the particle emission behavior here.
  // Customize particle properties based on the `surfaceSize`.
  // Create and add particles to the animation.
}

Implementation

@override
AnimatedParticle instantiateParticle(Size surfaceSize) {
  final angleDegrees = -90 + randomAngle();
  final beginX = random.nextDoubleRange(-smokeWidth / 2, smokeWidth / 2);
  return AnimatedParticle(
    particle: Particle(
      configuration: particleConfiguration,
      position: Offset(
        beginX + effectConfiguration.origin.dx,
        effectConfiguration.origin.dy,
      ),
    ),
    startTime: totalElapsed,
    animationDuration: randomDuration(),
    pathTransformation: StraightPathTransformation(
        distance: randomDistance(), angle: angleDegrees),
    fadeOutThreshold: randomFadeOutThreshold(),
    fadeInLimit: randomFadeInLimit(),
    scaleRange: randomScaleRange(),
    distanceCurve: effectConfiguration.distanceCurve,
    fadeInCurve: effectConfiguration.fadeInCurve,
    fadeOutCurve: effectConfiguration.fadeOutCurve,
    scaleCurve: effectConfiguration.scaleCurve,
    trail: effectConfiguration.trail,
  );
}