ferguson coons curve
♥0 |
Line 34 |
Modified 2010-03-09 15:42:58 |
MIT License
archived:2017-03-10 17:55:44
ActionScript3 source code
/**
* Copyright arumajirou ( http://wonderfl.net/user/arumajirou )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/6Msj
*/
package {
import flash.display.Sprite;
import flash.display.Graphics;
import flash.geom.*;
import flash.text.*;
public class FlashTest extends Sprite {
public var p0 : Vector3D;
public var p1 : Vector3D;
public var v0 : Vector3D;
public var v1 : Vector3D;
static public var tex : TextField = new TextField();
public function FlashTest() {
// write as3 code here..
tex.autoSize = TextFieldAutoSize.LEFT;
addChild( tex );
const g : Graphics = graphics;
g.lineStyle( 1, 0xff0000 );
p0 = new Vector3D( 0, stage.stageHeight / 2, 0, 1 );
p1 = new Vector3D( stage.stageWidth, stage.stageHeight / 2, 0, 1 );
v0 = new Vector3D( 0, -200, 0, 0 );
v1 = new Vector3D( 0, 200, 0, 0 );
g.moveTo( 0, stage.stageHeight / 2 );
for( var i : Number = 0 ; i < stage.stageWidth ; i++ )
{
var x : Number = fergusonCoons( i / stage.stageWidth, 0, stage.stageWidth, 0, 0 );
var y : Number = fergusonCoons( i / stage.stageWidth, stage.stageHeight / 2, stage.stageHeight /2, -200, 200 );
g.lineTo( x, y );
}
}
public function fergusonCoons( delta : Number, p0 : Number, p1 : Number, v0 : Number, v1 : Number ) : Number
{
return ( Math.pow( delta, 3 ) * ( 2 * (p0-p1) + v0 + v1 ) + Math.pow( delta, 2 ) * ( 3 * ( p1 - p0 ) - v1 - v0 - v0 ) + delta * v0 + p0 );
}
}
}