Fire crowd
ATTRACTORS VERSION
// forked from nutsu's forked from: forked from: BrownianMotion
// forked from ton's forked from: BrownianMotion
// forked from ton's BrownianMotion
// ATTRACTORS VERSION
package {
import flash.display.*;
import flash.filters.*;
import flash.events.*;
import flash.geom.*;
import frocessing.core.F5BitmapData2D;
import net.hires.debug.Stats;
[SWF(frameRate="60", backgroundColor="#000000")]
public class BrownianMotion extends Sprite {
private const N:int = 500;
private const MAX_R:int = 200;
private const W:int = 465;
private const H:int = 465;
private var fg:F5BitmapData2D;
private var bmp:Bitmap;
private var colors:Array = [
0x3a242b, 0x3b2426, 0x352325, 0x836454,
0x7d5533, 0x8b7352, 0xb1a181, 0xa4632e, 0xbb6b33, 0xb47249,
0xca7239, 0xd29057, 0xe0b87e, 0xd9b166, 0xf5eabe, 0xfcfadf,
0xd9d1b0, 0xfcfadf, 0xd1d1ca, 0xa7b1ac, 0x879a8c, 0x9186ad,
0x776a8e, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0xFFFFFF, 0xFFFFFF,
0xFFFFFF, 0xFFFFFF, 0xFFFFFF
];
function BrownianMotion() {
fg = new F5BitmapData2D(W, H, false, 0x000000);
bmp = new Bitmap(fg.bitmapData);
addChild(bmp);
fg.strokeAlpha = 1;
for (var i:int = 0; i < N; i++) {
var d:Dot = new Dot(colors[Math.floor(Math.random()*colors.length)]);
var r:Number = Math.sqrt(Math.random()) * MAX_R;
var angle:Number = Math.random() * (2 * Math.PI);
d.x = Math.cos(angle) * r;
d.y = Math.sin(angle) * r;
d.vx = 0;
d.vy = 0;
}
//addChild( new Stats() );
addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
}
private function onEnterFrameHandler(event:Event):void
{
fg.beginDraw();
fg.translate( W>>1, H>>1 );
for each(var d:Dot in Dot.dots) {
d.update();
fg.strokeColor = d.color;
fg.pixel( d.x, d.y );
}
fg.endDraw();
var bmd:BitmapData = fg.bitmapData;
bmd.applyFilter(bmd, bmd.rect, new Point(0,-1), new BlurFilter());
bmd.applyFilter(bmd, bmd.rect, new Point(), new ColorMatrixFilter([
1.015, 0, 0, 0, -0.25,
0, 1.014, 0, 0, -0.25,
0, 0, 1.013, 0, -0.5,
0, 0, 0, 0.5, 0
]));
}
}
}
class Dot{
public var vx:Number;
public var vy:Number;
public var x:Number;
public var y:Number;
public var color:uint;
private const X:Number = 20;
private const F:Number = 0.7;
public static var dots:Array = [];
private var targetID:int;
function Dot(color:uint) {
this.color = color;
targetID = Math.floor(Math.random()*dots.length);
dots.push(this);
}
public function update():void {
if(Math.random()>0.95) targetID = Math.floor(Math.random()*dots.length);
vx -= (x - dots[targetID].x)/800;
vy -= (y - dots[targetID].y)/800;
if (Math.random()>0.95) {
vx += (Math.random() - Math.random())*X;
vy += (Math.random() - Math.random())*X;
}
vx *= F;
vy *= F;
x += vx;
y += vy;
}
}