paint method
Called each time the AnimatedBackground needs to repaint.
The canvas provided in the context is already offset by the amount
specified in offset
, however the parameter is provided to make the
signature of the methods uniform.
Implementation
@override
void paint(PaintingContext context, Offset offset) {
var canvas = context.canvas;
var paint = Paint()..style = PaintingStyle.fill;
canvas.drawPaint(Paint()..color = _backgroundColor);
canvas.translate(center!.dx, center!.dy);
int i = 0;
double time = DateTime.now().millisecondsSinceEpoch.toDouble() / 1000.0;
for (Star star in stars!) {
if (star.position!.dx == 0 || star.distance <= 0.0) continue;
paint.color = Color.fromARGB(
0x80,
(math.sin(0.3 * i + 0 + time) * 64.0 + 190.0).floor(),
(math.sin(0.3 * i + 2 + time) * 64.0 + 190.0).floor(),
(math.sin(0.3 * i + 4 + time) * 64.0 + 190.0).floor(),
);
var x = star.targetPosition.dx / star.distance * 1.02;
var y = star.targetPosition.dy / star.distance * 1.02;
double z = 1.0 / star.distance * 6.0 + 1.0;
paint.strokeWidth = z;
canvas.drawLine(
Offset(x, y),
star.position!,
paint,
);
i++;
}
canvas.translate(-center!.dx, -center!.dy);
}