Skip to content

Instantly share code, notes, and snippets.

@eka
Created September 16, 2014 21:16
Show Gist options
  • Save eka/050ef6069a55e2564e37 to your computer and use it in GitHub Desktop.
Save eka/050ef6069a55e2564e37 to your computer and use it in GitHub Desktop.
public function drawArc(sprite:FlxSprite, centerX:Float, centerY:Float, radius:Float, startAngle:Float, arcAngle:Float, steps:Int):Void {
//
// Rotate the point of 0 rotation 1/4 turn counter-clockwise.
startAngle -= .25;
//
var twoPI = 2 * Math.PI;
var angleStep = arcAngle / steps;
// var xx = centerX + Math.cos(startAngle * twoPI) * radius;
// var yy = centerY + Math.sin(startAngle * twoPI) * radius;
var xx = centerX + radius * Math.cos(startAngle);
var yy = centerY + radius * Math.sin(startAngle);
var lx = xx;
var ly = yy;
for (i in 0...steps) {
var angle = startAngle + (i * angleStep);
xx = centerX + radius * Math.cos(angle);
yy = centerY + radius * Math.sin(angle);
// xx = centerX + Math.cos(angle * twoPI) * radius;
// yy = centerY + Math.sin(angle * twoPI) * radius;
var lineStyle:LineStyle = {color: FlxColor.WHITE, thickness: 1}
var drawStyle:DrawStyle = {};
trace('from ' + i + " lx:" + lx + " ly:"+ly);
trace('to ' + i + " x:" + xx + " y:"+yy);
// var text = new FlxText(xx, yy, -1, Std.string(i));
// FlxG.state.add(text);
FlxSpriteUtil.drawLine(sprite, lx, ly, xx, yy, {thickness: 5, color: FlxColor.WHITE});
// FlxSpriteUtil.drawLine(sprite, xx, yy, xx+1, yy+1, {thickness: 1, color: FlxColor.WHITE});
lx = xx;
ly = yy;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment