randomで調べ物

by h_kamizono forked from test (diff: 52)
 
♥0 | Line 40 | Modified 2010-11-03 18:50:52 | MIT License
play

ActionScript3 source code

/**
 * Copyright h_kamizono ( http://wonderfl.net/user/h_kamizono )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/bg7US
 */

package {
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            
            var N:int = 100;
            for (var i:int; i < N; ++i)
            {
                // 黄色はMath.random() only
                var y:Particle = new Particle(Math.random()*stage.stageWidth, Math.random()*stage.stageHeight, 0xffff00);
                addChild(y);
                y.draw();
                
                // 赤はMath.sqrt( Math.random() )
                var r:Particle = new Particle(Math.sqrt(Math.random())*stage.stageWidth, Math.sqrt(Math.random())*stage.stageHeight, 0xff0000);
                addChild(r);
                r.draw();
                
                // 蒼はMath.sqrt ( Math.sqrt( Math.random() ) )
                var b:Particle = new Particle(Math.sqrt(Math.sqrt(Math.random()))*stage.stageWidth, Math.sqrt(Math.sqrt(Math.random()))*stage.stageHeight, 0x00ffff);
                addChild(b);
                b.draw();
                
            }
        }
    }
}


import flash.display.Sprite;
class Particle extends Sprite
{
    private var _x:Number;
    private var _y:Number;
    private var _c:uint;
  
    public function Particle(x:Number, y:Number, color:uint)
    {
        _x = x;
        _y = y;
        _c = color;
    }
    
    public function draw():void
    {
        graphics.clear();
        graphics.lineStyle(0);
        graphics.beginFill(_c);
        graphics.drawCircle(_x, _y, 3);
    }
}