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

wwddd fork of: Spriteを球状に配置するだけ

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

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

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

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

	public class SpriteSphere extends Sprite
	{
		private var container:Sprite;
		private var planeN:Number;
		private const planeW:Number=60;
		private const planeH:Number=60;
		private const radius:Number=150;


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

			planeN=0;
			var H:int=(2 * radius * Math.PI) / 2 / planeH;
			var theta1:Number=0;
			var theta2:Number=90;

			for(var i:int=0; i < H; i++)
			{
				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(/*Math.random()* */ 0x0000ff, .6);
					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.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:int=array[i].z /14;
                                
                                //sp.filters=(b > 2) ? [new BlurFilter(b, b, 2)] : [];
                                sp.filters=[new GlowFilter(0xFF0000, 1, 0, 0, array[i].z , 1, 1,0)];
                        }
                } 
        }

}