/**
* Copyright teageek ( http://wonderfl.net/user/teageek )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/4SSi
*/
//ブラウン運動
//簡単なのからコツコツと勉強中
package {
import flash.display.*;
import flash.events.*;
import flash.media.*;
import flash.geom.*;
[SWF(backgroundColor = "0x000000", frameRate = "30")]
public class FlashTest extends Sprite {
private var canvas :BitmapData;
private var particles:Vector.<Particle> = new Vector.<Particle>();
private var color:ColorTransform = new ColorTransform(1, 1, 1, 1, -50, -35, -15);
public function FlashTest() {
for( var i :int =182; i<282; i+=2)
for( var j:int =182;j<282; j+=2 )
particles.push( new Particle(i,j) );
canvas = new BitmapData( 456,456, true, 0x0);
addChild( new Bitmap(canvas) );
addEventListener("enterFrame", onUpdate );
stage.addEventListener("click",init);
}
private function init(e:Event):void{
for each (var p:Particle in particles ) {
p.x=Math.random()*100-50+228;
p.y=Math.random()*100-50+228;
}
}
private function onUpdate( e:Event ):void {
for each ( var p:Particle in particles ) {
p.vx+=Math.random()*0.2-0.1;
p.vy+=Math.random()*0.2-0.1;
p.x+=p.vx;
p.y+=p.vy;
p.vx*=0.95;
p.vy*=0.95
}
canvas.lock();
canvas.colorTransform(canvas.rect,color);
for each ( p in particles )
canvas.setPixel32( p.x, p.y, p.color );
canvas.unlock();
}
}
}
class Particle {
public var x:Number = 0;
public var y:Number = 0;
public var vx:Number = 0;
public var vy:Number = 0;
public var ax:Number = 0;
public var ay:Number = 0;
public var color:uint=Math.random()*0xFFFFFFFF;
public function Particle( x:Number, y:Number ){
this.x = this.ax = x;
this.y = this.ay = y;
}
}