分享
 
 
 

com.flashvan.Graphic类

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

// ***********************************************************************************************

// ______

// .-" "-.

// / AOL // | |

// |, .-. .-. ,|

// | )(__/ \__)( |

// |/ /\ \|

// (@_ (_ ^^ _)

// _ ) \_______\__|IIIIII|__/__________________________

// (_)@8@8{}<________|-\IIIIII/-|___________________________>

// )_/ \ /

// (@ `--------` AOL FLASH STUDIO

//

// ***********************************************************************************************

//

// @FileName Graphic.as

// @Description 图形类

// @Package com.flashvan

// @Author AOL

// @Email jeremy1982@21cn.com

// @Create 2004.7.18

// @LastChange 2004.7.18

// @History

//

// ***********************************************************************************************

dynamic class com.flashvan.Graphic extends MovieClip

{

static var symbolName:String = "__Packages.com.flashvan.Graphic";

static var symbolOwner:Function = com.flashvan.Graphic;

static var symbolLinked = Object.registerClass(symbolName, symbolOwner);

function Graphic()

{

}

static function create(base_mc:MovieClip, name:String, depth:Number,o:Object)

{

var mc = base_mc.attachMovie(symbolName, name, depth,o);

return mc;

}

function drawRect(x1:Number, y1:Number, x2:Number, y2:Number):Void

{

moveTo(x1,y1);

lineTo(x2,y1);

lineTo(x2,y2);

lineTo(x1,y2);

lineTo(x1,y1);

}

function drawLine(x1:Number, y1:Number, x2:Number, y2:Number):Void

{

}

function fillRect(x:Number, y:Number, width:Number, height:Number):Void

{

}

// drawRoundRect

// x - x position of fill

// y - y position of fill

// w - width of fill

// h - height of fill

// r - corner radius of fill :: number or object {br:#,bl:#,tl:#,tr:#}

// c - hex color of fill :: number or array [0x######,0x######]

// alpha - alpha value of fill :: number or array [0x######,0x######]

// rot - rotation of fill :: number or matrix object {matrixType:"box",x:#,y:#,w:#,h:#,r:(#*(Math.PI/180))}

// gradient - type of gradient "linear" or "radial"

// ratios - (optional :: default [0,255]) - specifies the distribution of colors :: array [#,#];

function drawRoundRect(x:Number,y:Number,w:Number,h:Number,r,c,alpha,rot,gradient:String,ratios)

{

if (typeof r == "object") {

var rbr = r.br //bottom right corner

var rbl = r.bl //bottom left corner

var rtl = r.tl //top left corner

var rtr = r.tr //top right corner

}

else

{

var rbr = rbl = rtl = rtr = r;

}

// if color is an object then allow for complex fills

if(typeof c == "object")

{

if (typeof alpha != "object")

var alphas = [alpha,alpha];

else

var alphas = alpha;

if (ratios == undefined)

var ratios = [ 0, 0xff ];

var sh = h *.7

if (typeof rot != "object")

var matrix = {matrixType:"box", x:-sh, y:sh, w:w*2, h:h*4, r:rot * 0.0174532925199433 }

else

var matrix = rot;

if (gradient == "radial")

beginGradientFill( "radial", c, alphas, ratios, matrix );

else

beginGradientFill( "linear", c, alphas, ratios, matrix );

}

else if (c != undefined)

{

beginFill (c, alpha);

}

// Math.sin and Math,tan values for optimal performance.

// Math.rad = Math.PI/180 = 0.0174532925199433

// r*Math.sin(45*Math.rad) = (r*0.707106781186547);

// r*Math.tan(22.5*Math.rad) = (r*0.414213562373095);

//bottom right corner

r = rbr;

var a = r - (r*0.707106781186547); //radius - anchor pt;

var s = r - (r*0.414213562373095); //radius - control pt;

moveTo ( x+w,y+h-r);

lineTo ( x+w,y+h-r );

curveTo( x+w,y+h-s,x+w-a,y+h-a);

curveTo( x+w-s,y+h,x+w-r,y+h);

//bottom left corner

r = rbl;

var a = r - (r*0.707106781186547);

var s = r - (r*0.414213562373095);

lineTo ( x+r,y+h );

curveTo( x+s,y+h,x+a,y+h-a);

curveTo( x,y+h-s,x,y+h-r);

//top left corner

r = rtl;

var a = r - (r*0.707106781186547);

var s = r - (r*0.414213562373095);

lineTo ( x,y+r );

curveTo( x,y+s,x+a,y+a);

curveTo( x+s,y,x+r,y);

//top right

r = rtr;

var a = r - (r*0.707106781186547);

var s = r - (r*0.414213562373095);

lineTo ( x+w-r,y );

curveTo( x+w-s,y,x+w-a,y+a);

curveTo( x+w,y+s,x+w,y+r);

lineTo ( x+w,y+h-r );

if (c != undefined)

endFill();

}

// ==============

// mc.drawOval() - by Ric Ewing (ric@formequalsfunction.com) - version 1.1 - 4.7.2002

//

// x, y = center of oval

// radius = radius of oval. If [optional] yRadius is defined, r is the x radius.

// yRadius = [optional] y radius of oval.

// ==============

function drawOval(x:Number, y:Number, radius:Number, yRadius:Number):Void

{

if (arguments.length<3)

{

return;

}

// init variables

var theta:Number, xrCtrl:Number, yrCtrl:Number, angle:Number, angleMid:Number;

var px:Number, py:Number, cx:Number, cy:Number;

// if only yRadius is undefined, yRadius = radius

if (yRadius == undefined)

{

yRadius = radius;

}

// covert 45 degrees to radians for our calculations

theta = Math.PI/4;

// calculate the distance for the control point

xrCtrl = radius/Math.cos(theta/2);

yrCtrl = yRadius/Math.cos(theta/2);

// start on the right side of the circle

angle = 0;

moveTo(x+radius, y);

// this loop draws the circle in 8 segments

for (var i = 0; i<8; i++)

{

// increment our angles

angle += theta;

angleMid = angle-(theta/2);

// calculate our control point

cx = x+Math.cos(angleMid)*xrCtrl;

cy = y+Math.sin(angleMid)*yrCtrl;

// calculate our end point

px = x+Math.cos(angle)*radius;

py = y+Math.sin(angle)*yRadius;

// draw the circle segment

curveTo(cx, cy, px, py);

}

}

// ==============

// mc.drawArc() - by Ric Ewing (ric@formequalsfunction.com) - version 1.5 - 4.7.2002

//

// x, y = This must be the current pen position... other values will look bad

// radius = radius of Arc. If [optional] yRadius is defined, then r is the x radius

// arc = sweep of the arc. Negative values draw clockwise.

// startAngle = starting angle in degrees.

// yRadius = [optional] y radius of arc. Thanks to Robert Penner for the idea.

// ==============

// Thanks to: Robert Penner, Eric Mueller and Michael Hurwicz for their contributions.

// ==============

function drawArc(x:Number, y:Number, radius:Number, arc:Number, startAngle:Number, yRadius:Number)

{

if (arguments.length<5)

{

return;

}

// if yRadius is undefined, yRadius = radius

if (yRadius == undefined)

{

yRadius = radius;

}

// Init vars

var segAngle:Number, theta:Number, angle:Number, angleMid:Number, segs:Number;

var ax:Number, ay:Number, bx:Number, by:Number, cx:Number, cy:Number;

// no sense in drawing more than is needed :)

if (Math.abs(arc)>360)

{

arc = 360;

}

// Flash uses 8 segments per circle, to match that, we draw in a maximum

// of 45 degree segments. First we calculate how many segments are needed

// for our arc.

segs = Math.ceil(Math.abs(arc)/45);

// Now calculate the sweep of each segment

segAngle = arc/segs;

// The math requires radians rather than degrees. To convert from degrees

// use the formula (degrees/180)*Math.PI to get radians.

theta = -(segAngle/180)*Math.PI;

// convert angle startAngle to radians

angle = -(startAngle/180)*Math.PI;

// find our starting points (ax,ay) relative to the secified x,y

ax = x-Math.cos(angle)*radius;

ay = y-Math.sin(angle)*yRadius;

// if our arc is larger than 45 degrees, draw as 45 degree segments

// so that we match Flash's native circle routines.

if (segs>0)

{

// Loop for drawing arc segments

for (var i = 0; i// increment our angle

angle += theta;

// find the angle halfway between the last angle and the new

angleMid = angle-(theta/2);

// calculate our end point

bx = ax+Math.cos(angle)*radius;

by = ay+Math.sin(angle)*yRadius;

// calculate our control point

cx = ax+Math.cos(angleMid)*(radius/Math.cos(theta/2));

cy = ay+Math.sin(angleMid)*(yRadius/Math.cos(theta/2));

// draw the arc segment

curveTo(cx, cy, bx, by);

}

}

// In the native draw methods the user must specify the end point

// which means that they always know where they are ending at, but

// here the endpoint is unknown unless the user calculates it on their

// own. Lets be nice and let save them the hassle by passing it back.

return {x:bx, y:by};

}

// ==============

// mc.drawBurst() - by Ric Ewing (ric@formequalsfunction.com) - version 1.4 - 4.7.2002

//

// x, y = center of burst

// sides = number of sides or points

// innerRadius = radius of the indent of the curves

// outerRadius = radius of the outermost points

// angle = [optional] starting angle in degrees. (defaults to 0)

// ==============

function drawBurst(x:Number, y:Number, sides:Number, innerRadius:Number, outerRadius:Number, angle:Number)

{

if(arguments<5)

{

return;

}

if (sides>2)

{

// init vars

var step:Number, halfStep:Number, qtrStep:Number, start:Number, n:Number;

var dx:Number, dy:Number, cx:Number, cy:Number;

// calculate length of sides

step = (Math.PI*2)/sides;

halfStep = step/2;

qtrStep = step/4;

// calculate starting angle in radians

start = (angle/180)*Math.PI;

moveTo(x+(Math.cos(start)*outerRadius), y-(Math.sin(start)*outerRadius));

// draw curves

for (n=1; n<=sides; n++)

{

cx = x+Math.cos(start+(step*n)-(qtrStep*3))*(innerRadius/Math.cos(qtrStep));

cy = y-Math.sin(start+(step*n)-(qtrStep*3))*(innerRadius/Math.cos(qtrStep));

dx = x+Math.cos(start+(step*n)-halfStep)*innerRadius;

dy = y-Math.sin(start+(step*n)-halfStep)*innerRadius;

curveTo(cx, cy, dx, dy);

cx = x+Math.cos(start+(step*n)-qtrStep)*(innerRadius/Math.cos(qtrStep));

cy = y-Math.sin(start+(step*n)-qtrStep)*(innerRadius/Math.cos(qtrStep));

dx = x+Math.cos(start+(step*n))*outerRadius;

dy = y-Math.sin(start+(step*n))*outerRadius;

curveTo(cx, cy, dx, dy);

}

}

};

function drawPoly (x:Number, y:Number, sides:Number, radius:Number, angle:Number)

{

if (arguments.length<4)

{

return;

}

// convert sides to positive value

var count:Number = Math.abs(sides);

// check that count is sufficient to build polygon

if (count>2)

{

// init vars

var step:Number, start:Number, n:Number, dx:Number, dy:Number;

// calculate span of sides

step = (Math.PI*2)/sides;

// calculate starting angle in radians

start = (angle/180)*Math.PI;

moveTo(x+(Math.cos(start)*radius), y-(Math.sin(start)*radius));

// draw the polygon

for (n=1; n<=count; n++)

{

dx = x+Math.cos(start+(step*n))*radius;

dy = y-Math.sin(start+(step*n))*radius;

lineTo(dx, dy);

}

}

}

// ==============

// mc.drawWedge() - by Ric Ewing (ric@formequalsfunction.com) - version 1.3 - 6.12.2002

//

// x, y = center point of the wedge.

// startAngle = starting angle in degrees.

// arc = sweep of the wedge. Negative values draw clockwise.

// radius = radius of wedge. If [optional] yRadius is defined, then radius is the x radius.

// yRadius = [optional] y radius for wedge.

// ==============

// Thanks to: Robert Penner, Eric Mueller and Michael Hurwicz for their contributions.

// ==============

function drawWedge(x:Number, y:Number, startAngle:Number, arc:Number, radius:Number, yRadius:Number)

{

if (arguments.length<5)

{

return;

}

// move to x,y position

moveTo(x, y);

// if yRadius is undefined, yRadius = radius

if (yRadius == undefined)

{

yRadius = radius;

}

// Init vars

var segAngle:Number, theta:Number, angle:Number, angleMid:Number, segs:Number;

var ax:Number, ay:Number, bx:Number, by:Number, cx:Number, cy:Number;

// limit sweep to reasonable numbers

if (Math.abs(arc)>360)

{

arc = 360;

}

// Flash uses 8 segments per circle, to match that, we draw in a maximum

// of 45 degree segments. First we calculate how many segments are needed

// for our arc.

segs = Math.ceil(Math.abs(arc)/45);

// Now calculate the sweep of each segment.

segAngle = arc/segs;

// The math requires radians rather than degrees. To convert from degrees

// use the formula (degrees/180)*Math.PI to get radians.

theta = -(segAngle/180)*Math.PI;

// convert angle startAngle to radians

angle = -(startAngle/180)*Math.PI;

// draw the curve in segments no larger than 45 degrees.

if (segs>0)

{

// draw a line from the center to the start of the curve

ax = x+Math.cos(startAngle/180*Math.PI)*radius;

ay = y+Math.sin(-startAngle/180*Math.PI)*yRadius;

lineTo(ax, ay);

// Loop for drawing curve segments

for (var i = 0; iMath.cos(angle)*radius;

by = y+Math.sin(angle)*yRadius;

cx = x+Math.cos(angleMid)*(radius/Math.cos(theta/2));

cy = y+Math.sin(angleMid)*(yRadius/Math.cos(theta/2));

curveTo(cx, cy, bx, by);

}

// close the wedge by drawing a line to the center

lineTo(x, y);

}

}

}

//end of Class

在riacn看到一个转的国外人写的Graphic类,感觉不是很好。 首选它是从MovieClip类继承下来的,但它却

又用_root这个根时间轴来创建一个MovieClip的实例mc来mix-in到Graphic中。这样做是很不对的!并且一系列的

MovieClip的方法要通过mc来重写实现!我几个月前写的这个类虽然不是很充分,因为这是我组件库所有View的基类,

很多方法在考虑中,但绝对继承了MovieClip的所有方法和属性,而且跟MovieClip类一样是dynamic的.比起国外那

个,这个更有科学性.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有