zoukankan      html  css  js  c++  java
  • 好看的粒子效果

    [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});}

  • 相关阅读:
    Macbook下安装memcached
    CI框架视图继承
    JavaScript&jQuery 基本使用
    Mac下PHP的环境搭建
    完善口语第一步
    php反射
    php_Trait
    php接口和抽象类
    使用seafile搭建自己的私有云存储
    PHP 简单面向对象 验证码类(静态实例对象调用)
  • 原文地址:https://www.cnblogs.com/flashweb/p/2796894.html
Copyright © 2011-2022 走看看