show method

void show(
  1. Canvas canvas,
  2. double width,
  3. double height,
  4. Paint paint,
  5. bool hasTrail,
  6. OutlinedBorder shape,
  7. bool fillShape,
  8. int trailSteps,
  9. double trailLength,
)

Implementation

void show(
  Canvas canvas,
  double width,
  double height,
  Paint paint,
  bool hasTrail,
  OutlinedBorder shape,
  bool fillShape,
  int trailSteps,
  double trailLength,
) {
  if (z <= 0) return;

  final double sx = (x / z) * width / 2 + width / 2;
  final double sy = (y / z) * height / 2 + height / 2;

  if (sx < -_maxSize ||
      sx > width + _maxSize ||
      sy < -_maxSize ||
      sy > height + _maxSize) {
    return;
  }

  double r = (1 - z / width) * _maxSize;
  if (r < 0) r = 0;

  paint.color = color;
  final bool hasRotation = rotation != 0;
  final double angle = atan2(y, x);

  if (hasRotation) {
    canvas
      ..save()
      ..translate(sx, sy)
      ..rotate(angle + rotation);
    final rect = Rect.fromCircle(center: Offset.zero, radius: r);
    canvas
      ..drawPath(shape.getOuterPath(rect), paint)
      ..restore();
  } else {
    final rect = Rect.fromCircle(center: Offset(sx, sy), radius: r);
    canvas.drawPath(shape.getOuterPath(rect), paint);
  }

  if (hasTrail) {
    final double tl = r * trailLength;

    for (int i = 1; i <= trailSteps; i++) {
      final double t = i / trailSteps;

      final double tx = sx - cos(angle) * tl * t;
      final double ty = sy - sin(angle) * tl * t;

      final double tr = r * (1 - t);
      final double alpha = (1 - t) * 0.4;

      paint.color = color.withValues(alpha: alpha);

      if (hasRotation) {
        canvas
          ..save()
          ..translate(tx, ty)
          ..rotate(angle + rotation);
        final tRect = Rect.fromCircle(center: Offset.zero, radius: tr);
        canvas
          ..drawPath(shape.getOuterPath(tRect), paint)
          ..restore();
      } else {
        final tRect = Rect.fromCircle(center: Offset(tx, ty), radius: tr);
        canvas.drawPath(shape.getOuterPath(tRect), paint);
      }
    }
    pz = z;
  }
}