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

乱数雑伎

クリックで分布がかわるよ!
Get Adobe Flash player
by uwi 28 Oct 2009
/**
 * Copyright uwi ( http://wonderfl.net/user/uwi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/pXiO
 */

// クリックで分布がかわるよ!
package {
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    
    [SWF(frameRate=60)]
    public class FlashTest extends Sprite {
        private static var NSPLIT : int = 400;
        private var _box : Array;
        private var _bmd : BitmapData;
        private var _tf : TextField;
        
        public function FlashTest() {
            _box = new Array(NSPLIT);
            
            _bmd = new BitmapData(400, 400, false, 0xffffff);
            var bmp : Bitmap = new Bitmap(_bmd);
            addChild(bmp);
            bmp.x = 30;
            bmp.y = 30;
            
            _mode = -1;
            
            _tf = new TextField();
            addChild(_tf);
            _tf.width = 465;
            _tf.height = 465;
            _tf.selectable = false;
            
            addEventListener(MouseEvent.CLICK, onClick);
            onClick();
        }
        
        private var _ct : int;
        private var _mode : int;
        private var FTEMP : Array = [sample1, sample2, sample3, sample4, sample5, sample6, sample7, sample8, sample9];
        private var LTEMP : Array = [
            "Math.random() * 2 - 1", 
            "Math.random() - Math.random()", 
            "(Math.random() + Math.random() + Math.random()) * 2 / 3 - 1",
            "Math.random() * Math.random() * 2 - 1",
            "Math.sqrt(Math.random()) * 2 - 1",
            "Math.sin(Math.random() * Math.PI * 2)",
            "Math.asin(Math.random() * 2 - 1) / (Math.PI / 2)",
            "Math.max(Math.random(), Math.random()) * 2 - 1",
            "Math.max(Math.random(), Math.random(), Math.random()) * 2 - 1"
        ];
        
        private function onEnterFrame(e : Event) : void
        {
            _bmd.lock();
            for(var r : int = 0;r < 300;r++){
                var i : int = (FTEMP[_mode]() + 1) / 2 * NSPLIT;
                
                _bmd.setPixel(i, 400 - _box[i], 0x000000);
                _box[i]++;
            }
            _bmd.unlock();
            _ct++;
            if(_ct == 200)removeEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        
        private function onClick(e : MouseEvent = null) : void
        {
            _mode++;
            if(_mode == FTEMP.length)_mode = 0;
            
            _tf.text = LTEMP[_mode];
            
            for(var i : int = 0;i < NSPLIT;i++){
                _box[i] = 0;
            }
            _bmd.fillRect(_bmd.rect, 0xffffff);
            
            _ct = 0;
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        
        public function sample1() : Number
        {
            return Math.random() * 2 - 1;
        }
        
        public function sample2() : Number
        {
            return Math.random() - Math.random();
        }
        
        public function sample3() : Number
        {
            return (Math.random() + Math.random() + Math.random()) * 2 / 3 - 1;
        }
        
        public function sample4() : Number
        {
            return Math.random() * Math.random() * 2 - 1;
        }
        
        public function sample5() : Number
        {
            return Math.sqrt(Math.random()) * 2 - 1;
        }
        
        public function sample6() : Number
        {
            return Math.sin(Math.random() * Math.PI * 2);
        }
        
        public function sample7() : Number
        {
            return Math.asin(Math.random() * 2 - 1) / (Math.PI / 2);
        }
        
        public function sample8() : Number
        {
            return Math.max(Math.random(), Math.random()) * 2 - 1;
        }
        
        public function sample9() : Number
        {
            return Math.max(Math.random(), Math.random(), Math.random()) * 2 - 1;
        }        
    }
}