forked from: りんぐ
// forked from mononoahare's りんぐ
// write as3 code here..
package
{
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.filters.GlowFilter;
import flash.filters.BlurFilter;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.utils.Timer;
[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")]
public class Main extends Sprite
{
private var max:uint=30;
private var particles:Array=[];
private var _container:Sprite;
private var _canvas:BitmapData;
private var _ctf:ColorTransform=new ColorTransform(0.985,0.985,0.985,1)
private var _pt:Point=new Point(0,0);
private var _blur:BlurFilter=new BlurFilter(2, 2, 1);
private var _glow:GlowFilter=new GlowFilter(0x0066ff,0.15,0.01,0.01)
private var _rotation:Number = Math.PI / 180;
private var _adjustmenttimer:int = 0;
private var _adjustmentvalue:int = 2;
public function Main():void
{
_container=new Sprite();
//addChild(_container)
_canvas=new BitmapData(465,465,true,0x000000);
addChild(new Bitmap(_canvas));
addEventListener(Event.ADDED_TO_STAGE,init);
}
private function init(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE,init);
createParticle();
}
private function createParticle():void
{
for each (var p:Particle in particles)
{
p.destroy();
}
var angs:Array = [2, 4, 6, 8, 10, 12];
var ang:int = angs[int(Math.random() * angs.length)];
var radius:int = int(Math.random() * 100 + 100);
for(var i:uint=0;i<max;i++){
particles[i]=new Particle(0xFFFFFF*Math.random(),_container,(i+1)*360/max,Math.PI * ang / max * i, radius);
}
var timer:Timer = new Timer(20);
timer.addEventListener(TimerEvent.TIMER,render);
timer.start();
}
private function render(e:TimerEvent):void
{
if (_adjustmenttimer++ == 200)
{
var timer:Timer = Timer(e.target);
timer.stop();
timer.removeEventListener(TimerEvent.TIMER,render);
timer = null;
_adjustmenttimer = 0;
createParticle();
}
for(var i:uint=0;i<max;i++){
particles[i].update();
}
_canvas.draw(_container)
_canvas.applyFilter(_canvas,_canvas.rect,_pt,_blur);
_canvas.colorTransform(_canvas.rect,_ctf);
filters=[_glow];
}
}
}
import flash.display.Sprite;
import flash.display.DisplayObjectContainer;
import flash.display.DisplayObject;
class Particle
{
private var _x:Number=0;
private var _y:Number=0;
private var _color:uint=0xFFFFFF;
private var _angle:Number;
private var _r:uint=160;
private var _main:DisplayObjectContainer;
private var _graphic:Sprite;
private var _defx:uint=232;
private var _defy:uint=232;
private var _rotation:Number=0;
private var _container:Sprite;
private var _speed:Number = 2;
public function Particle(color:uint,main:DisplayObjectContainer,rotation:Number,angle:Number,radius:int)
{
_r = radius;
_main=main;
_color=color;
_angle=angle;//Math.random()*2*Math.PI;
_graphic=new Sprite();
_graphic.graphics.beginFill(_color,1);
_graphic.graphics.drawCircle(0,0,5);
_graphic.graphics.endFill();
_container=new Sprite();
_container.addChild(_graphic);
_main.addChild(_container);
_container.rotation=rotation;
_container.x=_defx;
_container.y=_defy;
}
public function update():void
{
_x=Math.cos(-_angle)*_r;
_y=Math.sin(-_angle)*_r*1/12;
_angle=_angle+_speed*Math.PI/120;
_graphic.x=_x;
_graphic.y=_y;
_graphic.scaleX=_graphic.scaleY=0.5-Math.sin(_angle)/2+0.5;
_graphic.blendMode="add";
_graphic.alpha=1;
}
public function destroy():void
{
_main.removeChild(_container);
_container = null;
_graphic = null;
}
}