Back to "flash Basic Theory Class-Catalog"
Now you have come to the last chapter. I put all the little things I want to introduce into this chapter, they are not suitable for other places, or a little detached from the main line of the previous chapters.
In this chapter, I've also reorganized the formulas that are listed in each of the previous chapters so that they can be used as a reference point for these formulas.
Because these topics are relatively fragmented concepts, so I have no way to organize these many things. So each section is a separate unit. Well, don't say much, let's get started.
Brown (random) movement
Let's talk about history first. One day, a botanist named Robert Brown was observing the pollen particles in a drop of water, and then he found that the pollen was randomly moving. Although they are not currents or water movements, these tiny particles will never stop. He found that the same thing would happen in the dust, but they wouldn't swim like pollen. Although he did not know why there was such a phenomenon, it was not just that he and everyone else could not give explanations for decades, but he named it after his name-just to be aware of it!
Today, our explanation for Brownian motion is that a large number of water molecules are moving in a single drop, although the droplets seem to be stationary. These water molecules collide with pollen and dust, passing some of the momentum to them. Because even a tiny speck of dust is 1 million times times heavier than a water molecule, so a collision will not have much effect. But when there are millions of collisions per second, the momentum accumulates.
Now, some of the water molecules may have hit one side of the dust, while others have hit the other side. Eventually, they will reach the overall average. However, as time changes, the side that receives more impact will fluctuate, assuming left, then the particle will move a little to the right. The more impact the bottom gets, the more the particles move upwards. Finally, all the values tend to average, and the end result usually does not generate too much momentum in either direction. This is the random suspension action.
We can easily simulate this effect in Flash. In each frame, calculate a random number added to the X and y velocities of the moving object. Random values should be either positive or negative, and generally very small, such as ranges from 0.1 to +0.1. The form is as follows:
vx += Math.random() * 0.2 - 0.1;
vy += Math.random() * 0.2 - 0.1;
Multiplies a random decimal number by 0.2, and the resulting value is from 0.0 to 0.2. Minus 0.1 Then the value becomes-0.1 to 0.1. It is important to add some friction (friction) here, otherwise the speed will increase and an unnatural acceleration can occur. In Brownian1.as, I created 50 particles and let them suspend in the form of Brownian motion. Particles are examples of familiar Ball classes, making them black and shrinking. Here's the code:
Package {
Import Flash.display.Sprite;
Import flash.events.Event;
public class Brownian1 extends Sprite {
private var numdots:uint = 50;
private var friction:number = 0.95;
private Var Dots:array;
Public Function Brownian1 () {
Init ();
}
Private Function init (): void {
Dots = new Array ();
for (var i:uint = 0; i < numdots; i++) {
var dot:ball = new Ball (1, 0);
Dot.x = Math.random () * stage.stagewidth;
Dot.y = Math.random () * stage.stageheight;
DOT.VX = 0;
Dot.vy = 0;
AddChild (dot);
Dots.push (dot);
}
AddEventListener (Event.enter_frame, onenterframe);
}
Private Function Onenterframe (event:event): void {
for (var i:uint = 0; i < numdots; i++) {
var dot:ball = dots[i];
DOT.VX + + math.random () * 0.2-0.1;
Dot.vy + + math.random () * 0.2-0.1;
Dot.x + = DOT.VX;
Dot.y + = Dot.vy;
DOT.VX *= Friction;
Dot.vy *= Friction;
if (Dot.x > Stage.stagewidth) {
dot.x = 0;
else if (Dot.x < 0) {
Dot.x = Stage.stagewidth;
}
if (Dot.y > Stage.stageheight) {
Dot.y = 0;
else if (Dot.y < 0) {
Dot.y = Stage.stageheight;
}
}
}
}
}