• 好看的粒子效果


    [SWF(width=800, height=465, backgroundColor=0x000000, frameRate=60)]
    var gravity:Number = .15, drag:Number = 0.6, bm:Bitmap, _canvas:BitmapData, _gbmp:BitmapData, _forceMap:BitmapData, _snow:Array=[], tf:TextField = new TextField(), _mat:Matrix = new Matrix(.25, 0, 0, .25), _sw:int=stage.stageWidth, _sh:int=stage.stageHeight;
    this.addChild(new Bitmap(_canvas = new BitmapData(_sw, _sh, false, 0x000000))) as Bitmap;
    this.addChild(bm = new Bitmap(_gbmp = new BitmapData(_sw*.25, _sh*.25, false, 0x000000),'never',true));
    bm.scaleX = bm.scaleY = 4;
    bm.blendMode = 'lighten';
    tf.defaultTextFormat = new TextFormat('Verdana',200, 0xffff00, true);
    tf.autoSize = TextFieldAutoSize.LEFT;
    tf.text = 'love';
    tf.x = (_sw - tf.width) *.5;
    tf.y = (_sh - tf.height) *.5;
    _forceMap = new BitmapData(_sw, _sh, false, 0x000000);
    _forceMap.draw(tf, tf.transform.matrix);
    _forceMap.applyFilter(_forceMap, _forceMap.rect, new Point(0, 0), new BlurFilter(4, 4));
    this.addEventListener(Event.ENTER_FRAME, function(){
    _canvas.lock();
    _canvas.fillRect(_canvas.rect, 0x000000);
    var n:int = _snow.length, d:Number
    while (n--) {var p:Object = _snow[n];p.vy += gravity * p.s;p.vx *= p.vy *= 0.95;p.vx *= p.vy *= 1 - (_forceMap.getPixel(p.x, p.y) / 0xffffff) * drag; p.x += p.vx; p.y += p.vy; _canvas.setPixel(p.x, p.y, 0xffffff);if (p.y > _sh) {_snow.splice(n, 1)}}
    _gbmp.draw(_canvas, _mat);
    _canvas.unlock();
    n = 10;
    while (n--) {particle(Math.random() * _sw, 0, Math.random() + 0.5);}});
    stage.addEventListener(MouseEvent.CLICK,function():void{_canvas.fillRect(_canvas.rect, 0x000000);_snow=[];})
    function particle(px:Number, py:Number, ps:Number = 1, pvx:Number = 0, pvy:Number = 0):void {_snow.push({x:px,y:py,s:ps,vx:pvx,vy:pvy});}

  • 相关阅读:
    mysql 去除重复数据
    linux 相关命令
    mysql load data infile auto increment id
    《Head First 设计模式》读书笔记
    《NoSQL精粹》读书笔记
    linux 服务器丢包故障排查
    《高性能MySQL》 读书总结
    NAT穿透(UDP打洞)
    python函数调用关系图(python call graph)
    VMware 三种网络模式
  • 原文地址:https://www.cnblogs.com/flashweb/p/2796894.html
Copyright © 2020-2023  润新知