Author
Travis Kirton


Stars

Creating a star is a lot like creating a circle, the only difference is that you also specify variables for its inner and outer radius.

let star = Star(center: canvas.center, pointCount: 5, innerRadius: 10, outerRadius: 20)

Regular Polygons

Creating a regular-sided polygon is even easier… The major difference here is you specify the number of sides and the phase.

The phase is it initial rotation of the shape… You can specify a value (in radians) if you want the shape’s points to start in a different position.

//defaults to 5 sides and 0 phase
let hexagon = RegularPolygon(center: canvas.center, radius: 90)
let pentagon = RegularPolygon(center: canvas.center, radius: 90, sides: 5, phase: M_PI_4)

Example

let dx = Vector(x: canvas.width/5, y: 0)
let star = Star(center: canvas.center-dx, pointCount: 20, innerRadius: 80, outerRadius: 100)
let hexagon = RegularPolygon(center: canvas.center + dx, radius: 90, sides: 6, phase: 0)
canvas.add(star)
canvas.add(hexagon)