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

forked from: forked from: Tiling

Get Adobe Flash player
by aobyrne 28 Jun 2011
/**
 * Copyright aobyrne ( http://wonderfl.net/user/aobyrne )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/7LZE
 */

// forked from whirlpower's forked from: Tiling
// forked from quqjp's Tiling
// forked from quqjp's Tiling
package 
{
    /*
    * BitmapをやめてShapeにしてみた。
    * 構造理解のため、そぎ落とせるところはそぎ落としている。
    *
    * ※ 止まりません。
    */

    import flash.display.*;
    import flash.events.Event;
    import flash.text.TextField;
    
    public class TilingAlternate extends Sprite
    {
        private var mapLogic:MapLogic;
        public static var textField:TextField;
        private var csprite:Sprite;
        
        public function TilingAlternate():void
        {
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            setDebug();
            csprite = new Sprite;
            addChild(csprite);
            
            mapLogic = new MapLogic( 45, 45, 5, 10,false);
            //addEventListener( Event.ENTER_FRAME, render );
            
            theMethod();
        }
        
        private function setDebug():void 
        {
            textField = new TextField();
            textField.width = 400;
            textField.height = 400;
            textField.border = true;
            textField.x = 465;
            cTrace( "textField : " + textField );
            addChild(textField);
        }
        
        
        private function theMethod():void 
        {
            csprite.visible = false;
            while (Tile(csprite.addChild( mapLogic.create() )).y < 480) 
            {
                
                
            }
            cTrace('----------------------------------------------------------------')
            cTrace('----------------------------------------------------------------')
            cTrace('----------------------------------------------------------------')
            cTrace('----------------------------------------------------------------')
            Tile.period = Tile.counter;
            Tile.counter = 0;
            Tile.linePeriod = Tile.lineCounter;
            Tile.lineCounter = 0;
            mapLogic.reset();
            mapLogic.hasPeriodBeenSet = true;
            while (csprite.numChildren)
            {
                csprite.removeChildAt(csprite.numChildren-1)
            }
            csprite.visible = true;
            addEventListener( Event.ENTER_FRAME, render );
        }
        
        
        private function cTrace(msg:String):void 
        {
            traceAt(msg);
        }
        
        private function render( e:Event ):void
        {
            if (Tile(csprite.addChild( mapLogic.create() )).y > 480)
            {
                removeEventListener(Event.ENTER_FRAME, render );
                
            }
        }
        
        public static function traceAt(msg:String):void
        {
            textField.appendText(msg + '\n');
            textField.scrollV = textField.maxScrollV;
        }
        
    }
}

import flash.display.*;
import flash.text.TextField;
import frocessing.color.ColorHSV;
    
internal class MapLogic
{
    private var _map            :Array = [];
    
    private var gridW        :int;
    private var igridW        :int;
    
    private var gridH        :int;
    private var igridH        :int;
    
    private var tileMax        :int;
    private var itileMax        :int;
    
    private var tileScale    :int = 10;
    private var itileScale    :int = 10;
    
    private var _isDisplaying:Boolean;
    public  var emptyPos        :int = 0;
    public var hasPeriodBeenSet:Boolean;
    
    private var values:Array;
    private var count:uint;
    
    public function MapLogic( gridW:int, gridH:int, tileMax:int, tileScale:int ,isDisplaying:Boolean = true):void
    {
        _isDisplaying = isDisplaying;
        this.gridW        = igridW=gridH;
        this.gridH        = igridH=gridW;
        this.tileMax        = itileMax=tileMax;
        this.tileScale    = itileScale=tileScale;
        values = [];
    }
    
    
    private function cTrace(arg1:String):void 
    {
        TilingAlternate.traceAt(arg1);
    }
    
    public function create(number:Number=0):Tile
    {
        var position        :int = -1;
        var emptyWidth    :int = 0;
        
        for ( var i:int = emptyPos; i < emptyPos + 500 ; i++ ){
            if ( !_map[i] && position == -1 ){
                position = i;
                emptyWidth++;
            } else if ( emptyWidth >= tileMax ){
                break;
            } else if ( !_map[i] && !( i % gridW == 0 && i != emptyPos ) ) {
                emptyWidth++;
            } else if ( position != -1 ) {
                break;
            }
        }
        var ww:int    = hasPeriodBeenSet ? values[count++][2] / tileScale:int( Math.random() * emptyWidth ) + 1;
        number = 0;
        cTrace( "ww : " + ww );
        
        var p:int = position;
        for ( var yy:int = 0; yy < ww; yy++ ){
            for ( var xx:int = 0; xx < ww; xx++ ){
                _map[p] = 1;
                p++;
            }
            p += gridW - ww;
        }
        emptyPos = position + ww;
        
        var px:int = position % gridW * tileScale;
        trace( "px : " + px );
        var py:int = position == 0 ? 0 : int( position / gridW ) * tileScale;
        cTrace( "position : " + position );
        cTrace( "py : " + py );
        var color:uint = 0;
        if (!hasPeriodBeenSet)
        {
            values[values.length] = [px, py, ww * tileScale, ww * tileScale, _isDisplaying ];  
        }
        else 
        {
            color = 1;
        }
        return new Tile( px, py, ww * tileScale, ww * tileScale,_isDisplaying,color );
    }
    
    public function reset():void 
    {
        cTrace( "MapLogic.reset" );
        this.gridW        = igridW;
        this.gridH        = igridH;
        this.tileMax        = itileMax;
        this.tileScale    = itileScale;
        //values.length = 0;
        _map = null;
        _map = [];
        emptyPos = 0;
    }
}
internal class Tile extends Sprite
{
    static private var color:uint;
    public static var counter:int;
    public static var lineCounter:int;
    public static var period:uint = 310;
    public static var linePeriod:uint = 310;
    private const colors:Array=[0xff0000,0,0xff]
    public function Tile( _x:int, _y:int, _w:int, _h:int,isDisplaying:Boolean=true,colorArg:uint=0 ):void
    {
        if (_x<0.1) 
        {
            
            if (colorArg) 
            {
                color = new ColorHSV(lineCounter++ * 360 / linePeriod).value
                if (lineCounter%2==1 && false) 
                {
                    color = colors[lineCounter % colors.length];
                    color = 0;
                }
            }
            else
            {
                color = colors[lineCounter++ % colors.length];
            }
        }
        this.x = _x+1;
        this.y = _y+1;
        counter++;
        if(isDisplaying)(addChild(new TextField) as TextField).text = counter.toString();
        if (lineCounter%2==1)graphics.lineStyle( 2,  colors[lineCounter % colors.length] );
        graphics.beginFill(color);
        graphics.drawRect( 0, 0, _w-2, _h-2 );
    }
    
    private function cTrace(arg1:String):void 
    {
        TilingAlternate.traceAt(arg1);
    }
}