Windows screensaver changes the line, I think we are not unfamiliar, I used to do a pure as a, let everyone appreciate
Train of thought: Look at the change line as a point in motion, there is a connection between these points. The movement of each point is similar, from a certain point at a certain speed in the X, y direction of the line motion, if this point outside the left and right, the x direction of the speed of the reverse, if this point beyond the upper and lower bounds, the y direction of the speed of the reverse. Because these points are not displayed, create an empty movie as a point and connect those points with a line function.
With the idea, we started writing programs.
Source:
var dot_num = 6;if (!started) {//Call copy function copy point Duplicate_dot (); started = true;} Onenterframe = function () {for (var n = 1; n<=dot_num; n++) {dot_move (this["dot" +n], this["dot" +n].xspeed, this["do T "+n].yspeed); } line_draw ();};/ /copy functions, and set the initial position and speed function of the point Duplicate_dot () {for (var n = 1; n<=dot_num; n++) {//create empty movie as point, instance named Dot1, Dot2, Dot3 ... cr Eateemptymovieclip ("Dot" +n, n); Let these points randomly distribute in the scene this["dot" +n]._x = random (400); this["dot" +n]._y = random (300); Set the speed at which these points move in the X and y directions this["dot" +n].xspeed = random (20) +10; this["dot" +n].yspeed = random (20) +10; The motion function of the}}//point, obj for the movie, xspeed,yspeed the Speed function dot_move (obj, xspeed, yspeed) of the x,y direction respectively, {with (eval (obj)) {//Let movie sport _x = XSpeed; _y + = Yspeed; When the left and right bounds are exceeded, xspeed takes the reverse if (_x>400) {_x = 400; XSpeed =-xspeed; } if (_x<0) {_x = 0; XSpeed =-xspeed; ///when the upper and lower bounds are exceeded, yspeed take the reverse if (_y>300) {_y = 300; Yspeed =-yspeed; } if (_y<0) {_y = 0; Yspeed =-yspeed; }}//line function, connect each point function Line_draw () {CREAteemptymovieclip ("line", 5000); With (lines) {//define the size of the line, color, transparency LineStyle (1, 0XFF00FF, 100); The beginning of the drawing line MoveTo (dot1._x, dot1._y); Connection point dot1 to Dot2...dot10 for (var n = 2; n<=dot_num; n++) {lineTo (this["dot" +n]._x, this["dot" +n]._y); }//connected to DOT1, forming a polygon lineTo (dot1._x, dot1._y); }} |
Enter the above program into the Flash MX frame, a simple change line effect is completed. Interested friends can add color, style and other changes. Come on, try it!
source File Download