Rainbow Goo

by bradsedito
♥0 | Line 46 | Modified 2013-01-26 01:57:33 | MIT License
play

ActionScript3 source code

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





// forked from chinkurosanbo's AS??
 package
 {
     import flash.display.BlendMode;
     import flash.display.Shape;
     import flash.display.Sprite;
     import flash.events.Event;
     import flash.filters.BlurFilter;

     [SWF(width="500", height="500", backgroundColor="0xffffff", frameRate="90")]


     public class SimpleRepulsion extends Sprite
     {
         private var num          :int    =  250;
         private var firstPointX  :Array  =  new Array();
         private var firstPointY  :Array  =  new Array();
         private var blurr:BlurFilter = new BlurFilter( 6,6,3 );


         public function SimpleRepulsion()
         {
             for(var i:int=0; i < num; i++)
             {
                 var circle:Shape=new Shape();
                 circle.graphics.beginFill(Math.random() * 0xFFFFFF);   //0x111111);
                 circle.graphics.drawCircle( 0,0,30 );
                 circle.graphics.endFill();
                 circle.blendMode  =  BlendMode.ADD;  //MULTIPLY;
                 circle.filters    =  [ blurr ];                
                
                 circle.x=Math.round(Math.random() * stage.stageWidth);
                 circle.y=Math.round(Math.random() * stage.stageHeight);
                 circle.name="circle" + i.toString();
                 addChild(circle);

                 firstPointX[i]=circle.x;
                 firstPointY[i]=circle.y;
             }

             addEventListener(Event.ENTER_FRAME, onFrame);
         }


         public function onFrame(e:Event):void
         {
             for(var i:int=0; i < num; i++)
             {
                 var circle:Shape=getChildByName("circle" + i.toString())as Shape;
                 var theta:Number=Math.atan2((circle.y - mouseY), (circle.x - mouseX));
                 var d:Number=1000 / Math.sqrt(Math.pow(mouseX - circle.x, 2) + Math.pow(mouseY - circle.y, 2));

                 circle.x+=d * Math.cos(theta) + (firstPointX[i] - circle.x) * 0.08;
                 circle.y+=d * Math.sin(theta) + (firstPointY[i] - circle.y) * 0.08;
             }
         }
     }
 }