RegularPolygon

public class RegularPolygon: Polygon

RegularPolygon is a is a concrete subclass of Polygon that defines a shape whose sides are uniform (e.g. pentagon, octagon, etc.).

This class defines two variables called sides and phase that represent the number of sides and the initial rotation of the shape (respectively). The default shape is a hexagon.

  • Returns the number of sides in the polygon.

    Assigning a value to this property will change the number of sides and cause the receiver to automatically update its path.

    let f = Rect(100,100,100,100)
    var p = RegularPolygon(frame: f)
    p.sides = 3
    canvas.add(p)
    

    Declaration

    Swift

    public var sides: Int = 6
  • Returns the phase (i.e. rotated beginning position) of the shape. This is not actual rotation, it simply changes where the beginning of the shape is.

    Assigning a value to this property will change the starting position of the beginning of the shape. The shape will still calculate its points based on the frame.

    let f = Rect(100,100,100,100)
    var p = RegularPolygon(frame: f)
    p.phase = M_PI_2
    canvas.add(p)
    

    Declaration

    Swift

    public var phase: Double = 0
  • Initializes a new RegularPolygon.

    Default values are are sides = 6 (i.e. a hexagon), phase = 0.

    Declaration

    Swift

    convenience public init(center: Point, radius: Double = 50.0, sides: Int = 6, phase: Double = 0.0)