The 12th chapter of Flash Basic theory course particle gravity and gravitation Ⅱ

Source: Internet
Author: User
Tags addchild

Back to "flash Basic Theory Class-Catalog"

Orbital movement

Finally, let's look at a realistic example where we can create a simple planetary system with the sun and the Earth. Create a mass of 10,000 of the sun and a mass of 1 planets. Next, let the planet move away from the sun for a distance and give it a velocity perpendicular to the sun. As shown in Figure 12-3.

Figure 12-3 Setting the stage

If the given mass, the distance and the speed are very suitable, then can let the planet into orbit. See document Class Orbit.as. You need to explain the code in Init, and a little change is to set the Numparticles variable to 2.

private function init():void {
 particles = new Array();
 var sun:Ball = new Ball(100, 0xffff00);
 sun.x = stage.stageWidth / 2;
 sun.y = stage.stageHeight / 2;
 sun.mass = 10000;
 addChild(sun);
 particles.push(sun);
 var planet:Ball = new Ball(10, 0x00ff00);
 planet.x = stage.stageWidth / 2 + 200;
 planet.y = stage.stageHeight / 2;
 planet.vy = 7;
 planet.mass = 1;
 addChild(planet);
 particles.push(planet);
 addEventListener(Event.ENTER_FRAME, onEnterFrame);
}

To give you an example, see orbitdraw.as, draw a track line, you can get some interesting patterns.

Elastic motion

You might want to use elastic motion as another particle of gravity. Yes, the elastic movement is my favorite! Recall the example of spring chain and elastic motion between objects in the eighth chapter. Later we will see a wider range of applications, where the particles are moving in an elastic motion, like those in the gravitational process.

The inspiration comes from the node Garden [node Garden] authored by Jared Tarbell in Www.levitated.net, as shown in Figure 12-4. The overall idea is to use a region to contain certain nodes (particles), and each node will interact with the adjacent nodes to produce a reaction. This is my idea of using elastic motion as a reaction force.

Figure 12-4 Node Garden of Jared Tarbell

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.