topical media & game development
animation-ch04-MultiCurves3Filled.ax
animation-ch04-MultiCurves3Filled.ax
[swf]
[flash]
flex
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
public class @ax-animation-ch04-MultiCurves3Filled extends Sprite
{
public function @ax-animation-ch04-MultiCurves3Filled()
{
init();
}
private function init():void
{
var points:Array = new Array();
for (var i:int = 0; i < 9; i++)
{
points[i] = new Object();
points[i].x = Math.random() * stage.stageHeight;
points[i].y = Math.random() * stage.stageHeight;
}
// find the first midpoint and move to it
var xc1:Number = (points[0].x + points[points.length - 1].x) / 2;
var yc1:Number = (points[0].y + points[points.length - 1].y) / 2;
graphics.lineStyle(1);
graphics.beginFill(0xff00ff);
graphics.moveTo(xc1, yc1);
// curve through the rest, stopping at midpoints
for (i = 0; i < points.length - 1; 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 point, back to the first midpoint
graphics.curveTo(points[i].x, points[i].y, xc1, yc1);
graphics.endFill();
}
}
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.