自己計測するパーティクル
/**
* Copyright knd ( http://wonderfl.net/user/knd )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/avic
*/
package {
import flash.display.Sprite;
import flash.events.Event;
[SWF(backgroundColor="0x0")]
public class FlashTest extends Sprite {
private var _particles:Array;
public function FlashTest() {
// write as3 code here..
_particles = [];
for (var i:int = 0; i < 100; i++)
{
var p:Particle = new Particle();
_particles.push(p);
addChild(p);
}
addEventListener(Event.ENTER_FRAME, loop);
}
private function loop(e:Event):void
{
for (var i:int = 0; i < 100; i++)
{
var p:Particle = _particles[i];
p.update();
if (p.x > 465 || p.x < -60)
{
p.init();
this.setChildIndex(p, 0);
}
if (p.y > 465 || p.y < -80)
{
p.init();
this.setChildIndex(p, 0);
}
}
}
}
}
import net.hires.debug.Stats;
class Particle extends Stats
{
private var _x0:Number;
private var _y0:Number;
private var _theta0:Number;
private var _theta:Number;
public function Particle()
{
super();
_x0 =200;
_y0 =180;
_theta0 = 2 * Math.PI * Math.random();
_theta = 2.5 * Math.random();
}
public function update():void
{
_theta += 0.01;
var r:Number = _theta * 10;
r *= r;
x = _x0 + r * Math.cos(_theta + _theta0);
y = _y0 + r * Math.sin(_theta + _theta0);
}
public function init():void
{
x = _x0;
y = _y0;
_theta = 0;
_theta0 = 2 * Math.PI * Math.random();
}
}