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

砂 + computeSpectrum

fork http://wonderfl.net/c/2rWu
Get Adobe Flash player
by kuma360 11 Aug 2010
/**
 * Copyright kuma360 ( http://wonderfl.net/user/kuma360 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/sh9p
 */

//fork http://wonderfl.net/c/2rWu
package 
{
    import com.bit101.components.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.media.*;
    import flash.net.*;
    import flash.system.*;
    import flash.utils.*;
    
    
    
    [SWF ( width = 465, height = 465, frameRate = 60 )];
    public class Main extends Sprite 
    {
        
        private var _CANVAS:BitmapData = new BitmapData ( stage.stageWidth , stage.stageHeight , false , 0 ) ;
        
        private var _B0:PushButton ; 
        private var _B1:PushButton ; 
        private var _B2:PushButton ; 
        private var _B3:PushButton ; 
        
        private var _CLICK:Boolean = false ;
        private var _COLOR:uint = 0x836034;
        private var _BX:int = 0 ;
        private var _BY:int = 0 ;
        
        private const _s1:ByteArray = new ByteArray();
        private const _s2:Array = new Array();
        
        
        public function Main():void {
            
            addChild ( new Bitmap ( _CANVAS ) ) ;
            
            {//sound
                
                Security.loadPolicyFile('http://5ivestar.org/proxy/crossdomain.xml');
                
                var s:Sound = new Sound( 
                    new URLRequest('http://5ivestar.org/proxy/http://www.apmmusic.com/audio/WOM/WOM_WOM_0138/WOM_WOM_0138_00601.mp3'), 
                    new SoundLoaderContext(1000, true) 
                );
                
                s.play();
                
                for ( var I:int = 0 ; I < 512 ; ++ I ) {
                    _s2[I] = 0 ;
                }
                
            }
            
            {//button
            
                _B0 = new PushButton ( this,  10 , 20, "ERASE" ) ;
                _B1 = new PushButton ( this, 120 , 20, "WALL" ) ;
                _B2 = new PushButton ( this, 230 , 20, "SAND" ) ;
                _B3 = new PushButton ( this, 340 , 20, "WATER" ) ;
                _B1.enabled = false ;
                
                _B0.addEventListener ( MouseEvent.CLICK , function ():void { _COLOR = 0x000000 ; _B0.enabled = false ; _B1.enabled = true  ; _B2.enabled = true  ; _B3.enabled = true  ; } ) ;
                _B1.addEventListener ( MouseEvent.CLICK , function ():void { _COLOR = 0x836034 ; _B0.enabled = true  ; _B1.enabled = false ; _B2.enabled = true  ; _B3.enabled = true  ; } ) ;
                _B2.addEventListener ( MouseEvent.CLICK , function ():void { _COLOR = 0xF7E779 ; _B0.enabled = true  ; _B1.enabled = true  ; _B2.enabled = false ; _B3.enabled = true  ; } ) ;
                _B3.addEventListener ( MouseEvent.CLICK , function ():void { _COLOR = 0x80A2F0 ; _B0.enabled = true  ; _B1.enabled = true  ; _B2.enabled = true  ; _B3.enabled = false ; } ) ;
                
            }
           
            stage.addEventListener ( MouseEvent.MOUSE_DOWN , function ():void { _CLICK = true ; } ) ;
            stage.addEventListener ( MouseEvent.MOUSE_UP   , function ():void { _CLICK = false; } ) ;
            addEventListener ( Event.ENTER_FRAME , RUN ) ;
            
        }
        
        
        
        
        public function RUN ( e:Event ):void {
            
            var I:int = 0 ;
            var y1:int = 0 ;
            var y2:int = 0 ;
            
            
            _CANVAS.lock() ;
            
            ////////////////////////////////////
            _s1.position = 0 ;
            SoundMixer.computeSpectrum ( _s1, true ) ;
            for ( I = 0 ; I < 512 ; ++ I ) {
                
                y1 = _s1.readFloat() * 100 ;
                y2 = _s2[I] * 100 ;
                if ( y2 < y1 ) {
                    if ( I < 230 ) {
                        _CANVAS.setPixel ( I + 50 , 60 , 0xF7E779 ) ;
                    } else {
                        _CANVAS.setPixel ( I + 50 , 60 , 0x80A2F0 ) ;
                    }
                }
                _s2[I] = y1 ;
            }
                                    
            
            ////////////////////////////////////
            if ( _CLICK && 60 < mouseY && 60 < _BY ) {
                
                for ( var J:int = 0 ; J < 20 ; ++ J ) {
                    var R:Number = J / 20 ;
                    _CANVAS.fillRect ( new Rectangle ( _BX * R + mouseX * ( 1 - R ) , _BY * R + mouseY * ( 1 - R ) , 5 , 5 ) , _COLOR ) ;
                }
                
            }
            _BX = mouseX ;
            _BY = mouseY ;
            
            ////////////////////////////////////
            for ( var X:int = 0 ; X < _CANVAS.width ; ++ X ) {
                
                for ( var Y:int = _CANVAS.height - 1 ; Y >= 0 ; -- Y ) {
                    
                    var C:uint = _CANVAS.getPixel ( X , Y ) ;
                    if ( C == 0 ) {
                        continue ;
                    }
                    
                    if ( C == 0xF7E779 ) {
                        
                        var T:uint ;
                        var TX:int ;
                        
                        {//落下
                            T = _CANVAS.getPixel ( X , Y + 1 ) ;
                            if ( T == 0 ) {
                                _CANVAS.setPixel ( X , Y     , T ) ;
                                _CANVAS.setPixel ( X , Y + 1 , C ) ;
                                continue ;
                            }
                            
                            //水より砂の方が重い,適当な確率で場所の置換を許す。
                            if ( T == 0x80A2F0 && Math.random() < .5 ) {
                                _CANVAS.setPixel ( X , Y     , T ) ;
                                _CANVAS.setPixel ( X , Y + 1 , C ) ;
                                continue ;
                            }
                        }
                        
                        {//左右移動
                            TX = X + Math.floor ( Math.random() * 7 ) - 3 ;
                            T = _CANVAS.getPixel ( TX , Y ) ;
                            if ( T == 0 ) {
                                _CANVAS.setPixel (  X , Y , T ) ;
                                _CANVAS.setPixel ( TX , Y , C ) ;
                                continue ;
                            }
                            
                            //水より砂の方が重い,適当な確率で場所の置換を許す。
                            if ( T == 0x80A2F0 && Math.random() < .8 ) {
                                _CANVAS.setPixel (  X , Y , T ) ;
                                _CANVAS.setPixel ( TX , Y , C ) ;
                                continue ;
                            }
                        }
                        
                    }
                    
                    if ( C == 0x80A2F0 ) {
                        
                        {//落下
                            T = _CANVAS.getPixel ( X , Y + 1 ) ;
                            if ( T == 0 ) {
                                _CANVAS.setPixel ( X , Y     , T ) ;
                                _CANVAS.setPixel ( X , Y + 1 , C ) ;
                                continue ;
                            }
                        }
                        
                        {//左右移動
                            TX = X + Math.floor ( Math.random() * 7 ) - 3 ;
                            T = _CANVAS.getPixel ( TX , Y ) ;
                            if ( T == 0 ) {
                                _CANVAS.setPixel (  X , Y , T ) ;
                                _CANVAS.setPixel ( TX , Y , C ) ;
                                continue ;
                            }
                        }

                    }
                    
                }
                
            }
            
            
            _CANVAS.unlock() ;
            
        }
        
    }
    
}