Skip to content

Instantly share code, notes, and snippets.

@lucasmotta
Last active November 10, 2020 11:52
Show Gist options
  • Save lucasmotta/975907 to your computer and use it in GitHub Desktop.
Save lucasmotta/975907 to your computer and use it in GitHub Desktop.
Distribute children on a path of a star
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