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

3d spiral

just boring in work - 3d spiral
Get Adobe Flash player
by malczak 09 Jan 2009

    Tags

    3d
    Embed
                            /* just boring in work - 3d spiral */
package {
 import flash.display.*;
 import flash.geom.*;
 import flash.filters.*;
 import flash.events.Event;

 [SWF(width="400", height="400", backgroundColor="0xffffff", frameRate="15")]    
  
  /**
  * @author : Mateusz Malczak (http://segfaultlabs.com)
  */
  public class Main extends MovieClip {

     private var bv:Vector.<Bitmap> = new Vector.<Bitmap>(0,false);
     private var stepRotMtx : Matrix3D;

     public function Main():void
     {
        var s:BitmapData = new BitmapData(120,120);
        s.perlinNoise(200,200,8,Math.random(),true,true,BitmapDataChannel.BLUE,true);
        
        var blurf:BlurFilter = new BlurFilter(8,0);    

        var R:Number = 200; /* spiral radius */
        var sd:Number = 18; /* spiral leap */

        var rdl:Number = R * Math.sqrt( 2*(1 - Math.cos( 36*Math.PI/180 ) ) );
        rdl = Math.atan2( rdl, sd )*180/Math.PI-90; /* side radius beetween two elements */
        
        /* create bitmaps */
        var i:uint;
        var b:Bitmap;
        var m3d:Matrix3D;
        var alfa:Number;
            for ( i=0; i<40; i+=1 )
            {
                b = new Bitmap(s);
                m3d = new Matrix3D();                
                m3d.appendTranslation(-60,-60,0); /* move transformation ref. point to the center of bitmap */
                m3d.appendRotation( rdl, Vector3D.Z_AXIS );
                m3d.appendRotation( -5, Vector3D.X_AXIS );
                m3d.appendRotation( (90-36*i), Vector3D.Y_AXIS );
                alfa = 36*i*Math.PI/180;
                m3d.appendTranslation( R*Math.cos(alfa), 
                                       sd*i, /* spiral Y shift */
                                       R*Math.sin(alfa) );
                m3d.appendTranslation( 200, 0, 150 );
                m3d.appendRotation( 25, Vector3D.X_AXIS );
                b.transform.matrix3D = m3d;
                b.filters = [ blurf, 
                              new ColorMatrixFilter(           
                                [
                                        1,0,0,0,5*i,
                                        0,1,0,0,2*i,
                                        0,0,1,0,-2*i,
                                        0,0,0,1,0
                                ] )
                            ];
                bv.push( b );    
                addChild( b );
            }; 
       /* enter frame rotation modification */
       stepRotMtx = m3d = new Matrix3D();
       m3d.appendRotation( -25, Vector3D.X_AXIS );
       m3d.appendTranslation( -200, 0, -150 );
       m3d.appendRotation( 10, Vector3D.Y_AXIS );
       m3d.appendTranslation( 200, 0, 150 );
       m3d.appendRotation( 25, Vector3D.X_AXIS );

       addEventListener( Event.ENTER_FRAME, ef );
     }

    public function ef( evt:Event ):void
    {
        var b:Bitmap;
        var m3d:Matrix3D;
            for each ( b in bv )
                b.transform.matrix3D.append( stepRotMtx );
        sortZ(); /* fix z ordering */
    }

    private function sortZ():void
    {
        bv.sort( sortF ); /* sort on z */
        bv.forEach( reorder ); /* indices fix based on depth */
    };
    
    private function reorder( b1:Bitmap, idx:int, v:Object ):void
    {
        setChildIndex( b1, idx );
    };

    private function sortF( b1:Bitmap, b2:Bitmap ):Number 
    {    
        if ( b1.z < b2.z ) return 1;
        if ( b1.z > b2.z ) return -1;
        return 0;
    };

  }
}