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

Testing if Point < Point is useful - not really

Get Adobe Flash player
by Quasimondo 03 Apr 2011
    Embed
/**
 * Copyright Quasimondo ( http://wonderfl.net/user/Quasimondo )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/z7jl
 */

package {
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.geom.Point;
    
    public class PointTest extends Sprite {
        public function PointTest() {
            test2()
        }
        
        private function test():void
        {
            var v:Vector.<Point> = new Vector.<Point>()
            for ( var i:int = 0; i < 255; i++ )
            {
                v.push( new Point( int(200*Math.random()), int(200*Math.random()) ) );
                
            }
            
            v.sort( function( a:Point, b:Point):int{
                if ( a < b ) return -1;
                if ( a > b ) return 1;
                return 0;
            });
            var b:BitmapData = new BitmapData(200,200,false,0);
            for ( i = 0; i < 255; i++ )
            {
                b.setPixel( v[i].x,v[i].y,i << 16 | i << 8 | i );
            }
            
            addChild( new Bitmap(b) );
            
            
        }
        
        private function test2():void
        {
            var v:Vector.<Point> = new Vector.<Point>()
            for ( var i:int = 0; i < 255; i++ )
            {
                v.push( new Point( int(200*Math.random()), int(200*Math.random()) ) );
                
            }
            
            v.sort( function( a:Point, b:Point):int{
                return ( a.x - b.x + 200 * (a.y - b.y) )
            });
            var b:BitmapData = new BitmapData(200,200,false,0);
            for ( i = 0; i < 255; i++ )
            {
                b.setPixel( v[i].x,v[i].y,i << 16 | i << 8 | i );
            }
            
            addChild( new Bitmap(b) );
            
            
        }

    }
}