14.12.07

Moon Orbit

This project is in continuation of a tutorial of Flash AS 2.0 using some AS 3.0 practices given to us by Anna.

Essentially the tutorial was to create a moon orbiting the Earth within Flash.

I thought it would be interesting to extend this to being able to play with the settings that determine the orbit trajectory while the file is playing. I allowed the user to change the numbers that govern the trajectory, speed with the inclusion of the Earths own orbit.

Please view here.

This was a fun excursion into some techniques I hadn't before tried. For example the inclusion of the components that Flash offers as default in order to control the settings of the orbits.

Code:

angle = 0;
centerX = stage.width/2;
centerY = stage.height/2;
centerpos = {_x:300, _y:250};
i = 1;
earthSpeed = earthSpeed_com.value;
moonSpeed = moonSpeed_com.value;
earthXRadius = earthXRadius_com.value;
earthYRadius = earthYRadius_com.value;
moonXRadius = moonXRadius_com.value;
moonYRadius = moonYRadius_com.value;
var earthSpeed_com:mx.controls.NumericStepper;
var moonSpeed_com:mx.controls.NumericStepper;
var moonXRadius_com:mx.controls.NumericStepper;
var moonYRadius_com:mx.controls.NumericStepper;
var earthXRadius_com:mx.controls.NumericStepper;
var earthYRadius_com:mx.controls.NumericStepper;
var nstepListener:Object = new Object();
nstepListener.change = function(evt_obj:Object) {
trace("Value changed to "+evt_obj.target.value);
earthXRadius = earthXRadius_com.value;
earthYRadius = earthYRadius_com.value;
moonXRadius = moonXRadius_com.value;
moonYRadius = moonYRadius_com.value;
earthSpeed = earthSpeed_com.value;
moonSpeed = moonSpeed_com.value;
};
earthSpeed_com.addEventListener("change",nstepListener);
moonSpeed_com.addEventListener("change",nstepListener);
moonXRadius_com.addEventListener("change",nstepListener);
moonYRadius_com.addEventListener("change",nstepListener);
earthXRadius_com.addEventListener("change",nstepListener);
earthYRadius_com.addEventListener("change",nstepListener);
var moon_mc:MovieClip = _root.attachMovie("moon_mc", "moon_mc", i, centerpos);
i++;
var earth_mc:MovieClip = _root.attachMovie("earth_mc", "earth_mc", i, centerpos);
earth_mc.onEnterFrame = function():Void {
this._x = 300+Math.cos(angle)*earthXRadius;
this._y = 200+Math.sin(angle)*earthYRadius;
angle += earthSpeed;
earthpos = {_x:this._x, _y:this._y};
i++;
var trail_mc:MovieClip = _root.attachMovie("earth_mc", "earth_mc", i, earthpos);
trail_mc.onEnterFrame = function() {
this._alpha -= 1;
this._xscale -= 2;
this._yscale -= 2;
if (this._xscale<=0) {
this.removeMovieClip();
}
};
};
moon_mc.onEnterFrame = function():Void {
this._x = earth_mc._x+Math.cos(angle)*moonXRadius;
this._y = earth_mc._y+Math.sin(angle)*moonYRadius;
angle += moonSpeed;
moonpos = {_x:this._x, _y:this._y};
i++;
var trail_mc:MovieClip = _root.attachMovie("moon_mc", "trail_mc", i, moonpos);
trail_mc.onEnterFrame = function() {
this._alpha -= 0.75;
this._xscale -= 2;
this._yscale -= 2;
if (this._xscale<=0) {
this.removeMovieClip();
}
};
};

4 comments:

Steve said...

A rather nice fun thing to play around with, is what you have created i loved just playing about with the numbers and made it do unusual orbits and different speeds. Looks like you know your flashy stuff jak, as im a moving image person, im into mostly animation, so its nice to see a difference of things and this was just fun to play around with.

Ben C said...

Quality! It would be good if you could control the ratios with sliding bars -then hook it up to a touch screen monitor; then I real would feel like I was creating the solar system!

mex said...

this is awsum real like it
proper fun to play with

Jako said...

That's a really good idea actually Ben. I'm sure given just a little research it wouldn't be too hard, but having never attempted that before I really don't know. Certainly sliding bars is possible. I'd love to return to this project and actually mess about with it to the extent that new shapes, colours and trail patterns can be created. Maybe experiment with the new line drawing tools that Flash now has? Would be good to see!