forked from: Interactive blobs
// forked from mrdoob's Interactive blobs
package
{
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.filters.BlurFilter;
import flash.events.Event;
import flash.geom.Rectangle;
import flash.geom.Point;
import funnel.*;
[SWF( backgroundColor='0xFFFFFF', frameRate='50', width='800', height='600')]
public class blobsInteractive extends Sprite
{
private var bl :Array;
private var r :Bitmap;
private var c :Sprite;
private var b :Sprite;
private var s :Number = 0;
private var p :Number = .9;
private var gio:Gainer;
private var isPressed:Boolean = false;
private var Xnum:Number;
private var Ynum:Number;
public function blobsInteractive()
{
stage.align = "TL";
stage.scaleMode = "noScale";
bl = new Array();
b = new Sprite();
b.graphics.beginFill(0xFFFFFF,1);
b.graphics.lineTo(stage.stageWidth,0);
b.graphics.lineTo(stage.stageWidth,stage.stageHeight);
b.graphics.lineTo(0,stage.stageHeight);
b.graphics.lineTo(0,0);
b.graphics.endFill();
addChild(b);
c = new Sprite();
c.filters = [new BlurFilter(20,20,2)];
addChild(c);
r = new Bitmap( new BitmapData( stage.stageWidth, stage.stageHeight, false, 0x00FFFFFF ) );
addChild(r);
buttonMode = true;
addEventListener( "enterFrame", u );
addEventListener( "mouseUp", mu );
addEventListener( "mouseDown", md );
gio = new Gainer();
gio.analogInput(0).filters = [new Scaler(0.2, 0.8, 0, 1, Scaler.LINER, true)];
var smoother1:Convolution = new Convolution(Convolution.MOVING_AVERAGE);
var scaler1:Scaler = new Scaler(0.20, 0.90, 0, 1, Scaler.LINER, true);
gio.analogInput(2).filters = [smoother1, scaler1];
var smoother2:Convolution = new Convolution(Convolution.MOVING_AVERAGE);
var scaler2:Scaler = new Scaler(0.20, 0.90, 0, 1, Scaler.LINER, true);
gio.analogInput(1).filters = [smoother2, scaler2];
}
private function u(e:Event):void
{
var Xnum:Number = stage.stageWidth * gio.analogInput(2).value;
var Ynum:Number = stage.stageHeight * gio.analogInput(1).value;
for (var i:Number = 0; i < 200; i ++)
{
if (!bl[i])
{
bl[i] = new MovieClip();
bl[i].graphics.beginFill(0xFF7004A,1);
bl[i].graphics.drawCircle(0,0,Math.random()*40+5);
bl[i].x = Xnum;
bl[i].y = Ynum;
bl[i].xspeed = bl[i].yspeed = 0;
bl[i].cycle = Math.random() * .01 + .0005;
bl[i].offsetx = Math.random() * 200-100;
bl[i].offsety = Math.random() * 200-100;
c.addChild(bl[i]);
}
bl[i].x += bl[i].xspeed = (( Xnum - bl[i].x + bl[i].offsetx) * bl[i].cycle ) + ( bl[i].xspeed * p);
bl[i].y += bl[i].yspeed = (( Ynum - bl[i].y + bl[i].offsety) * bl[i].cycle ) + ( bl[i].yspeed * p);
}
r.bitmapData.fillRect(new Rectangle(0,0,stage.stageWidth, stage.stageHeight),0x00FFFFFF);
r.bitmapData.draw(c);
r.bitmapData.threshold(r.bitmapData,new Rectangle(0,0,stage.stageWidth, stage.stageHeight),new Point(0,0),">",0x00800000,0xFFFFFFFF,0x00808080,true);
if(gio.analogInput(0).value > 0.5){
md();
}
if(isPressed){
if(gio.analogInput(0).value < 0.5){
mu();
}
}
}
private function md(e:Event):void
{
for (var i:Number = 0; i < 200; i ++)
{
bl[i].offsetx += gio.analogInput(0).value * Math.random() * 100-50;
bl[i].offsety += gio.analogInput(0).value * Math.random() * 100-50;
}
isPressed = true;
}
private function mu(e:Event):void
{
for (var i:Number = 0; i < 200; i ++)
{
bl[i].offsetx = Math.random()*200-100;
bl[i].offsety = Math.random()*200-100;
}
isPressed = false;
}
}
}