In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Basic:Multiple curves with midpoints

Get Adobe Flash player
by nsos 13 Jan 2012
    Embed
/**
 * Copyright nsos ( http://wonderfl.net/user/nsos )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/orte
 */

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);
}
}
}