forked from: Basic:Multiple curves with midpoints

by bradsedito forked from Basic:Multiple curves with midpoints (diff: 1)
♥0 | Line 32 | Modified 2014-02-26 13:23:19 | MIT License
play

ActionScript3 source code

/**
 * Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/cqUv
 */

// forked from nsos's Basic:Multiple curves with midpoints
package
{
import flash.display.Sprite;
public class MultiCurves2 extends Sprite
{
private var numPoints:uint = 9;
public function MultiCurves2()
{
init();
}
private function init():void
{
// first set up an array of random points
var points:Array = new Array();
for (var i:int = 0; i < numPoints; i++)
{
points[i] = new Object();
points[i].x = Math.random() * stage.stageHeight;
points[i].y = Math.random() * stage.stageHeight;
}
graphics.lineStyle(1);
// now move to the first point
graphics.moveTo(points[0].x, points[0].y);
// curve through the rest, stopping at each midpoint
for (i = 1; i < numPoints - 2; i ++)
{
var xc:Number = (points[i].x + points[i + 1].x) / 2;
var yc:Number = (points[i].y + points[i + 1].y) / 2;
graphics.curveTo(points[i].x, points[i].y, xc, yc);
}
// curve through the last two points
graphics.curveTo(points[i].x, points[i].y, points[i+1].x,
points[i+1].y);
}
}
}