一個隨機畫圓弧的效果,有幾個屬性可調整,也不多描述了,
貼一下代碼,有興趣的看一下吧,剛加了下注釋...
//******* draw_arc ************************
//******************* 作者:boenlee *****
//舞台元件:
//可視區域元件--mask
//移動按鈕--up_btn, down_btn, left_btn, right_btn
//文本框--angle_txt, time_txt, r_txt, thickness_txt
//復選按鈕--trace_check, leaf_check
//重畫按鈕--redraw_btn
//庫鏈接元件:
//葉子--leaf
//***************************************************
//畫小於等於45度的圓弧,任意角度開始
//mc:目標mc名稱
//ox:原點x位置
//oy:原點y位置
//r:半徑
//origin_angle:起始角度
//angle:弧的角度,正數順時針畫弧,負數逆時針畫弧
//thickness:線的粗細
//rbg:線的顏色
//alpha:線的透明度
//返回:圓弧終點坐標,終點為角度大的點,與angle符號無關
function draw_small_arc (mc:MovieClip, ox:Number, oy:Number, r:Number, origin_angle:Number, angle:Number,
thickness:Number, rbg:Number, alpha:Number):Object {
var origin_angle:Number = origin_angle % 360;
var angle:Number = angle % 360;
origin_angle = angle < 0 ? origin_angle + angle : origin_angle;
angle = Math.abs (angle);
angle = angle > 45 ? 45 : angle;
var ctrl_r:Number = maintain_digit (1 / cosD (angle / 2) * r, 4);
var ctrl_sin:Number = maintain_digit (sinD (origin_angle + angle / 2), 4);
var ctrl_cos:Number = maintain_digit (cosD (origin_angle + angle / 2), 4);
var org_sin:Number = maintain_digit (sinD (origin_angle), 4);
var org_cos:Number = maintain_digit (cosD (origin_angle), 4);
var achr_sin:Number = maintain_digit (sinD (origin_angle + angle), 4);
var achr_cos:Number = maintain_digit (cosD (origin_angle + angle), 4);
with (mc) {
lineStyle (thickness, rbg, alpha, false, "normal", "none");
moveTo (org_cos * r + ox, org_sin * r + oy);
curveTo (ctrl_cos * ctrl_r + ox, ctrl_sin * ctrl_r + oy, achr_cos * r + ox, achr_sin * r + oy);
}
return {x:achr_cos * r + ox, y:achr_sin * r + oy};
}
//畫小於等於360度的圓弧,任意角度開始
//參數及返回值與draw_small_arc函數相同
function draw_arc (mc:MovieClip, ox:Number, oy:Number, r:Number, origin_angle:Number, angle:Number, thickness:Number,
rbg:Number, alpha:Number):Object {
var origin_angle:Number = angle < 0 ? origin_angle + angle : origin_angle;
var angle:Number = Math.abs (angle);
var times:Number = int (angle / 45);
var last_angle:Number = angle % 45;
if (times >= 8) {
times = 8;
last_angle = 0;
}
for (var i:Number = 0; i < times; i++) {
draw_small_arc (mc, ox, oy, r, 45 * i + origin_angle, 45, thickness, rbg, alpha);
}
return draw_small_arc (mc, ox, oy, r, 45 * times + origin_angle, last_angle, thickness, rbg, alpha);
}
//小數保留
//val:要處理數值
//maintain:保留位數
//返回:處理後的數
function maintain_digit (val:Number, maintain:Number):Number {
var multiple:Number = Math.pow (10, Math.abs (maintain));
return Math.round (val * multiple) / multiple;
}
//以角度為參數計算sin值
function sinD (angle:Number):Number {
return Math.sin (Math.PI / 180 * angle);
}
//以角度為參數計算cos值
function cosD (angle:Number):Number {
return Math.cos (Math.PI / 180 * angle);
}
//隨機顏色
function rnd_color ():Number {
return random (255) << 16 | random (255) << 8 | random (255);
}
//弧線顏色數組,由於隨機顏色比較丑,所以選擇幾個比較好的顏色
var color_arr:Array = [0xFF1111, 0xEDB83D, 0xEBEB1D, 0x99E91F, 0x20E91F, 0x23E4E3, 0x1DC2EB, 0x1B45ED,
0x6F1BED, 0xC21BED, 0xEB1DEB, 0xF017AF, 0xF01784, 0xFFFFFF];
//葉子顏色數組,原因同上
var leaf_color_arr:Array = [0x25EB25, 0xF3F347, 0x4AF09D, 0xF2AD48];
//起始角度
var origin_angle:Number;
//弧的角度
var angle:Number;
//弧度是否隨機
var angle_rnd:Boolean;
//方向
var dir:Number;
//上一個弧的方向
var old_dir:Number;
//弧的個數
var time:Number;
//弧所在圓的坐標
var posx:Number;
var posy:Number;
//弧終點位置
var pos_obj:Object;
//半徑
var r:Number;
//弧線粗細
var thickness:Number;
//是否跟蹤
var is_trace:Boolean = false;
//是否有樹葉生長效果
var leaf_grow:Boolean = false;
//用於畫弧線的mc
var line_mc:MovieClip;
//初始化屬性
function init_prop () {
line_mc.removeMovieClip ();
line_mc = this.createEmptyMovieClip ("line_mc", 1);
line_mc.setMask (mask);
line_mc._x = mask._x;
line_mc._y = mask._y;
origin_angle = random (4) * 90;
angle = get_txt_value (angle_txt, 0,