/** Moves an Actor along an n-sided polygon. The code includes diffent ways to connect each point of the polygon. "regular", rounded inwards/outwards, star-shaped. */ class PolygonRole : ActionRole { @Attribute var sides = 5 @Attribute var sideLength = 200 override fun createAction() : Action { val path = Path().apply { for (i in 0 until sides) { // by is a vector length `sideLength`, in the direction we need to move for this side of the polygon. val by = Angle.degrees( 360 / sides * i ).vector() * sideLength // Choose how you want to connect the points of the polygon. // Keep only ONE example uncommented ! // A straight line between each point of the polygon //lineBy( by ) // Or use a slightly concave curve instead //circularArcBy( by, sideLength * 1.2, false, false ) // Or use a slightly convex curve //circularArcBy( by, sideLength * 1.2, false, true ) // Or A star shape, by using two lines, on each side of the polygon. val inwards = by.perpendicular() * 0.2 // 0.2 determines how pointed the star is. lineBy( by/2 + inwards ) lineBy( by/2 - inwards ) } } return path.relativeTo( actor.position ).follow( actor.position, 5 ).forever() } }