com.flashvan.Graphic类

类别:软件工程 点击:0 评论:0 推荐:

// *********************************************************************************************** // ______ // .-" "-. // / AOL \ // | | // |, .-. .-. ,| // | )(__/ \__)( | // |/ /\ \| // (@_ (_ ^^ _) // _ ) \_______\__|IIIIII|__/__________________________ // (_)@8@8{}<________|-\IIIIII/-|___________________________> // )_/ \ / // (@ `--------` AOL FLASH STUDIO // // *********************************************************************************************** // // @FileName Graphic.as // @Description 图形类 // @Package com.flashvan // @Author AOL // @Email [email protected] // @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 ([email protected]) - 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 ([email protected]) - 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

本文地址:http://com.8s8s.com/it/it36041.htm