Geek's Love

by Jacky.Riawan
<3
♥0 | Line 57 | Modified 2011-11-04 09:31:03 | MIT License
play

ActionScript3 source code

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

package {
    import flash.events.Event;
    import flash.display.AVM1Movie;
    import flash.display.Sprite;
    import flash.events.Event;
    [SWF(frameRate="90")]
    public class FlashTest extends Sprite {
        private var numSeed:int = 8100;//seeds number :)
        private const scale:int=90;//scale of the plot
        private const plotSpeed:int=10; //plotting speed
        private const shiftX:Number=stage.stageWidth/2;
        private const shiftY:Number=stage.stageHeight/2;
        public function FlashTest() {
           addEventListener(Event.ENTER_FRAME,plotting);
        }
        private function plotting(e:Event):void{
            for(var i:int=0;i<plotSpeed;i++){
                doRandomPlot();
                numSeed--;
                if(numSeed==0){
                    removeEventListener(Event.ENTER_FRAME,plotting);
                }

            }
        }

        //call this for instant plotting
        private function instantPlot():void{
            for (var seedX:int=0; seedX<Math.sqrt(numSeed); seedX++)
            {
                for (var seedY:int=0; seedY<Math.sqrt(numSeed); seedY++)
                {
                   doRandomPlot();
                }
            }
        }
        private function doRandomPlot():void{
            var plotX:Number=Math.random()*3-1.5;
            var plotY:Number=Math.random()*3.5-1.5;
            if(get_plot(plotX,plotY)){
                graphics.lineStyle(1,0xFF0000,Math.random()/2+.5);
            }else{
                graphics.lineStyle(1,0xCCCCCC,Math.random()/2);
            }
            graphics.drawCircle(shiftX+plotX*scale,shiftY+plotY*scale*-1,1);
        }

        private function get_plot(plot_x:Number,plot_y:Number):Boolean
            {
                var num:Number=Math.pow(plot_x,2)+Math.pow((plot_y-Math.pow(Math.pow(plot_x,2),1/3)),2);
                if (num<1)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            
            }
    }
}