flash on 2012-9-30
package {
import flash.geom.ColorTransform;
import flash.display.AVM1Movie;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class FlashTest extends Sprite {
private var world:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0);
private var bitmap:Bitmap = new Bitmap(world);
private var timer:Timer = new Timer(20);
private var px:Vector.<Number> = new Vector.<Number>();
private var py:Vector.<Number> = new Vector.<Number>();
private var mx:Number = 0;
private var my:Number = 0;
private var l:Number = 0;
private var i:int = 0;
private var j:int = 0;
public function FlashTest():void
{
for(i = 0; i < 2000; i += 1)
{
px.push(Math.random() * stage.stageWidth);
py.push(Math.random() * stage.stageHeight);
}
addChild(bitmap);
timer.addEventListener(TimerEvent.TIMER, te);
stage.addEventListener(MouseEvent.MOUSE_MOVE, me);
timer.start();
}
private function me(e:MouseEvent):void
{
mx = e.stageX;
my = e.stageY;
}
private function te(e:TimerEvent):void
{
world.colorTransform(world.rect, new ColorTransform(1, 1, 1, 1, 0, 0, 0, -1));
for(i = 0; i < 2000; i += 1)
{
l = Math.sqrt(Math.pow(mx - px[i], 2) + Math.pow(my - py[i], 2)) * .05;
if(px[i] > mx)
px[i] += -1/l * mx;
else if(px[i] < mx)
px[i] += 1/l * mx;
if(py[i] > my)
py[i] += -1/l * my;
else if(py[i] < my)
py[i] += 1/l * my;
world.setPixel(px[i], py[i], 0xff0000);
}
}
}
}