com.flashvan.graphic class

xiaoxiao2021-03-06  60

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

// ______

// .- "" -.

// / aol /

// | |

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

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

// | / // / |

// (@_ (_ ^^ _)

// _) / _______ / __ | iiiiii | __ / _________________________

// (_) @ 8 @ 8 {} <________ | - / iiiiii / - | __________________________>

//) _ / / /

// (@ `--------` Aol Flash Studio

//

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

//

@Filename graphic.as

@Description graphics

@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 The 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 Calculation

Theta = math.pi / 4;

// Calculate the discance 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 ou 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 Mueeller and Michael Hurwicz for their controls.

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

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 ou 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 (degreees / 180) * Math.pi to get radians.

Theta = - (segangle / 180) * Math.pi;

// Convert Angle Startangle To Radians

Angle = - (Startangle / 180) * Math.pi;

// Findur Starting Points (AX, AY) Relative to the Secify X, Y

AX = X-Math.cos (Angle) * RADIUS;

AY = Y-math.sin (angle) * yradius;

// ix 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 ou 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 Thei 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 the the has of 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

// Side = 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, Side:

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 Side

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, Side:

Number, Radius:

Number, Angle:

Number

{

IF (arguments.

Length <4)

{

Return;

}

// Convert Sides to Positive Value

VAR Count:

Number =

Math.

ABS (SIDES);

// Check what 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.drawhedge () - 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 Mueeller and Michael Hurwicz for their controls.

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

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 segan:

Number, Theta:

Number, Angle:

Number, Anglemid:

Number, segs:

Number;

VAR AX:

Number, AY:

Number, bx:

Number, by:

Number, CX:

Number, CY:

Number;

// limited 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 ou 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 (degreees / 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 deter

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; i

Math.

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

I saw a Graphic class written by RiaCn, I didn't feel good. Preferences are inherited from the MovieClip class, but it uses the _root this root timeline to create an instance MC of MOVIECLIP to Mix-in to Graphic. This is not right! And a series of MOVIECLIP methods should be rewritten through the MC! Although this class written in a few months is not very sufficient, because this is the base class of all views of my component library, many methods are considering, but absolutely inherit all methods and properties of MovieClip, and is Dynamic as the MovieClip class. This is more scientific than the abroad.

转载请注明原文地址:https://www.9cbs.com/read-118978.html

New Post(0)