Flash Production Example Tutorial: Two-point random polyline effect

Source: Internet
Author: User
Tags clear screen cos polyline pow sin
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.