点击这里看演示 贴一下代码有兴趣的看一下吧刚加了下注释 //******************* 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;//用于画弧线的mcvar 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, 0, 10, 360); if (angle == 0) { angle_rnd = true; } else { angle_rnd = false; } dir = random (2) ? 1 : -1; posx = random (100) - 50; posy = random (100) - 50; time = get_txt_value (time_txt, 50, 10, 10, 200); r = get_txt_value (r_txt, 20, 5, 5, 50); thickness = get_txt_value (thickness_txt, 5, 1, 1, 10);}//主函数function main () { if (--time > 0) { dir = random (2) ? 1 : -1; origin_angle = angle; //如果当前弧的方向与前一个的不同,计算当前弧所在圆的原点位置 if (dir old_dir == 0) { posx = cosD (origin_angle) * 2 * r; posy = sinD (origin_angle) * 2 * r; origin_angle = 180; } if (angle_rnd) { angle = dir * (random (50) 50); } else { angle = dir * Math.abs (angle); } pos_obj = draw_arc (line_mc, posx, posy, r, origin_angle, angle, thickness, color_arr[random (color_arr.length)], 100); //加载树叶 if (leaf_grow) { line_mc.attachMovie ("leaf", "leaf" time, time, {_x:pos_obj.x, _y:pos_obj.y, _rotation:random (360), _xscale:random (50) r * 2 thickness * 5, _yscale:random (50) r * 2 thickness * 5, _alpha:random (100) thickness * 5}); var leaf_color:Color = new Color (line_mc["leaf" time]); leaf_color.setRGB (leaf_color_arr[random (leaf_color_arr.length)]); } //跟踪 if (is_trace) { line_mc._x = mask._x - pos_obj.x; line_mc._y = mask._y - pos_obj.y; } old_dir = dir; } else { delete line_mc.onEnterFrame; }}//获取文本框内容,为数值//txt_name:文本框名称//nan_val:文本内容非数字时所取值//zero_val:文本内容为0时所取值//min_val:文本内容最小值//max_val:文本内容最大值function get_txt_value (txt_name:TextField, nan_val:Number, zero_val:Number, min_val:Number, max_val:Number) { if (isNaN (Number (txt_name.text))) { txt_name.text = String (nan_val); } else if (Number (txt_name.text) == 0) { txt_name.text = String (zero_val); } else if (Number (txt_name.text) < min_val) { txt_name.text = String (min_val); } else if (Number (txt_name.text) > max_val) { txt_name.text = String (max_val); } return Number (txt_name.text);}//重画redraw_btn.onRelease = function () { delete line_mc.onEnterFrame; init_prop (); line_mc.onEnterFrame = main;};//选择是否跟踪trace_check.onRelease = function () { is_trace = !is_trace; this.gotoAndStop (Number (is_trace) 1);};//选择是否生长树叶leaf_check.onRelease = function () { leaf_grow = !leaf_grow; this.gotoAndStop (Number (leaf_grow) 1);};var keep_moving:MovieClip = this.createEmptyMovieClip ("keep_moving", 2);var speed:Number = 10;//移动line_mcfunction moving (speedx:Number, speedy:Number) { keep_moving.onEnterFrame = function () { line_mc._x = speedx; line_mc._y = speedy; };}//停止移动function stop_move () { delete keep_moving.onEnterFrame;}//按钮控制up_btn.onPress = function () { moving (0, speed);};down_btn.onPress = function () { moving (0, -speed);};left_btn.onPress = function () { moving (speed, 0);};right_btn.onPress = function () { moving (-speed, 0);};up_btn.onRelease = up_btn.onReleaseOutside = down_btn.onRelease = down_btn.onReleaseOutside = left_btn.onRelease = left_btn.onReleaseOutside = right_btn.onRelease = right_btn.onReleaseOutside = function () { stop_move ();};//键盘控制var key_lis:Object = new Object ();key_lis.onKeyDown = function () { switch (Key.getCode ()) { case 37 : moving (speed, 0); break; case 38 : moving (0, speed); break; case 39 : moving (-speed, 0); break; case 40 : moving (0, -speed); break; }};key_lis.onKeyUp = function () { stop_move ();};Key.addListener (key_lis);init_prop ();line_mc.onEnterFrame = main;
本文仅代表作者观点,不代表本站立场。 本文系作者授权发表,未经许可,不得转载。本文地址:/3Dsheji/170527.html
《原神》干枯的种子解密教程 生命之谷的居民成就解锁 游戏攻略
《原神》2.6版迪奥娜出装与配队教程 游戏攻略
《原神》天目影打刀图纸获取教程 天目影打刀图纸怎么获得 游戏攻略
《原神》2.6版神里绫华简要培养教程 游戏攻略
《原神》层岩巨渊全解谜宝箱获取教程_ 游戏攻略
《原神》2.6版宵宫单体输出装备选择与配队教程 游戏攻略
《原神》2.6版机关棋谭玩法与第一日关卡教程 游戏攻略
《原神》岩中幽谷副本解锁教程 游戏攻略
打开手机扫描上面的二维码
潘少俊衡
Powered By EmpireCMS
爱享小站
中德益农
谷姐神农
环亚肥料
桂ICP备2023010378号-4
桂公网备 45012202000125号
联系我们
商业合作
广告投放
投稿须知
使用手机软件扫描微信二维码
关注我们可获取更多热点资讯
感谢潘少俊衡友情技术支持