When Particle Collide (LHC Simulation)
forked from ClusterAmaryllis (diff: 46)
...adding 3D, maybe Stage3D ...using actual physics equations used by physicists
ActionScript3 source code
/**
* Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/vAM6
*/
package
{
import flash.display.*;
import flash.events.*;
import flash.utils.*;
public class ClusterAmaryllis extends Sprite
{
private var lines:Vector.<Sprite> = new Vector.<Sprite>();
private var prop:Vector.<Object> = new Vector.<Object>();
private var timer:Timer;
private var postCollisionParticlesNumber:uint = new uint( 30 );
public function ClusterAmaryllis()
{
init();
}
private function init():void
{
var initPos:Array = new Array(0, stage.stageHeight);
for(var i:uint = 0; i < postCollisionParticlesNumber; i++)
{
prop.push(new Object());
prop[i].xpos = stage.stageWidth / 2;
prop[i].ypos = stage.stageHeight / 2;
prop[i].zpos = 0;
prop[i].vx = 0;
prop[i].vy = 0;
prop[i].vz = 0;
prop[i].speed = 1 + Math.random() * 2;
prop[i].vec = Math.random() * 10 - 5;
prop[i].angle = Math.random() * 360;
lines.push(new Sprite());
//lines[i].graphics.lineStyle(Math.random() * 3, 0x6BC976 + Math.random() * 100 << 16);
lines[i].graphics.lineStyle( 1,0x131413+Math.random()*100<<16 );
lines[i].graphics.moveTo(prop[i].xpos, prop[i].ypos);
addChild(lines[i]);
}
timer = new Timer(33);
timer.addEventListener(TimerEvent.TIMER, onLoop, false, 0, true);
timer.start();
}
private function onLoop(e:TimerEvent):void
{
for(var i:uint = 0; i < postCollisionParticlesNumber; i++)
{
prop[i].vec += Math.random() * 4 - 2;
prop[i].angle += (Math.random() * 5) * Math.sin(prop[i].vec * (Math.PI / 180));
prop[i].vx = Math.cos(prop[i].angle * (Math.PI / 180) ) * prop[i].speed;
prop[i].vy = Math.sin(prop[i].angle * (Math.PI / 180) ) * prop[i].speed;
prop[i].vz = Math.atan2( prop[i].vx,prop[i].vy );
prop[i].xpos += prop[i].vx;
prop[i].ypos += prop[i].vy;
prop[i].zpos += prop[i].vz;
prop[i].zpos += prop[i].vz * Math.random();
lines[i].graphics.lineTo(prop[i].xpos, prop[i].ypos);
lines[i].alpha = Math.abs(Math.sin(prop[i].angle * (Math.PI / 180) ));
if(prop[i].xpos < 0 || prop[i].xpos > stage.stageWidth)
{
prop[i].vx = 0;
}
if(prop[i].ypos > stage.stageHeight || prop[i].ypos < 0)
{
prop[i].vy = 0;
}
/*if(prop[i].zpos > [some Zmax] || prop[i].zpos < [some Zmin] )
{
prop[i].vy = 0;
}*/
}
}
}
}