I was messing around with eliptical orbits awhile back, and came up with a halfway decent swarming prototype I thought some might find interesting.
[swf=http://jerryscript.hostrocket.com/flash/examples/particle/swarm.swf]width=450 height=250[/swf]
MovieClip.prototype.swarm=function(sides, start, change){
this.c=start;
this.bs=start-180;
this.bsc=change;
this.bsx=1;
this.ly=0;
this.fly=this.flyout=0;
this.sides=sides;
this.frozen=0;
this.onEnterFrame=function(){
if(this.frozen==0){
if(this.flyout<2){
this.flyout+=0.01;
}else{
if(Math.round(Math.random()*100)==1){
this.flyout=0;
}
}
this.fly = (this.flyout<1) ? 2-this.flyout : this.flyout;
this.clear();
if(this.c<=360){
if(this.bs<-180 || this.bs>180){ this.bsc*=(-1); }
if(this.bs>180){ this.bsx*=(-1); }
this.bs+=this.bsc;
if(this.bsx<0){
this.xx=this.bs;
this.yy=180;
}else{
this.xx=180;
this.yy=this.bs;
}
this.moveTo(this.x, this.y);
for(a=0; a<=10; a+=2){
this.lineStyle(a, 0xaaaaaa, a/10*100/4);
this.x=Math.sin(Math.PI/180*(this.c+a))*this.xx/this.fly;
this.y=Math.cos(Math.PI/180*(this.c+a))*this.yy/this.fly;
this.lineTo(this.x, this.y);
}
this.c += 360 / this.sides;
}else{
this.c=0;
}
updateAfterEvent();
if(Math.round(Math.random()*200)==1 && (this.x*this.x+this.y*this.y)<90*90){
this.frozen=Math.round(Math.random()*40);
}
}else{
this.frozen--;
}
};
};
createEmptyMovieClip('sphere', 1);
with(sphere){
_x=450;
_y=250;
createEmptyMovieClip('lightbulb', 2);
with(lightbulb){
lineStyle(1, 0x0000ff, 1);
colors =[ 0xffffff, 0xffffff, 0xffffff ];
alphas =[ 100, 20, 25 ];
ratios =[ 0, 254, 255 ];
matrix ={matrixType:'box', x:-78, y:-78, w:155, h:155, r:(45/180)*Math.PI };
beginGradientFill('radial', colors, alphas, ratios, matrix );
for(c=0;c<360;c+=6){
x=Math.sin(Math.PI/180*c)*85;
y=Math.cos(Math.PI/180*c)*85;
if(c==0){ moveTo(x, y); }
lineTo(x, y);
}
endFill();
}
for(m=1; m<13; m++){
sphere.createEmptyMovieClip('dot'+m, 10+m);
sphere['dot'+m].swarm(60,Math.round(Math.random()*360), m);
}
}
_root.sphere.onPress=function(){
this.startDrag();
};
_root.sphere.onRelease=_root.sphere.onReleaseOutside=function(){
stopDrag();
};
_root.sphere.onEnterFrame=function(){
_root.sphere.lightbulb._visible=_root.lighton;
this._alpha=Math.random()*15+85;
this._xscale=this._yscale=_root.slider._y-200;
};
_root.lineStyle(4, 0xffffff);
for(d=1; d<6; d++){
_root.moveTo(95, d*50+150);
_root.lineTo(105, d*50+150);
}
_root.moveTo(100, 200);
_root.lineTo(100, 400);
createEmptyMovieClip('slider', 100);
with(slider){
lineStyle(5, 0xffffff);
moveTo(-10, 0);
lineTo(10, 0);
_x=100;
_y=250;
}
_root.slider.onPress=function(){
this.startDrag(1, 100, 200, 100,4 00);
};
_root.slider.onRelease=_root.slider.onReleaseOutside=function(){
stopDrag();
};
_root.lighton=true;
createEmptyMovieClip('lightswitch', 200);
with(lightswitch){
_x=_y=50;
createTextField('lighttext', 201, 0, 0, 0, 0);
with(lighttext){
type='static';
background=border=autosize=true;
multiline=false;
borderColor='0xffffff';
backgroundColor='0xaaaaaa';
format=getTextFormat();
format.bold=true;
format.size=20;
setNewTextFormat(format);
text='Light On/Off';
}
}
_root.lightswitch.onPress=function(){
_root.lightswitch.lighttext.backgroundColor='0xffffff';
};
_root.lightswitch.onRelease=function(){
_root.lightswitch.lighttext.backgroundColor='0xaaaaaa';
_root.lighton=!_root.lighton;
};
_root.lightswitch.onReleaseOutside=function(){
_root.lightswitch.lighttext.backgroundColor='0xaaaaaa';
};
Note- the swf file was created with a black background, not sure why it doesn’t show up as black here with the forum’s swf tags?!?