快速业务通道

AS2边缘柔化类

作者 佚名技术 来源 服务器技术 浏览 发布时间 2012-07-10


http://www.riacn.com 首页看到一个这样的东西,作者用的是修改MovieClip原型的方法, 这种方法不是很好. 破坏了封装性.用AS2修改了一下.
// AS2 Soft Edge Class
// origin AS1 author : V1.0 by Mario Klingemann
// see




class SoftEdgeClass extends MovieClip
{
static var symbolName:String = "__Packages.SoftEdgeClass";
static var symbolOwner:Function = SoftEdgeClass;
static var symbolLinked = Object.registerClass(symbolName, symbolOwner);

public var work_mc:MovieClip;
public var color:Number = 0;
public var blur:Number = 0;


static function soft(base_mc:MovieClip, name:String, depth:Number,o:Object)
{
var mc = base_mc.attachMovie(symbolName, name, depth,{blur:o.blur,color:o.color,work_mc:base_mc});
// return mc;
}


function SoftEdgeClass()
{
softEdge();
}


function softEdge()
{
var b = work_mc.getBounds(work_mc);
for (var i = 0; i <= blur; i++)
{
lineStyle(3, color, 100 - (100 / blur) * i);
roundRect(b.xMin + i, b.yMin + i, b.xMax - i, b.yMax - i, blur - (i * 2 / 3));
}
lineStyle(3, color, 100);
beginFill(color, 100);
drawRect2(b.xMin - 1, b.yMin - 1, b.xMax + 1, b.yMax + 1);
roundRect(b.xMin, b.yMin, b.xMax, b.yMax, blur);
endFill();
}


function drawRect2(x1, y1, x2, y2)
{
moveTo(x1, y1);
lineTo(x2, y1);
lineTo(x2, y2);
lineTo(x1, y2);
lineTo(x1, y1);
}

function roundRect(x1, y1, x2, y2, r)
{
r = Math.min(Math.abs(r), Math.min(Math.abs(x1 - x2), Math.abs(y1 - y2)) / 2);
var f = 0.707106781186548 * r;
var a = 0.588186525863094 * r;
var b = 0.00579432557070009 * r;
var ux = Math.min(x1, x2);
var uy = Math.min(y1, y2);
var lx = Math.max(x1, x2);
var ly = Math.max(y1, y2);
moveTo(ux + r, uy);
var cx = lx - r;
var cy = uy + r;
lineTo(cx, uy);
curveTo(lx - a, uy + b, cx + f, cy - f);
curveTo(lx - b, uy + a, lx, uy + r);
cy = ly - r;
lineTo(lx, cy);
curveTo(lx - b, ly - a, cx + f, cy + f);
curveTo(lx - a, ly - b, lx - r, ly);
cx = ux + r;
lineTo(cx, ly);
curveTo(ux + a, ly - b, cx - f, cy + f);
curveTo(ux - b, ly - a, ux, ly - r);
cy = uy + r;
lineTo(ux, cy);
curveTo(ux + b, uy + a, cx - f, cy - f);
curveTo(ux + a, uy + b, ux + r, uy);
}
}

关键词:

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号