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

forked from: forked from: code on 2008-12-17

Study for color generation.
Get Adobe Flash player
by fladdict 17 Dec 2008
    Embed
// forked from fladdict's forked from: code on 2008-12-17
// forked from fladdict's code on 2008-12-17
// write as3 code here..
// Study for color generation.
package{
  import flash.display.*
  import flash.events.*

  public class Sketch01 extends Sprite
  {
    public var lines:Array;
    public var canvas:BitmapData;



    public function Sketch01():void
    {
      lines = [];
      var yPos:Number = 0;
      while(yPos<stage.stageHeight){
        var h:Number = Math.round(10 + normRand()*18);
        var bmd:BitmapData = new BitmapData(stage.stageWidth, h, false, 0);
        var bm:Bitmap = new Bitmap(bmd);
        bm.y = yPos;
        //bm.y = stage.stageHeight * 0.5;
        bm.x = stage.stageWidth * 0.5;
        addChild(bm);
        yPos += bm.height;
        lines.push(bm);
      }
      stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
    }

    public function enterFrameHandler(e:Event):void
    {
      var n:int = lines.length;
      for(var i:int=0; i<n; i++)
      {
        var bm:Bitmap = lines[i];
        var bmd:BitmapData = bm.bitmapData;
        bmd.fillRect(bmd.rect, getColor());

        bm.rotationY = Math.random()*360;
        bm.rotationX = Math.random()*360;
        bm.rotationZ = Math.random()*360;
      }
    }

    protected function getColor():int
    {
        var b:int = Math.random()*255;
        var r:int = Math.random()*b;
        var g:int = Math.random()*r;
        
        return r<<16 | g<<16 | b;
    }

    protected function normRand():Number 
    {
      return (Math.random()+Math.random()+Math.random()+Math.random()+Math.random())/5 - 0.5;
    }
  }
}