// forked from Susisu's forked from: entropy
// forked from Susisu's entropy
package {
import flash.display.StageQuality;
import flash.geom.Rectangle;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.Event;
import flash.display.Sprite;
import flash.geom.Point;
import net.hires.debug.Stats;
[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="60")]
public class FlashTest extends Sprite {
public var particles:Vector.<Particle>=new Vector.<Particle>();
public var canvas:BitmapData=new BitmapData(465,465,false);
public var bmp:Bitmap=new Bitmap(canvas);
public var cp:Point=new Point(465/2,465/2);
public var gpoints:Vector.<Point>=new Vector.<Point>();
private var rect:Rectangle = new Rectangle(0,0,465,465);
public function FlashTest() {
stage.quality = StageQuality.LOW;
var p:Particle;
for(var i:int=0;i<100;i++){
for(var j:int=0;j<100;j++){
var r:Number=Math.random()*2*Math.PI;
particles.push(p = new Particle(i+cp.x-50,j+cp.y-50,Math.cos(r),Math.sin(r)));
if(i+j > 0) particles[particles.length - 2].next = p;
}
}
for(i=0;i<360;i+=120){
gpoints.push(new Point(Math.cos(i/180*Math.PI)*120+cp.x,Math.sin(i/180*Math.PI)*120+cp.y));
}
gpoints.push(cp);
addChild(bmp);
addEventListener(Event.ENTER_FRAME,onEnterFrame);
addChild(new Stats());
}
public function onEnterFrame(e:Event):void{
canvas.lock();
canvas.fillRect(rect,0);
var dx:Number,dy:Number;
var d2:Number;
var j:int;
var p:Particle = particles[0];
while(p = p.next){
p.x+=p.vx;
p.y+=p.vy;
for(j=0;j<4;j++){
dx=gpoints[j].x-p.x;
dy=gpoints[j].y-p.y;
d2=dx*dx+dy*dy
p.vx+=dx/d2;
p.vy+=dy/d2;
}
canvas.setPixel(p.x>>0,p.y>>0,0xffffff);
}
canvas.unlock();
}
}
}
import flash.geom.Point;
class Particle{
public var x:Number=0;
public var y:Number=0;
//public var v:Point=new Point(0,0);
public var vx:Number=0;
public var vy:Number=0;
public var next:Particle = null;
public function Particle(x:Number,y:Number,vx:Number,vy:Number){
this.x=x;
this.y=y;
this.vx=vx;
this.vy=vy;
}
}