generateConfettiParticles function
Generates count particles with randomized traits drawn from colors.
Pure aside from random (pass a seeded Random for deterministic
tests) — kept separate from the widget so "did we spawn the right
number of particles, with colors from the given palette" is a plain
unit test.
Implementation
List<ConfettiParticle> generateConfettiParticles(
int count,
List<Color> colors, {
Random? random,
}) {
final rng = random ?? Random();
return List.generate(count, (_) {
return ConfettiParticle(
startX: rng.nextDouble(),
fallSpeed: 140 + rng.nextDouble() * 160,
size: 6 + rng.nextDouble() * 6,
startRotation: rng.nextDouble() * pi * 2,
rotationSpeed: (rng.nextDouble() - 0.5) * 8,
swayAmplitude: 16 + rng.nextDouble() * 28,
swayFrequency: 1 + rng.nextDouble() * 2,
color: colors[rng.nextInt(colors.length)],
shape: rng.nextBool() ? ConfettiShape.rect : ConfettiShape.circle,
);
});
}