In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Moire Explorer

Theme:
* Play with BitmapPatterBuilder.
* Purpose of this trial is to find the possibility of the dot pattern.
*
* by Takayuki Fukatsu aka fladdict
/**
 * Copyright Quasimondo ( http://wonderfl.net/user/Quasimondo )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/c86c
 */

// forked from checkmate's fladdict challenge for professionals
/**
 * Theme:
 * Play with BitmapPatterBuilder.
 * Purpose of this trial is to find the possibility of the dot pattern.
 *
 * by Takayuki Fukatsu aka fladdict
 **/
package {
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Graphics;
    import flash.display.Sprite;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.geom.Matrix;
    import flash.filters.BlurFilter;
    
    public class Professional extends Sprite {
        
        private const layerCount:int = 2;
        private var patterns:Array = [];
        private var matrices:Array = [];
        private var angles:Array = [];
        
        public function Professional() {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            
            //generate bitmap pattern.
            for ( var i:int = 0; i<layerCount; i++ )
            {
                patterns.push( randomPattern() );
                matrices.push( new Matrix() );
                angles.push( 0.01 * ( Math.random()-Math.random() ));
            }
            
            stage.addEventListener( Event.ENTER_FRAME, animate );
            this.filters = [ new BlurFilter(2,2,2)];
        }
        
        private function animate( event:Event ):void
        {
            var g:Graphics = graphics;
            g.clear();
            for ( var i:int = 0; i<layerCount; i++ )
            {
                matrices[i].rotate(angles[i]);
                g.beginBitmapFill(patterns[i],matrices[i]);
                g.drawRect(0,0,480,480);
                g.endFill();
                if ( Math.random() < 0.005 )
                {
                    patterns[i] = randomPattern();
                }
                if ( Math.random() < 0.05 )
                {
                   angles[i] = 0.01 * ( Math.random()-Math.random() );
                }
                
            }
          }
        
        //most simple patern
        public function randomPattern():BitmapData{
            var line:Array = [];
            for ( var x:int = 0; x < 10; x++ )
            {
                line.push( Math.random() < 0.5 ? 1 : 0 )
             }
               
                
            return BitmapPatternBuilder.build(
                [line],
                [0x00000000, 0xff000000]
            );
        }
    
       
    }
}

/**-----------------------------------------------------
 * Use following BitmapPatternBuilder class 
 * 
 * DO NOT CHANGE any codes below this comment.
 *
 * -----------------------------------------------------
*/
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Graphics;
    
class BitmapPatternBuilder{
    /**
     * creates BitmapData filled with dot pattern.
     * First parameter is 2d array that contains color index for each pixels;
     * Second parameter contains color reference table.
     *
     * @parameter pattern:Array 2d array that contains color index for each pixel.
     * @parameter colors:Array 1d array that contains color table.
     * @returns BitmapData
     */
    public static function build(pattern:Array, colors:Array):BitmapData{
        var bitmapW:int = pattern[0].length;
        var bitmapH:int = pattern.length;
        var bmd:BitmapData = new BitmapData(bitmapW,bitmapH,true,0x000000);
        for(var yy:int=0; yy<bitmapH; yy++){
            for(var xx:int=0; xx<bitmapW; xx++){
                var color:int = colors[pattern[yy][xx]];
                bmd.setPixel32(xx, yy, color);
            }
        }
        return bmd;
    }
    
    /**
     * short cut function for Graphics.beginBitmapFill with pattern.
     */
    public static function beginBitmapFill(pattern:Array, colors:Array, graphics:Graphics):void{
        var bmd:BitmapData = build(pattern, colors);
        graphics.beginBitmapFill(bmd);
        bmd.dispose();        
    }
}