Bitmap特效,被风吹散效果。
详细代码:
- package
- {
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.display.MovieClip;
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.filters.BlurFilter;
- import flash.geom.Point;
- import flash.geom.Rectangle;
- /**
- * ...
- * @author flashk
- */
- public class Min extends Sprite
- {
- public var a_mc:MovieClip;
- private var bd:BitmapData;
- private var bds:BitmapData;
- private var ps:Array;
- public function Min() {
- bd = new BitmapData(1420, 300, true);
- bds = new BitmapData(a_mc.width, a_mc.height, true);
- bds.draw(a_mc);
- var bp:Bitmap = new Bitmap();
- bp.bitmapData = bd;
- this.addChild(bp);
- start();
- }
- private function start():void {
- ps = new Array();
- for (var i:int = 1; i <= bds.width; i++) {
- for (var j:int = 1; j <= bds.height; j++) {
- ps.push(new Po(i, j, bds.getPixel32(i, j),bds.width));
- }
- }
- this.addEventListener(Event.ENTER_FRAME, render);
- this.removeChild(a_mc);
- }
- private function render(event:Event):void {
- var po;
- //bd.fillRect(new Rectangle(0, 0, bd.width, bd.height), 0);
- bd.applyFilter(bd, new Rectangle(0, 0, bd.width, bd.height), new Point(0, 0), new BlurFilter(2, 2, 1));
- bd.lock();
- var len = ps.length;
- for (var i:int = 0 ; i < len; i+=1) {
- po = ps[i];
- po.move();
- bd.setPixel32(po.x, po.y+80, po.color);
- }
- bd.unlock();
- }
- }
- }
- class Po {
- public var x:Number;
- public var y:Number;
- public var color:uint;
- private var speed:Number;
- private var r:Number = 0;
- private var by:Number;
- public function Po(x:Number, y:Number, color:uint,w:Number) {
- this.x = x;
- this.y = y;
- this.color = color;
- this.speed = Math.random() * 10 - (w - x) / 2;
- //r = Math.random() * 50;
- this.by = y;
- }
- public function move():void {
- speed += 0.5;
- if(speed>0){
- this.x += speed;
- r += 10;
- this.y = this.by + Math.sin(r* Math.PI/180)*50;
- }
- }
-
}
源文件和swf下载s2demo.rar:
再来玩个加鼠标控制的,美女被风吹散...
- package
- {
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.display.MovieClip;
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.filters.BlurFilter;
- import flash.filters.ColorMatrixFilter;
- import flash.geom.ColorTransform;
- import flash.geom.Point;
- import flash.geom.Rectangle;
- /**
- * ...
- * @author flashk
- */
- public class Min extends Sprite
- {
- public var a_mc:MovieClip;
- private var bd:BitmapData;
- private var bds:BitmapData;
- private var ps:Array;
- private var ns:uint;
- private var checks:Array;
- private var noise:BitmapData;
- private var randomSeed:Number;
- private var image:BitmapData;
- private var rect:Rectangle;
- private var cTra:ColorTransform;
- private var vectorList:Array;
- private var num:uint = 10000;
- public function Min() {
- noise = new BitmapData(a_mc.width, a_mc.height, false, 0x000000);
- randomSeed = Math.floor(Math.random() * 0xFFFF);
- noise.perlinNoise(a_mc.width, a_mc.height, 4, randomSeed, false, false, 1 | 2 | 0 | 0 );
- image = new BitmapData(465, 465, true, 0);
- this.addChild(new Bitmap(image));
- rect = new Rectangle( 0, 0, 465, 465 )
- cTra = new ColorTransform(1, 1, 1, 0.9, 0, 0, 0, 0)
- bd = new BitmapData(600, 450, true);
- bds = new BitmapData(a_mc.width, a_mc.height, true,0x00FFFFFF);
- bds.draw(a_mc);
- var bp:Bitmap = new Bitmap();
- bp.bitmapData = bd;
- ps = new Array();
- start(1);
- this.removeChild(a_mc);
- }
- private function start(s:uint):void {
- ns = s;
- vectorList = [];
- for (var i:int = s; i <= bds.width; i++) {
- for (var j:int = 1; j <= bds.height; j++) {
- vectorList.push(new Po(i, j, bds.getPixel32(i, j),bds.width,this));
- }
- }
- this.addEventListener(Event.ENTER_FRAME, render);
- }
- private function render(event:Event):void {
- image.colorTransform( rect, cTra );
- image.lock();
- var len:uint = vectorList.length;
- for (var i:uint = 0; i < len; i++) {
- var body:Po = vectorList[i];
- body.speed += 0.4;
- if(body.speed>0){
- var col:Number = noise.getPixel(body.px, body.py);
- body.ax += ((col >> 16 & 0xFF) - 128)/1000;
- body.ay += ((col >> 8 & 0xFF) -128)/1000;
- body.vx += body.ax;
- body.vy += body.ay;
- body.px += body.vx;
- body.py += body.vy;
- body.ax *= .975;
- body.ay *= .975;
- body.vx *= .92;
- body.vy *= .92;
- }
- if (body.px < 0) {
- vectorList.splice(i, 1);
- len -= 1;
- }
- image.setPixel32( body.px, body.py+100, body.color );
- }
- image.unlock();
- }
- }
- }
- class Po {
- public var x:Number;
- public var y:Number;
- public var color:uint;
- public var speed:Number;
- private var r:Number = 0;
- private var by:Number;
- public var vx:Number = 0;
- public var vy:Number = 0;
- public var ax:Number = 0;
- public var ay:Number = 0;
- public var px:Number;
- public var py:Number;
- public function Po(x:Number, y:Number, color:uint,w:Number,eventLis:Object) {
- this.x = x;
- this.y = y;
- this.px = x;
- this.py = y;
- this.color = color;
- this.speed = Math.random() * 15 - (w - x) / 3 -20;
- this.by = y;
- }
- }
鼠标控制swf效果:s2wind-mouseControl.rar