I have a bunch of random tests I’ve done, and they’re just fun to make. This is one of 'em, and I’ll post code in the morning when I have it in front of me. Nothing fancy, but I think it’s fun.
http://ragonadesign.com/avoid_grid_AS3/avoidGrid_AS3.html
Make sure to run your mouse through the particles at the bottom of the graphic to play with it.
Everyone post your fun BMD experiments, there must be a ton out there.
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Stage;
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.filters.BlurFilter;
import flash.filters.ColorMatrixFilter;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.events.Event;
/**
* ...
* @author rragona
*/
public class Main extends Sprite
{
private var mStage:Sprite = new Sprite();
private var sObjects:Array = new Array();
private var minDist:Number = new Number(70);
private var f:Number = new Number(0.6);
private var k:Number = new Number(0.15);
private var bmd:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0xFFFFFF);
private var bf:BlurFilter = new BlurFilter(2, 2, 3);
private var cmf:ColorMatrixFilter = new ColorMatrixFilter([1.3, 0, 0, 0, 0,
0, 1.1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0 ,0 ,0.97 ,0])
private var bm:Bitmap = new Bitmap(bmd);
public function Main()
{
init();
}
private function init():void
{
initBM();
initStage();
initGrid();
}
private function initBM():void
{
addChild(bm);
addEventListener(Event.ENTER_FRAME, bmdLoop);
}
private function initStage():void
{
addChild(mStage);
mStage.x = stage.stageWidth / 2 - 25;
mStage.y = stage.stageHeight - 200;
}
private function bmdLoop(e:Event):void
{
bmd.draw(this);
bmd.applyFilter(bmd, bmd.rect, new Point(0, 0), bf);
bmd.applyFilter(bmd, bmd.rect, new Point(0, 0), cmf);
bmd.scroll(2, -25);
}
private function initGrid():void
{
for (var z:int = 0; z < 15; z ++)
{
for (var q:int = 0; q < 15; q ++)
{
var myCirc:MovieClip = new MovieClip();
myCirc.graphics.lineStyle(1, 0x222222);
myCirc.graphics.drawCircle(0, 0, 0.5);
myCirc.x = z * 5;
myCirc.y = q * 5;
myCirc.startX = myCirc.x;
myCirc.startY = myCirc.y;
myCirc.vx = 0;
myCirc.vy = 0;
myCirc.addEventListener(Event.ENTER_FRAME, avoidMouse);
mStage.addChild(myCirc);
sObjects.push(myCirc);
}
}
}
private function avoidMouse(e:Event):void
{
var curClip:Object = e.target;
var difX:Number = new Number();
var difY:Number = new Number();
var v2:Number = new Number();
difX = mStage.mouseX - e.target.x;
difY = mStage.mouseY - e.target.y;
v2 = Math.sqrt(difX * difX + difY * difY);
if (v2 < minDist)
{
curClip.vx -= (difX/v2)*minDist*k;
curClip.vy -= (difY/v2)*minDist*k;
}
curClip.vx += (e.target.startX - e.target.x) * k;
curClip.vy += (e.target.startY - e.target.y) * k;
e.target.x += curClip.vx;
e.target.y += curClip.vy;
curClip.vx *= f;
curClip.vy *= f;
}
}
}