用ActionScript画虚线

原创 2006年06月12日 11:11:00
 /*-------------------------------------------------------------
mc.dashTo is a method for drawing dashed (and dotted)
lines. I made this to extend the lineTo function because it
doesn?t have the cutom line types that the in program
line tool has. To make a dotted line, specify a dash length
between .5 and 1.
-------------------------------------------------------------*/

MovieClip.prototype.dashTo = function(startx, starty, endx, endy, len, gap) {
// ==============
// mc.dashTo() - by Ric Ewing (ric@formequalsfunction.com) - version 1.2 - 5.3.2002
//
// startx, starty = beginning of dashed line
// endx, endy = end of dashed line
// len = length of dash
// gap = length of gap between dashes
// ==============
//
// if too few arguments, bail
if (arguments.length < 6) {
return false;
}
// init vars
var seglength, deltax, deltay, segs, cx, cy;
// calculate the legnth of a segment
seglength = len + gap;
// calculate the length of the dashed line
deltax = endx - startx;
deltay = endy - starty;
delta = Math.sqrt((deltax * deltax) + (deltay * deltay));
// calculate the number of segments needed
segs = Math.floor(Math.abs(delta / seglength));
// get the angle of the line in radians
radians = Math.atan2(deltay,deltax);
// start the line here
cx = startx;
cy = starty;
// add these to cx, cy to get next seg start
deltax = Math.cos(radians)*seglength;
deltay = Math.sin(radians)*seglength;
// loop through each seg
for (var n = 0; n < segs; n++) {
this.moveTo(cx,cy);
this.lineTo(cx+Math.cos(radians)*len,cy+Math.sin(radians)*len);
cx += deltax;
cy += deltay;
}
// handle last segment as it is likely to be partial
this.moveTo(cx,cy);
delta = Math.sqrt((endx-cx)*(endx-cx)+(endy-cy)*(endy-cy));
if(delta>len){
// segment ends in the gap, so draw a full dash
this.lineTo(cx+Math.cos(radians)*len,cy+Math.sin(radians)*len);
} else if(delta>0) {
// segment is shorter than dash so only draw what is needed
this.lineTo(cx+Math.cos(radians)*delta,cy+Math.sin(radians)*delta);
}
// move the pen to the end position
this.moveTo(endx,endy);
};
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

as3代码画虚线源码

  • 2015-09-01 15:43
  • 335KB
  • 下载

画虚线

实际项目中需要画竖着的虚线,在网上没找到。。。就改造了一下画横着的虚线方法。/** * 画虚线 * * @param frame 虚线的frame * @param isTrans ...

鼠标画虚线框放大图片

  • 2009-09-22 17:54
  • 3.30MB
  • 下载

iOS画虚线方法

我们公司有一个UI需要用虚线,美工给了图片,但我觉得不好,因为图片占用内存会很大,不利于App的精简,于是研究了一下iOS绘制虚线的方法,其实跟绘制直线是一样的,只有一个部分不一样,下面贴出我的代码,...

画虚线实例

IOS画虚线边框

iOS 画虚线的重新理解

之前写了一篇画虚线的文章,只是做了效果,并没有对其画的过程原来深刻理解,当时只是为了业务需求。今天刚刚好遇到群里有人问了,回头又重新理解了一下。 群里朋友 需求是彩色虚线。效果如图 完整代码如下: ...

Android画虚线

  • 2016-06-29 10:18
  • 994KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)