forked from: temp
/**
* Copyright FTMSuperfly ( http://wonderfl.net/user/FTMSuperfly )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/nlpr
*/
// forked from jokehn9's temp
package {
import flash.display.BitmapData;
import flash.events.Event;
import flash.display.Shape;
import flash.display.Sprite;
import flash.ui.Mouse;
public class FlashTest extends Sprite {
private var shape:Shape;
private var arr:Array = [];
private const num:int = 100;
private var canvas:BitmapData = new BitmapData(465,465,true);
public function FlashTest() {
// write as3 code here..
Mouse.hide();
shape = new Shape();
addChild(shape);
var p:Particle = new Particle();
for(var i:int = 0;i<num; i++) {
arr[i] = new Particle;
arr[i].x = arr[i].prevx = Math.random() * 465;
arr[i].y = arr[i].prevy = Math.random() * 465;
}
addEventListener("enterFrame",ff);
stage.addEventListener("mouseDown",boom);
}
private function ff(e:Event):void {
//움직인다.
var p:Particle;
var dx:Number,dy:Number;
var d:Number = 0;
for(var i:int = 0; i<num;i++) {
p = arr[i];
dx = mouseX - p.x;
dy = mouseY - p.y;
d = Math.sqrt(dx*dx + dy*dy);
p.speedX += dx * 7 / d;
p.speedY += dy * 7/ d;
p.speedD = Math.sqrt(p.speedX*p.speedX + p.speedY * p.speedY);
p.speedX *= 0.98;
p.speedY *= 0.98;
p.ds = d;
p.x += p.speedX;
p.y += p.speedY;
}
//그린다
shape.graphics.clear();
shape.graphics.lineStyle(1,0x0);
for(i = 0; i< num;i++) {
shape.graphics.lineStyle(Math.abs(arr[i].speedD/32),(arr[i].color<<16)*0.8,1);
shape.graphics.moveTo(arr[i].prevx,arr[i].prevy);
shape.graphics.lineTo(arr[i].x,arr[i].y);
arr[i].prevx = arr[i].x
arr[i].prevy = arr[i].y
}
}
private function boom(e:Event):void {
var dx:Number, dy:Number = 0;
var mi:int = 0;
for(var i:int = 0; i<num;i++) {
if(Math.random() > 0.5) {
mi = 1;
}
else {
mi = -1;
}
arr[i].speedX = -100 * Math.random() + 50;
arr[i].speedY = arr[i].speedX * mi;
}
}
}
}
class Particle {
public var x:Number = 0;
public var y:Number = 0;
public var speedX:Number = 0;
public var speedY:Number = 0;
public var prevx:Number = 0;
public var prevy:Number = 0;
public var ds:Number = 0;
public var color:uint = 0xff * Math.random();
public var speedD:Number = 0;
}