Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Support curveTo #1

Merged
merged 1 commit into from

3 participants

@leethomason

A simple, initial implementation of curveTo(). A couple areas of improvement are in the notes; I'm happy to tune the function, but wanted to get unblocked from the API not being present at all.

@jonathanrpace

Great! Don't suppose you fancy tackling cubicCurveTo while you're there? :)

One suggestion - is it worth passing the 'numDivisions' as an optional parameter, with a default value of 8? That way if people need to tweak it, there's no need to open up the class.

@robsilv
Owner

Thanks Lee, your contributions are obviously very welcome! :D

@leethomason

@jonathanrpace, Good reminder on the cubics. Beginning of the week I'll add the cubics, and also add a proper error metric for the quadratics so it can compute a reasonable number of "numDivisions" for you. That will be much better than the current hardcoded value, and if we stiff need tuning that can be added later.

@robsilv You are welcome - glad to see this getting momentum!

@jonathanrpace jonathanrpace merged commit 0e711d3 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 5, 2012
  1. @leethomason

    Add support for curveTo

    leethomason authored
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 0 deletions.
  1. +27 −0 extension/src/starling/display/Graphics.as
View
27 extension/src/starling/display/Graphics.as
@@ -14,6 +14,8 @@ package starling.display
{
private var _currentFillColor :uint;
private var _currentFillAlpha :Number;
+ private var _currentX :Number;
+ private var _currentY :Number;
private var _strokeThickness :Number
private var _strokeColor :uint;
@@ -43,6 +45,8 @@ package starling.display
child.dispose();
_container.removeChildAt(0);
}
+ _currentX = NaN;
+ _currentY = NaN;
}
public function beginFill(color:uint, alpha:Number = 1.0):void
@@ -179,6 +183,27 @@ package starling.display
_currentFill.addVertex(x, y, _currentFillColor, _currentFillAlpha );
}
}
+ _currentX = x;
+ _currentY = y;
+ }
+
+ public function curveTo(cx:Number, cy:Number, a2x:Number, a2y:Number):void
+ {
+ // A couple of improvements to this code:
+ // - Should be unified with 'lineTo' so there is prefix & postfix code, but the main code calls "addVertex" directly.
+ // - "8" subdivisions should be experimented with: 2-16 is about right, depending on the screen size of the curve.
+
+ for ( var j:int = 1; j <= 8; ++j ) {
+ var t:Number = Number(j) / 8.0;
+ var oneMinusT:Number = (1.0 - t);
+ var bx:Number = oneMinusT * oneMinusT * _currentX + 2.0 * oneMinusT * t * cx + t * t * a2x;
+ var by:Number = oneMinusT * oneMinusT * _currentY + 2.0 * oneMinusT * t * cy + t * t * a2y;
+
+ lineTo( bx, by );
+ }
+
+ _currentX = a2x;
+ _currentY = a2y;
}
public function moveTo(x:Number, y:Number):void
@@ -202,6 +227,8 @@ package starling.display
_currentFill.addVertex(x, y, _currentFillColor, _currentFillAlpha );
}
}
+ _currentX = x;
+ _currentY = y;
}
private function beginStroke():void
Something went wrong with that request. Please try again.