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: 3D Carousel

forked by rigardkruger (http://www.rigardkruger.com)
Flash 10 で被写界深度ネタ Z-sortつき
Get Adobe Flash player
by rigard 29 Dec 2008
// forked by rigardkruger (http://www.rigardkruger.com)
// forked from clockmaker's 3D Carousel
// Flash 10 で被写界深度ネタ Z-sortつき
package{
  import flash.display.*
  import flash.events.*
  import flash.filters.BlurFilter;
  import flash.geom.*;
  
  [SWF(frameRate="90", width="465", height="465")]
  public class Main extends Sprite {

  public function Main() {
      
        var m:Matrix = new Matrix();
        m.createGradientBox(stage.stageWidth, stage.stageHeight);

        var back:Shape = new Shape();
        back.graphics.beginGradientFill(GradientType.RADIAL, [0x000000, 0x101010], [1, 1], [175, 255], m);
        back.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
        back.graphics.endFill();
        addChild(back);

      var main :Sprite = Sprite(addChild(new Sprite()))
      main.x = stage.stageWidth / 2
      main.y = stage.stageHeight / 2
      //var wrap :Sprite = Sprite(main.addChild(new Sprite()))
        var wrap:Sprite = new Sprite();
        var wrapwrap:Sprite = new Sprite();
        wrap.x = stage.stageWidth / 2;
        wrap.y = stage.stageHeight / 2;
        wrapwrap.addChild(wrap);

        var data:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0x00000000);
        var output:Bitmap = new Bitmap(data);
        addChild(output);
      
      var pp:PerspectiveProjection = root.transform.perspectiveProjection; 
      
        var numObjects:int = 50;
      var objs:Array = []
      for(var i:int=0; i<numObjects; i++)
      {
        var sp: MovieClip = MovieClip(wrap.addChild(new MovieClip()))
        sp.graphics.beginFill(0xff - (Math.random() * 0x66) << 16 | Math.random() * 0x33 << 8 | Math.random() * 0x33)
        //sp.graphics.drawRect(-5, -50, 10, 100)
        sp.graphics.drawEllipse(-5, -70, 10, 140);
        sp.x = 100 * Math.sin( i * 360 / numObjects * Math.PI / 180)
       // sp.y = -140 + 5 * i;
        sp.z = 100 * Math.cos( i * 360 / numObjects * Math.PI / 180)
        sp.i = i*10;
        
        objs.push(sp)
      }
      
      stage.addEventListener(Event.ENTER_FRAME, function(e:Event):void
      {
        
        //data.fillRect(new Rectangle(0, 0, stage.stageWidth, stage.stageHeight), 0xffffff);
        data.draw(wrapwrap);
        data.applyFilter(data, new Rectangle(0, 0, stage.stageWidth, stage.stageHeight), new Point(), new BlurFilter(4, 4));
        var ct:ColorTransform = new ColorTransform();
        ct.redMultiplier = 1.1;
        ct.blueMultiplier = 1.2;
        ct.alphaMultiplier = 0.99;

        data.colorTransform(new Rectangle(0, 0, stage.stageWidth, stage.stageHeight), ct);

        pp.projectionCenter = new Point(stage.stageWidth / 2,
                  stage.stageHeight / 2 - 100)
        
        wrap.rotationY += (mouseX / stage.stageWidth * 480 - wrap.rotationY) * 0.05
        
        var arr:Array = []
        for (var i:int=0; i<objs.length; i++) {
          var ele:MovieClip = objs[i] as MovieClip
          ele.rotationY = -wrap.rotationY
            ele.rotationX = ele.i / numObjects * 36;
            ele.i -= 1;
            ele.rotationZ = ele.i / numObjects * 36;
            ele.y = 100 * Math.sin(ele.i / 80);
          var mtx:Matrix3D = ele.transform.getRelativeMatrix3D(main)
          arr.push( { ele:ele, z:mtx.position.z } )
        }

        arr.sortOn("z", Array.NUMERIC | Array.DESCENDING)
        var baseZ:Number = wrap.z
        for (i=0; i<arr.length; i++) {
          ele = arr[i].ele as MovieClip
          var z:Number = arr[i].z
          wrap.setChildIndex(ele, i)
          var b:Number = Math.abs(z)
          
          // focus depth blur effect, warning, very slow:
          b = z/10
          ele.filters = (b > 2) ? [new BlurFilter(b, b, 3)] : []
        }
      })
    }
  }
}