Line data Source code
1 : import 'dart:math'; 2 : import 'dart:ui'; 3 : 4 : import '../components/mixins/single_child_particle.dart'; 5 : import 'curved_particle.dart'; 6 : import 'particle.dart'; 7 : 8 : /// A particle which rotates its child over the lifespan 9 : /// between two given bounds in radians 10 : class RotatingParticle extends CurvedParticle with SingleChildParticle { 11 : @override 12 : Particle child; 13 : 14 : final double from; 15 : final double to; 16 : 17 0 : RotatingParticle({ 18 : required this.child, 19 : this.from = 0, 20 : this.to = 2 * pi, 21 : double? lifespan, 22 0 : }) : super( 23 : lifespan: lifespan, 24 : ); 25 : 26 0 : double get angle => lerpDouble(from, to, progress) ?? 0; 27 : 28 0 : @override 29 : void render(Canvas canvas) { 30 0 : canvas.save(); 31 0 : canvas.rotate(angle); 32 0 : super.render(canvas); 33 0 : canvas.restore(); 34 : } 35 : }