第四章 渲染技术Ⅱ[FL 基理译]
2009-05-30 12:08:30 来源:WEB开发网图4-2 带有中间点的多线条
注意,图4-2中第一个中间点和最后一个中间点都没有被使用,第一个和最后一个原始点留作曲线的两个端点,只需在第二个点和倒数第二个点之间进行连接。这里是前一个例子的升级版,文档类 MultiCurve2.as:
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);
}
}
}
更多精彩
赞助商链接