createStar static method

List<Offset> createStar(
  1. int points,
  2. double outerRadius,
  3. double innerRadius,
  4. Offset center, [
  5. double rotation = 0,
])

Creates a star with the given number of points.

points is the number of points. outerRadius is the outer radius of the star. innerRadius is the inner radius of the star. center is the center of the star. rotation is the rotation angle in radians. Defaults to 0.

Implementation

static List<Offset> createStar(
  int points,
  double outerRadius,
  double innerRadius,
  Offset center, [
  double rotation = 0,
]) {
  final starPoints = <Offset>[];
  final angleStep = math.pi / points;

  for (int i = 0; i < points * 2; i++) {
    final radius = i.isEven ? outerRadius : innerRadius;
    final angle = i * angleStep + rotation;
    final x = center.dx + radius * math.cos(angle);
    final y = center.dy + radius * math.sin(angle);
    starPoints.add(Offset(x, y));
  }

  return starPoints;
}