PolygonComponent.regular constructor

PolygonComponent.regular({
  1. required int sides,
  2. required double radius,
  3. Vector2? position,
  4. Vector2? size,
  5. Vector2? scale,
  6. double? angle,
  7. Anchor? anchor,
  8. Iterable<Component>? children,
  9. int? priority,
  10. Paint? paint,
  11. List<Paint>? paintLayers,
  12. ComponentKey? key,
  13. bool? shrinkToBounds,
})

With this constructor you create a regular (equiangular and equilateral) polygon from number of sides and radius anywhere in the 2d-space. It will automatically calculate the size of the Polygon (the bounding box) if no size is given.

Implementation

PolygonComponent.regular({
  required int sides,
  required double radius,
  Vector2? position,
  Vector2? size,
  Vector2? scale,
  double? angle,
  Anchor? anchor,
  Iterable<Component>? children,
  int? priority,
  Paint? paint,
  List<Paint>? paintLayers,
  ComponentKey? key,
  bool? shrinkToBounds,
}) : this(
       List.generate(sides, (i) {
         final angle = tau * i / sides;
         return Vector2(radius * cos(angle), radius * sin(angle));
       }, growable: false),
       position: position,
       size: size,
       scale: scale,
       angle: angle,
       anchor: anchor,
       children: children,
       priority: priority,
       paint: paint,
       paintLayers: paintLayers,
       key: key,
       shrinkToBounds: shrinkToBounds,
     );