-
-
Save lucasmotta/975907 to your computer and use it in GitHub Desktop.
Distribute children on a path of a star
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static function star(items : Array, points : uint, innerRadius : Number = 50, outerRadius : Number = 100, align : String = null) : Distribute | |
{ | |
var path : Path = new Path(); | |
path.offset = DistributeAlign.getOffset(Math.max(innerRadius, outerRadius) * 2, Math.max(innerRadius, outerRadius) * 2, align); | |
var step : Number,halfStep : Number, rot : Number, px : int, py : int, i : int; | |
step = (Math.PI * 2) / points; | |
halfStep = step / 2; | |
rot = Math.PI / (points % 4 ? 2 : 4); | |
px = Math.round(Math.cos(- rot) * outerRadius); | |
py = Math.round(Math.sin(- rot) * outerRadius); | |
path.add(new Point(px, py)); | |
for (i = 1; i <= points; i++) | |
{ | |
px = Math.round(Math.cos((step * i) - halfStep - rot) * innerRadius); | |
py = Math.round(Math.sin((step * i) - halfStep - rot) * innerRadius); | |
path.add(new Point(px, py)); | |
px = Math.round(Math.cos((step * i) - rot) * outerRadius); | |
py = Math.round(Math.sin((step * i) - rot) * outerRadius); | |
path.add(new Point(px, py)); | |
} | |
return new Distribute(items, path); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment