Remember when you first started learning as! I've consulted a lot of people about this as!. But the effect is always not ideal! The past few days looked at the mathematical data to find an unexpected harvest Ah! Share it with everyone! It seems that mathematics is still very important! Only blame of course is not cold, do not learn by heart! Oh ah.
Show Effect: ( Click the mouse after the animation do not let go after the test what will you see?) )
Click here to download the source file
First frame:X=0
I=0
Lovex and Lovey two arrays save the main coordinates of the word love, respectively!
Lovex=new Array (175,175,175,175,175,195,215,235,255,255,255,275,295,315,315,315,295,275,325,325,325,340,355,37
0,385,385,385,405,425,445,465,405,405,425,445,465,405,405,425,445,465)
Lovey=new Array (168,188,208,228,248,248,248,248,188,208,228,248,248,228,208,188,168,168,168,188,208,228,248,22
8,208,188,168,168,168,168,168,188,208,208,208,208,228,248,248,248,248)
its0.itlovex=lovex[0]//in bug 0. Save the x coordinates of the bug 0 by pressing the mouse.
its0.itlovey=lovey[0]//in bug 0. Save the y-coordinate of the bug 0 by pressing the mouseSecond Frame
X + +Third Frame
if (x<41) {
Its0.duplicatemovieclip ("its" + x, x)//Copy 40 bugs
this["its" +x].itlovex=lovex[x]//a variable in worm x save the x coordinates of the bug x by pressing the mouse
this["its" +x].itlovey=lovey[x]//a variable in worm x Save the y-coordinate of the bug x by pressing the mouse
gotoAndPlay (2)
}else{
Stop ()
}Bug Its0 This MC code:
Onclipevent (load) {//Set initial value at load
ang = Math.random ();//The initial radian value of the worm generated randomly
INCR = Math.random ()/100;//increment of radian value that randomly produces worms
AIMX = random (600) -300;//the elliptical motion length radius of two bugs randomly generated, the range is based on the size of your flash, and my 600*400 center point is (3
00,200)
X=random (600)-300;
Aimy = Random (400)-200
Y=random (400)-200;
XY = random (200) -100;//randomly produces center-biased value of worms
_xscale = _yscale=_yscale* (Math.random () +.1)//random size ratio of worms due to the appearance of the font after pressing the mouse, it is not used for a while
}
Onclipevent (MouseDown) {_root.i=1}
Onclipevent (mouseUp) {_root.i=2}
Onclipevent (enterframe) {
if (_root.i = 1) {//When the mouse is pressed when i==1, the worm moves to the point of love specified
_x = _x+ (itlovex-_x)/10;
_y = _y+ (itlovey-_y)/10;
}
if (_root.i = 2) {//When the mouse is pressed when i==2, the worm moves back to the position of the mouse
Ix=math.cos (ANG) *x+300+xy//calculates the position of the mouse before the bug is pressed
Iy=math.sin (ANG) *y+200+xy
_x = _x+ (ix-_x)/5;//move bugs to position before pressing the mouse
_y = _y+ (iy-_y)/5;
if (Math.Abs (ix-_x) <=1 and Math.Abs (iy-_y) <=1) {_root.i = 0;} When the worm approaches (ix,iy), it goes back to the position where the mouse was pressed, set i=0
}
if (_root.i = = 0) {//i==0 when there is no mouse action
x = x+ (aimx-x)/150;//calculates the length and radius of a worm based on two random lengths of radius difference
y = y+ (aimy-y)/150;
_x = Math.Cos (ANG) *x+300+xy;//calculation of the trajectory of an insect's elliptical motion
_y = Math.sin (ANG) *y+200+xy;
Ang = ang+incr;//radian increment
}
}