forked from: Movimento Orgânico

by Thy forked from Movimento Orgânico (diff: 148)
mesma coisa, mas dá errado :,(
tentei usar bmdata
mas com draw ao invés de cpyPxls, acho que a performace cai..
e.. rotation #fail
♥0 | Line 125 | Modified 2011-10-23 03:33:58 | GPLv3 License
play

ActionScript3 source code

/**
 * Copyright Thy ( http://wonderfl.net/user/Thy )
 * GNU General Public License, v3 ( http://www.gnu.org/licenses/quick-guide-gplv3.html )
 * Downloaded from: http://wonderfl.net/c/nfjV
 */

// forked from gabriel.eu.br's Movimento Orgânico
package {
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.display.StageQuality;
    import flash.events.Event;
    import flash.geom.Rectangle;
    
    public class Main extends Sprite 
    {
        private var bug:Bug = new Bug; // bug linked list 'header'
        private var data:BitmapData,
                    bm:Bitmap;
        private var w:int, 
                    h:int;
        
        public function Main() 
        {
            // listener
            this.addEventListener(Event.ENTER_FRAME, ef);
            
            // display
            stage.quality = StageQuality.LOW;
            w = stage.stageWidth;
            h = stage.stageHeight;
            rect = new Rectangle(0, 0, w, h);
            data = new BitmapData(w, h, true, 0);
            bm = new Bitmap(data, "auto", true);
            this.addChild(bm);
            
            // bugs creation
            { 
                var i:int= -1, // counter
                x:Number,
                y:Number,
                a:Number, // alpha
                s:Number, // scale
                b:Bug = bug; // temp bug 'pointer'
                
                while(++i < 50)
                {
                    x = Math.random() * w;
                    y = Math.random() * h;
                    a = Math.random() * .5 + .5;
                    s = Math.random() * 20 + 1;
                    b.next = new Bug(x, y, a, s, w, h);
                    b = b.next;
                }
            }
        }
        
        private var rect:Rectangle;
        public function ef (e:Event):void
        {
            data.lock();
            data.fillRect(rect, 0);
            
            var b:Bug = bug;
            while(b = b.next)
            {
                b.update();
                data.draw(b.data, b.matrix);
                //data.copyPixels(b.data, b.rect, b.point, null, null, true); 
            }
            data.unlock();
        }
    }
}


import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.Shape;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;

class Bug
{
    public var next:Bug,
               data:BitmapData,
               matrix:Matrix;
    private var w:int, w2:int, 
                h:int, h2:int,
                rect:Rectangle,
                x:Number = 0,
                y:Number = 0;
    private var vel:Number = 2, 
                dif:Number = .2, 
                angle:Number = Math.random() * Math.PI * 2;
    private const PIBY180:Number = Math.PI / 180;
    
    
    public function Bug (x:Number = 0, y:Number = 0, a:Number = 1, s:Number = 1, w:int = 465, h:int = 465)
    {
        this.x = x;
        this.y = y;
        this.w = w;
        this.h = h;
        
        // draw
        {
            var sh:Shape = new Shape();
            var g:Graphics = sh.graphics;
            var color:uint = Math.round(Math.random() * 256) << 16 | 
                             Math.round(Math.random() * 256) << 8 | 
                             Math.round(Math.random() * 256);
            g.lineStyle(1, color, 1, true);
            g.beginFill(color, a); // a for alpha
            g.lineTo(10 * s, 0); // s for scale
            g.lineTo(5 * s, 10 * s);
            g.endFill();
            g = null;
            dist = 5 * s;
            data = new BitmapData(sh.width, sh.height, true, 0);
            matrix = new Matrix();
            data.draw(sh);
            w2 = sh.width;
            h2 = sh.height;
            sh.graphics.clear();
            sh = null;
        }
    }
    
    private var cos:Number,
                sin:Number,
                dist:Number;
    public function update():void
    {
        angle += (Math.random() -.5) * dif * PIBY180;
        cos = Math.cos(angle);
        sin = Math.sin(angle);
        x += cos * vel;
        y += sin * vel;
        
        // doing it wrong
        
        if (x > w) x = -w2;
        else if (x < -w2) x = w;
        if (y > h) y = -h2;
        else if (y < -h2) y = h;
        
        matrix.identity();
        matrix.tx = x;
        matrix.ty = y;
        matrix.rotate(angle);
    }
    
}