Dust Cleaning
Move mouse to swipe the dust. :)
/**
* Copyright Caiim. ( http://wonderfl.net/user/Caiim. )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/v8Yk
*/
package {
import flash.net.URLRequest;
import flash.display.Loader;
import flash.text.TextField;
import flash.events.MouseEvent;
import flash.display.Bitmap;
import flash.events.Event;
import flash.display.BitmapData;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private var bd:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0);
private var px:Vector.<int> = new Vector.<int>();
private var py:Vector.<int> = new Vector.<int>();
private var powerX:Vector.<Number> = new Vector.<Number>();
private var powerY:Vector.<Number> = new Vector.<Number>();
private var direction:Vector.<int> = new Vector.<int>();
private const COUNT:int = 12000;
private const AOE:int = 40;
private var url:String = "http://www.allkpop.com/wp-content/uploads/2012/08/20120820_PSy_Gangnamstyle.jpg";
public function FlashTest() {
//image loader
var loader:Loader = new Loader();
loader.load(new URLRequest(url));
addChild(loader);
for(var i:int = 0;i<COUNT;i++)
{
px.push(Math.random()*stage.stageWidth);
py.push(Math.random()*stage.stageHeight);
direction.push(0);
powerX.push(0);
powerY.push(0);
}
addChild(new Bitmap(bd));
addEventListener(Event.ENTER_FRAME, update);
stage.addEventListener(MouseEvent.MOUSE_MOVE, push);
}
private function push(e:MouseEvent):void
{
for(var i:int = 0 ; i < COUNT ; i++)
{
var dist:Number = Math.sqrt(Math.pow(mouseY - py[i], 2) + Math.pow(mouseX - px[i], 2));
if(dist <= AOE)
{
direction[i] = Math.atan2(py[i] - mouseY, px[i] - mouseX);
powerX[i] = powerY[i] = (AOE - dist) / AOE * 10;
}
}
}
private function update(e:Event):void
{
bd.fillRect(bd.rect, 0x00000000);
for(var i:int = 0; i < COUNT ; i++)
{
px[i] += Math.cos(direction[i]) * powerX[i];
py[i] += Math.sin(direction[i]) * powerY[i];
if(px[i] <= 0 || px[i] >= stage.stageWidth)
{
powerX[i] *= -1;
powerX[i] *= 1.2;
}
if(py[i] <= 0 || py[i] >= stage.stageHeight)
{
powerY[i] *= -1;
powerY[i] *= 1.2;
}
var limit:Number = 1;
powerX[i] *= 0.9;
if(powerX[i] < limit && powerX[i] > -limit)
powerX[i] = 0;
powerY[i] *= 0.9;
if(powerY[i] < limit && powerY[i] > -limit)
powerY[i] = 0;
for(var offX:int = -1 ; offX <= 0; offX++)
for(var offY:int = -1 ; offY <= 0; offY++)
bd.setPixel32(px[i] + offX, py[i] + offY, 0xffff5500);
}
}
}
}