flash on 2013-6-15
/**
* Copyright J.J ( http://wonderfl.net/user/J.J )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/i9nT
*/
package {
import flash.events.Event;
import flash.geom.ColorTransform;
import flash.filters.BlurFilter;
import flash.display.BitmapData;
import flash.media.Video;
import flash.media.Camera;
import flash.display.Bitmap;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private var w:int,h:int;
private var partilces : Vector.<Particle>;
private var vidbmp : Bitmap;
private var cam : Video;
private var main : Bitmap;
private var clr : ColorTransform;
private var blrfltr : BlurFilter;
public function FlashTest() {
// write as3 code here..
stage.frameRate=60;
w=stage.stageWidth;
h=stage.stageHeight;
cam=new Video(w,h)
var c:Camera=Camera.getCamera()
cam.attachCamera(c)
partilces=new Vector.<Particle>()
main=new Bitmap()
main.bitmapData=new BitmapData(w, h,false,0x000000)
addChild(main)
clr=new ColorTransform(2,2,2,1);
blrfltr=new BlurFilter(5,5);
vidbmp=new Bitmap()
vidbmp.bitmapData=new BitmapData(w,h ,false);
for (var i : int = 0; i <8000; i++) {
var p:Particle=new Particle(Math.random()*w, Math.random()*h);
var m:Number=Math.random()*2*Math.PI
p.vx=Math.sin(m);
p.vy=Math.cos(m);
partilces.push(p);
}
addEventListener(Event.ENTER_FRAME, loop)
}
private function loop(event : Event) : void {
vidbmp.bitmapData.draw(cam)
vidbmp.bitmapData.colorTransform(vidbmp.bitmapData.rect,clr );
var n:int=2
while(n--){
main.bitmapData.lock()
main.bitmapData.applyFilter(main.bitmapData, main.bitmapData.rect, main.bitmapData.rect.topLeft, blrfltr)
partilces.forEach(function (p:Particle,src:*,i:*):*{
var c:Number=vidbmp.bitmapData.getPixel(p.x, p.y) & 0xff;
var cright:Number=vidbmp.bitmapData.getPixel(p.x+1, p.y) & 0xff;
var cdown:Number=vidbmp.bitmapData.getPixel(p.x, p.y+1) & 0xff;
p.vx+=(cright-c)/50
if(Math.abs(p.vx)>.5) p.vx*=.98
p.x+=p.vx
p.vy+=(cdown-c)/50
if(Math.abs(p.vy)>.5) p.vy*=.98
p.y+=p.vy
if(p.x<=0 || p.x>w) p.vx*=-1,p.vx*=.98
if(p.y<=0 || p.y>h) p.vy*=-1
main.bitmapData.setPixel(p.x, p.y, vidbmp.bitmapData.getPixel(p.x, p.y))
})
main.bitmapData.unlock()
}
}
}
}
class Particle {
public var x:Number,y:Number,vx:Number,vy:Number;
public function Particle (_x:Number,_y:Number){
this.x=_x,this.y=_y
vx=vy=0;
}
}