createPath method

  1. @override
Path createPath()
override

Returns the path for this glyph shape centered at origin.

Implementation

@override
Path createPath() {
  final outerRadius = size / 2;
  final innerRadius = outerRadius * innerRadiusFactor;
  final path = Path();

  final angleStep = 3.141592653589793 / points; // pi / points

  for (int i = 0; i < points * 2; i++) {
    final angle = i * angleStep - 1.5707963267948966; // Start from top
    final radius = i.isEven ? outerRadius : innerRadius;
    final px = radius * _cos(angle);
    final py = radius * _sin(angle);

    if (i == 0) {
      path.moveTo(px, py);
    } else {
      path.lineTo(px, py);
    }
  }

  path.close();
  return path;
}