2007/01/30 | 图书摘录十四:绘制圆形
类别(编程资源) | 评论(0) | 阅读(98) | 发表于 13:28

绘制圆形:
 
1. 创建一个新的 Flash  文档,并将它保存为circle2.fla 。
 2. 将下面的 ActionScript   代码添加到时间轴中的第1  帧:
this.createEmptyMovieClip("circle_mc", 10);
circle_mc._x = 100;
circle_mc._y = 100;
drawCircle(circle_mc, 100, 0x99FF00, 100);
function drawCircle(target_mc:MovieClip, radius:Number, fillColor:Number, fillAlpha:Number):Void {
var x:Number = radius;
var y:Number = radius;
with (target_mc) {
beginFill(fillColor, fillAlpha);
moveTo(x + radius, y);
curveTo(radius + x, Math.tan(Math.PI / 8) * radius + y,
Math.sin(Math.PI / 4) * radius + x, Math.sin(Math.PI / 4) * radius + y);
curveTo(Math.tan(Math.PI / 8) * radius + x, radius + y, x, radius + y);
curveTo(-Math.tan(Math.PI / 8) * radius + x, radius+ y, -Math.sin(Math.PI / 4) * radius + x, Math.sin(Math.PI / 4) * radius + y);
curveTo(-radius + x, Math.tan(Math.PI / 8) * radius + y, -radius + x, y);
curveTo(-radius + x, -Math.tan(Math.PI / 8) * radius + y, -Math.sin(Math.PI / 4) * radius + x, -Math.sin(Math.PI / 4) * radius + y);curveTo(-Math.tan(Math.PI / 8) * radius + x, -radius + y, x, -radius + y);
curveTo(Math.tan(Math.PI / 8) * radius + x, -radius + y, Math.sin(Math.PI / 4) * radius + x, -Math.sin(Math.PI / 4) * radius + y);
curveTo(radius + x, -Math.tan(Math.PI / 8) * radius + y, radius + x, y);
endFill();
}
}
3. 保存Flash 文档,然后选择 “控制” >“测试影片”对该SWF 文件进行测试。
   
此代码可创建一个更复杂、更逼真的圆形。此示例不止调用了四次curveTo()方法,而是调用了八次 curveTo() 方法,使形状具有更圆滑的外观。

注:代码实现的原理没有时间去考证了,需要的时候就来抄吧。

0

评论Comments