forked from: forked from: Mosaic Smoke Colored Square

by kaaad
added color and rect
♥0 | Line 35 | Modified 2011-03-07 11:50:01 | MIT License
play

ActionScript3 source code

/**
 * Copyright kaaad ( http://wonderfl.net/user/kaaad )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/vEQS
 */

// forked from FelixT's forked from: Mosaic Smoke Colored Square
// forked from tjoen's Mosaic Smoke Colored Square
// forked from nemu90kWw's Mosaic Smoke
// added color and rect

package {
    import flash.display.*;
    import flash.geom.*;
    import flash.events.*;
    
    public class FlashTest extends Sprite {
        private var bmp:BitmapData = new BitmapData(24, 24, false);
        private var offsets:Array = new Array(new Point(), new Point());
        private var g:Shape = new Shape();
        private var circle:Vector.<Shape> = new Vector.<Shape>(bmp.width * bmp.height);
        
        function FlashTest() {
            graphics.beginFill(0x000000);
            graphics.drawRect(0, 0, 465, 465);
            
            var matrix:Matrix = new Matrix();
            matrix.createGradientBox(bmp.width, bmp.height, Math.PI/2);
            g.graphics.beginGradientFill(GradientType.LINEAR, [0x000000, 0xFFFFFF], [1, 1], [0, 255], matrix);
            g.graphics.drawRect(0, 0, bmp.width, bmp.height);
            
            for(var i:int = 0; i < bmp.width * bmp.height; i++) {
                circle[i] = Shape(addChild(new Shape()));
                circle[i].x = (i % bmp.width) * Math.random()*20;
                circle[i].y = Math.floor(i / bmp.width) * Math.random()*20;
                circle[i].graphics.beginFill(0x888888);
                circle[i].graphics.drawRect(Math.random(),Math.random(),Math.random()*5,Math.random());
            }
            
        }
          public function onEnterFrame(e:Event):void {
            bmp.perlinNoise(100, 30, 3, 0, false, true, 0, true, offsets);
            bmp.colorTransform(bmp.rect, new ColorTransform( 6, 3, 3, 1, -256, -256, -256, 0));
            
            for(var i:int = 0; i < circle.length; i++) {
                circle[i].scaleX = circle[i].scaleY = (bmp.getPixel(i % bmp.width, Math.floor(i / bmp.width)) & 0xFF) / 16;
            }
            
            offsets[0].offset(0.1, -0.1);
            offsets[1].offset(0.3, 0.05);
        }
      
    }
}