Tutorials | random
The effect is as follows: (with the mouse any click Flash animation)
Click here to download the source file
Image in the past or rookie when watching a lightning effect mode, because did not read the source file, has not been to ponder the algorithm, today's math class to review the triangle function when suddenly thought of this idea, so the pen in the notebook wrote a following as.
Go home to open flash, test pass.
There are illustrations in the source file.:
* Polyline Effect
*
* Code by Wood (13tds.com)
*
* Flash 8.0 ActionScript 2.0
*
***/
Stage.scalemode = "Noscale";
Stage.showmenu = false;
Import Flash.geom.Point; Register point type, if you do not use this class can be used in other ways to replace the location of points
var flash:function = Function (A:point, B:point, Q:number, P:number) {
_root.clear (); Clear Screen
_root.moveto (a.x, A.Y); Move to Point A
_root.linestyle (1); Initialize the route of the formula
Len = math.sqrt (Math.pow (b.x-a.x, 2) +math.pow (B.Y-A.Y, 2)); Length of
Qlen = len/q; Average length of each segment
Angle = Math.atan2 (B.Y-A.Y, b.x-a.x); Radian
deg = Angle*180/math.pi; Angle
For (I=1 i<q; i++) {
temp = {X:a.x+qlen*math.cos (angle) *i, y:a.y+qlen*math.sin (angle) *i}; Find the point I position
Tempangle = (deg-90) *math.pi/180; The angle of the vertical route
Templen = P-random (p*2); Amplitude (length) p ~ P
LineTo (Temp.x+math.cos (tempangle) *templen, Temp.y+math.sin (tempangle) *templen); Move to Temp dot
}
_root.lineto (b.x, B.Y); to point B
};
var a:point = new Point (0, 0); Initial a dot
var b:point = new Point (400, 300); Initial B-Dot
var c:number = 2; Initial segment Numbers
SetInterval (flash,50,a,b,10,25)