utils : slope
find the slope between 2 points
♥0 |
Line 28 |
Modified 2010-12-19 05:35:22 |
MIT License
archived:2017-03-09 18:47:36
ActionScript3 source code
/**
* Copyright nicoptere ( http://wonderfl.net/user/nicoptere )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/ze2y
*/
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
public class Slope extends Sprite
{
public function Slope()
{
addEventListener( Event.ENTER_FRAME, findSlope );
}
public function slope( p0:Point, p1:Point ):Number
{
return ( p1.y - p0.y ) / ( p1.x - p0.x );
}
private function findSlope( e:Event ):void
{
var c:Point = new Point( stage.stageWidth * .5, stage.stageHeight * .5 );
var p:Point = new Point( stage.mouseX, stage.mouseY );
var slope:Number = slope( c, p );
var color:uint = ( slope > 0 ) ? 0xFF0000 : ( ( slope == 0 ) ? 0x0000FF : 0x00FF00 );
graphics.clear();
graphics.lineStyle( 0, color );
graphics.moveTo( c.x, c.y );
graphics.lineTo( p.x, p.y );
}
}
}