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: Spriteを球状に配置するだけ

Spriteを球状に配置しただけです。
Z-sortはclockmakerさんのものを利用させてもらってます(http://wonderfl.kayac.com/code/32ddf17fbf8581122c192435d1cccc870d10b375)。
/**
 * Copyright attunedesigns ( http://wonderfl.net/user/attunedesigns )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/f4nV
 */

// forked from sake's Spriteを球状に配置するだけ
/*
   Spriteを球状に配置しただけです。
   Z-sortはclockmakerさんのものを利用させてもらってます(http://wonderfl.kayac.com/code/32ddf17fbf8581122c192435d1cccc870d10b375)。
*/

package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.BlurFilter;
	import flash.geom.Matrix3D;

	[SWF(width="465", height="465", backgroundColor="0xFFFFFF", frameRate="40")]

	public class SpriteSphere extends Sprite
	{
		private var container:Sprite;
		private var planeN:Number;
		private const planeW:Number=40; //ellipse w
		private const planeH:Number=40; //ellipse h
		private const radius:Number=150;


		public function SpriteSphere()
		{
                        inittrace(this.stage);
			container=new Sprite();
			container.x=465 / 2;
			container.y=465 / 2;
			addChild(container);

                        planeN=0; //ellipse id
			var H:int=(2 * radius * Math.PI) / 2 / planeH; //circumference/2/ellipse diameter
			var theta1:Number;
			var theta2:Number=90;
                         
			for(var i:int=0; i < H; i++)
			{
				theta1=0;
				var pn:int=Math.floor((2 * radius * Math.cos(theta2 * Math.PI / 180) * Math.PI) / planeW);
				for(var j:int=0; j < pn; j++)
				{
					var sp:Sprite=new Sprite;
                                        sp.graphics.beginFill(100<<16 | j/pn*255<<8 | 80, .9);
					sp.graphics.drawEllipse(-planeW / 2, -planeH / 2, planeW, planeH);
					sp.graphics.endFill();
					sp.rotationX=-theta2;
					sp.rotationY=theta1;
					sp.x=radius * Math.cos(theta2 * Math.PI / 180) * Math.sin(theta1 * Math.PI / 180);
					sp.y=radius * Math.sin(theta2 * Math.PI / 180);
					sp.z=radius * Math.cos(theta2 * Math.PI / 180) * Math.cos(theta1 * Math.PI / 180);
					theta1+=360 / pn;
					sp.name="sp" + planeN.toString();
					container.addChild(sp);
					planeN++;
				}
				theta2-=180 / H;
			}
			addEventListener(Event.ENTER_FRAME, onFrame);
		}

		private function onFrame(e:Event):void
		{
			container.rotationZ++;
                        container.rotationY++;
                        
			var array:Array=[];

			for(var i:int=0; i < planeN; i++)
			{
				var sp:Sprite=container.getChildByName("sp" + i.toString())as Sprite;
				var mat:Matrix3D=sp.transform.getRelativeMatrix3D(this);
				array.push({sp:sp, z:mat.position.z});
			}

			array.sortOn("z", Array.NUMERIC | Array.DESCENDING);

			for(var i:int=0; i < planeN; i++)
			{
				var sp:Sprite=array[i].sp as Sprite;
				container.setChildIndex(sp, i);

				var b:Number=(array[i].z as Number) / 14;
				sp.filters=(b > 4) ? [new BlurFilter(b, b, 3)] : [];
			}
		}
	}
}
/////  WONDERFL TRACE /////
import flash.display.Sprite;
import flash.display.Stage;
import flash.text.TextField;
import flash.text.TextFormat;
function inittrace(s:Stage):void
{
    WTrace.initTrace(s);
}
//global trace function
var trace:Function;
//wtreace class
class WTrace
{
        private static var FONT:String = "Fixedsys";
        private static var SIZE:Number = 12;
        private static var TextFields:Array = [];
        private static var trace_stage:Stage;
        
        public static function initTrace(stg:Stage):void
        {
            trace_stage = stg;
            trace = wtrace;
        }
        
        private static function scrollup():void
        {
            // maximum number of lines: 100
            if (TextFields.length > 100) 
            {
                var removeme:TextField = TextFields.shift();
                trace_stage.removeChild(removeme);
                removeme = null;
            }
            for(var x:Number=0;x<TextFields.length;x++)
            {
                (TextFields[x] as TextField).y -= SIZE*1.2;
            }
        }
    
        public static function wtrace(... args):void
        {
        
            var s:String="";
            var tracefield:TextField;
            
            for (var i:int;i < args.length;i++)
            {
                // imitating flash:
                // putting a space between the parameters
                if (i != 0) s+=" ";
                s+=args[i].toString();
            }
            
            tracefield= new TextField();
            tracefield.autoSize = "left";
            tracefield.text = s;
            tracefield.y = trace_stage.stageHeight - 20;
            var tf:TextFormat = new TextFormat(FONT, SIZE);
            tracefield.setTextFormat(tf);
            trace_stage.addChild(tracefield);
            scrollup();                      
            TextFields.push(tracefield);
            
        }
}