forked from: forked from: forked from: Particle
Just added some random to the speed and some chaos to the animation.
/**
* Copyright hebee ( http://wonderfl.net/user/hebee )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/1IB5
*/
// forked from jeffbuzzerio's forked from: forked from: Particle
// forked from hebee's forked from: Particle
// Just added some random to the speed and some chaos to the animation.
package
{
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.MouseEvent;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.ColorTransform;
import flash.display.Shape;
import flash.geom.Point;
import flash.filters.BlurFilter;
import flash.display.Sprite;
public class dev extends Sprite
{
private const NUM_LIGHTS:int = 350;
private const MAX_SPEED:Number = 5;
private const MIN_SPEED:Number = 0.01;
private var WELL_X:Number = 0;
private var WELL_Y:Number = 0;
private var _canvas:BitmapData;
private var _lights:Array;
private var _alphaTransform:ColorTransform;
private var _blurFilter:BlurFilter;
private var _zeroPoint:Point;
public function dev()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
WELL_X = stage.stageWidth / 2;
WELL_Y = stage.stageHeight / 2;
_blurFilter = new BlurFilter(3,3,1);
_zeroPoint = new Point ;
_canvas = new BitmapData(stage.stageWidth,stage.stageHeight,false,0);
addChild(new Bitmap(_canvas));
_lights = new Array();
for (var n : int = 0; n < NUM_LIGHTS; ++n)
{
var light:Object = {};
light.x = WELL_X;
light.y = WELL_Y;
light.dx = 0;
light.dy = 0;
light.color = Math.random() * 0xFFFFFF;
light.speed = ((Math.random()*(100*(MAX_SPEED - MIN_SPEED))) + (100*MIN_SPEED))/100;
_lights[n] = light;
}
addEventListener( Event.ENTER_FRAME, onEnterFrame );
}
private function onEnterFrame( e : Event ):void
{
_canvas.lock();
var fade:Number = 8;
while (fade --)
{
_canvas.applyFilter(_canvas,_canvas.rect,_zeroPoint,_blurFilter);
}
var pixel:Object;
var pixelb:Object;
var angle:Number;
var distance_well:Number;
for (var n : int = 0; n < NUM_LIGHTS; ++n)
{
pixel = _lights[n];
distance_well = getAbs(Math.sqrt((pixel.x - WELL_X) * (pixel.x - WELL_X) + (pixel.y - WELL_Y) * (pixel.y - WELL_Y)));
pixel.lastX = pixel.x;
pixel.lastY = pixel.y;
if (distance_well < stage.stageHeight)
{
var p:Point = Point.polar(WELL_X + Math.random() * 100 - 50,n);
angle = Math.atan2((p.y + WELL_Y) - pixel.y,(p.x + WELL_X) - pixel.x);
pixel.dx -= pixel.speed * Math.cos(angle);
pixel.dy -= pixel.speed * Math.sin(angle);
pixel.dy *= (Math.random()*80)/100 + .2;
pixel.dx *= (Math.random()*80)/100 + .2;
pixel.x += pixel.dx;
pixel.y += pixel.dy;
}
else
{
pixel.lastX = pixel.x = WELL_X;
pixel.lastY = pixel.y = WELL_Y;
}
drawLine(pixel.lastX, pixel.lastY, pixel.x, pixel.y, pixel.color);
if(n-1 < 0){
pixelb = _lights[NUM_LIGHTS-1];
} else {
pixelb = _lights[n-1];
}
drawLine(pixelb.x, pixelb.y, pixel.x, pixel.y, 0xFEFEFE);
}
_canvas.applyFilter(_canvas,_canvas.rect,_zeroPoint,_blurFilter);
_canvas.unlock();
}
private function drawLine( startX : Number, startY : Number, endX : Number, endY : Number, color : Number ):void
{
var dx:Number = endX - startX;
var dy:Number = endY - startY;
var a:Number;
var b:Number;
var tmp:Number;
var len:Number;
var i:int;
if (getAbs(dx) > getAbs(dy))
{
a = dy / dx;
b = startY;
if (startX > endX)
{
tmp = startX;
startX = endX;
endX = tmp;
b = endY;
}
len = endX - startX;
for (i = 0; i < len; ++i)
{
_canvas.setPixel( i + startX, i * a + b, color );
}
}
else
{
a = dx / dy;
b = startX;
if (startY > endY)
{
tmp = startY;
startY = endY;
endY = tmp;
b = endX;
}
len = endY - startY;
for (i = 0; i < len; ++i)
{
_canvas.setPixel( i * a + b, i + startY, color );
}
}
}
private function getAbs( x : Number ):Number
{
return x < 0 ? -x : x;
}
}
}