prog.hu: Példányok elhelyezése egy ellipszis alakzatban

by szbzs2004
http://prog.hu/tudastar/148409/Peldanyok+elhelyezese+egy+ellipszis+alakzatban.html
♥0 | Line 38 | Modified 2012-03-12 09:33:20 | MIT License
play

ActionScript3 source code

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

// http://prog.hu/tudastar/148409/Peldanyok+elhelyezese+egy+ellipszis+alakzatban.html
package  {
   
    import flash.display.Sprite;
    import flash.geom.Point;
   
    [SWF(width="465", height="465", frameRate="25", backgroundColor="0")]
   
    public class Main extends Sprite {
       
        private static const H:int =   465;
        private static const W:int = H / 2;
        private static const N:int =  5000;
       
        public function Main() {
           addChild(new RndEllipse(W, H, N, 0xff0000, jari_jari));
           addChild(new RndEllipse(W, H, N, 0x00ff00, szbzs)).x = W;
        }

        private static function jari_jari():Point {
            var r:Number = Math.random();
            var angle:Number = 2 * Math.PI * Math.random();
            return Point.polar(r, angle);
        }

        private static function szbzs():Point {
            var r:Number = Math.sqrt(Math.random());
            var angle:Number = 2 * Math.PI * Math.random();
            return Point.polar(r, angle);
        }

    }
}

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Point;

class RndEllipse extends Bitmap {
   
    public function RndEllipse(width:int, height:int, numOfPoints:int, color:uint, rndPointFunc:Function) {
        var a:Number = width / 2;
        var b:Number = height / 2;
        super(new BitmapData(width, height, false, 0));
        for (var i:int = 0; i < numOfPoints; ++i) {
            var p:Point = rndPointFunc();
            this.bitmapData.setPixel(a * p.x + a, b * p.y + b, color);
        }
    }
}