Flash Labs NO.2 : Newton’s Law of Gravitation


It’s high time to support my physics by computers. Today I experimented with Newton’s Law of Gravitation for 3D and as far as it goes to one object it works great. However I didn’t managed to apply the force to the second object (The Sun).The movie which you can see above is a gif, cause of WordPress politics… The original animation looks much better.

Here’s my source code:

The rule that makes the day and night
 F = GMm/r^2

Two movieclips one called "planet" and the second called "sun" both should be exported for AS2
To get the best results get "planet" and the "sun" to the center of the movieclip
To make the planet move in third dimension I used the scale trick and I combine it with the Newton's formula.
Well we all know that Newton laws are symmetrical, so that the sun should also move a little, but I had no luck adjusting the params so I excluded it.

coder: Ranza
web: https://masteranza.wordpress.com
time: 00:26:31

var sun:MovieClip = _root.attachMovie("sun","sun",1);
sun._x =  Stage.width /2;
sun._y = Stage.height /2;
sun.mass = 20;

var planet:MovieClip = _root.attachMovie("planet","planet",2);
planet.Yspeed = -0.5;
planet.Xspeed = -0.1;
planet.Zspeed = -0.2;
planet.mass = 5;
planet._x = Stage.width /5;
planet._y = Stage.height /2;
planet.onEnterFrame = _root.PlanetPhysics;

function PlanetPhysics(){
 //Never mind about the G 😉 the speed is just for fun 😉
 sqrdistance = Math.pow(this._x-sun._x,2) + Math.pow(this._y - sun._y ,2) + Math.pow((100 - this._xscale),2);
 this.Xacc = ((sun._x - this._x)/Math.sqrt(sqrdistance)) * this.mass * sun.mass / sqrdistance;
 this.Yacc = ((sun._y - this._y )/Math.sqrt(sqrdistance)) * this.mass * sun.mass / sqrdistance;
 this.Zacc = ((100 - this._xscale)/Math.sqrt(sqrdistance)) * this.mass * sun.mass / sqrdistance;
 this.Xspeed += this.Xacc;
 this.Yspeed += this.Yacc;
 this.Zspeed += this.Zacc;
 this._x += this.Xspeed;
 this._y += this.Yspeed;
 this._alpha = this._xscale = this._yscale += this.Zspeed ;

 //The objects which are closer have to be on top
 if (this._xscale > 100){

By the way, I’ve invented a logo, shortly I will explain it’s symbolic meanings.


No Responses Yet to “Flash Labs NO.2 : Newton’s Law of Gravitation”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: