forked from: GREEN粒子
// forked from nabe's GREEN粒子
package {
import flash.display.*;
import flash.events.*;
[SWF(width="465", height="465", backgroundColor="0", frameRate="24")]
public class Program_ extends Sprite {
private const W_:uint = stage.stageWidth;
private const H_:uint = stage.stageHeight;
public function Program_ () {
addEventListener(Event.ADDED_TO_STAGE, init_);
}
private function init_ (evnet_:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, init_);
x = W_>>1;
y = H_>>1;
for (var i:int = 0; i < 20; i++) {
addChild(new GN_);
}
}
}
}
import flash.display.*;
import flash.events.*;
import flash.geom.*;
class GN_ extends Sprite {
private var vx_:Number;
private var vy_:Number;
private var k_:Number;
public function GN_ () {
draw_();
reset_();
addEventListener(Event.ENTER_FRAME, update_);
}
private function update_ (evnet_:Event):void {
x += vx_;
y += vy_;
if (Math.random() < 0.75) {
vx_ += 0.5 * (Math.random() - 0.5);
vy_ += 0.5 * (Math.random() - 0.5);
}
alpha *= k_;
if (alpha < 0.001) reset_();
}
private function reset_ ():void {
x = 100 * (Math.random() - 0.5);
y = 100 * (Math.random() - 0.5);
alpha = (Math.random() + 3) * 0.25;
vx_ = 3 * (Math.random() - 0.5);
vy_ = 3 * (Math.random() - 0.5);
k_ = (Math.random() + 19) * 0.05;
}
private function draw_ ():void {
var rect_:Rectangle = new Rectangle(-100, -100, 200, 200);
var matrix_:Matrix = new Matrix();
matrix_.createGradientBox(200, 200, 0, -100, -100);
var g_:Graphics = graphics;
g_.beginGradientFill(
GradientType.RADIAL,
[0xAAFFEE, 0x33CC99, 0x00CC99],
[0.75, 0.25, 0],
[0, 0xF, 0xCF],
matrix_, SpreadMethod.PAD, InterpolationMethod.RGB, 0
);
g_.drawEllipse(rect_.x, rect_.y, rect_.width, rect_.height);
g_.endFill();
}
}