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

鉄の輪

Get Adobe Flash player
by cpu_t 20 Mar 2010
    Embed
/**
 * Copyright cpu_t ( http://wonderfl.net/user/cpu_t )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/dUbw
 */

package {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
    import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.ColorTransform;
	import flash.geom.Point;
    public class FlashTest extends Sprite
	{
		private var bmpdata:BitmapData;
		private var src:Array;
		private var array:Array;
        public function FlashTest()
		{
			bmpdata = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0);
			addChild(new Bitmap(bmpdata));
			
            var sp:Sprite = new Sprite();
			sp.graphics.beginFill(0xFFFFFF);
			sp.graphics.drawCircle(30, 30, 30);
			sp.graphics.drawCircle(30, 30, 25);
			sp.graphics.endFill();
			src = new Array();
			src[0] = new BitmapData(60, 60, true, 0);
			src[0].draw(sp, null, new ColorTransform(1, 0, 0));
			src[1] = new BitmapData(60, 60, true, 0);
			src[1].draw(sp, null, new ColorTransform(.6, 0, 0));
			src[2] = new BitmapData(60, 60, true, 0);
			src[2].draw(sp, null, new ColorTransform(.8, .8, .8));
			
			array = new Array();
			
			addEventListener(Event.ENTER_FRAME, onUpdate);
        }
		
		private function onUpdate(e:Event):void 
		{
			if(Math.random()<.1)
			{
				var d:Number = Math.random() * Math.PI * 2;
				array.push( {
					x:bmpdata.width * .5,
					y:bmpdata.height * .5,
					vx:Math.cos(d) * 10,
					vy:Math.sin(d) * 10,
					count:0
				});
			}
			
			bmpdata.fillRect(bmpdata.rect, 0);
			
			for (var i:Number = 0; i < array.length; i++)
			{
				var obj:Object = array[i];
				obj.x += obj.vx;
				obj.y += obj.vy;
				if (obj.x < -30)
				{
					obj.x = 30;
					obj.vx *= -1;
					obj.count++;
				}
				else if (obj.x > bmpdata.width+30)
				{
					obj.x = bmpdata.width - 30;
					obj.vx *= -1;
					obj.count++;
				}
				if (obj.y < -30)
				{
					obj.y = 30;
					obj.vy *= -1;
					obj.count++;
				}
				else if (obj.y > bmpdata.height+30)
				{
					obj.y = bmpdata.height - 30;
					obj.vy *= -1;
					obj.count++;
				}
				if (obj.count >= 3)
				{
					array.splice(i, 1);
					i--;
					continue;
				}
				else if (obj.count <= 1)
				{
					var p:Point = null;
					if (obj.x < 30)
					{
						p = new Point(-obj.x-30, obj.y - 30);
					}
					else if (obj.x > bmpdata.width - 30)
					{
						p = new Point(bmpdata.width*2-obj.x-30, obj.y - 30);
					}
					if (p != null)
						bmpdata.copyPixels(src[obj.count+1], src[obj.count+1].rect, p);
					
					p = null;
					if (obj.y < 30)
					{
						p = new Point(obj.x - 30, -obj.y - 30);
					}
					else if (obj.y > bmpdata.height-30)
					{
						p = new Point(obj.x - 30, bmpdata.height*2-obj.y - 30);
					}
					if (p != null)
						bmpdata.copyPixels(src[obj.count+1], src[obj.count].rect, p);
				}
				bmpdata.copyPixels(src[obj.count], src[obj.count].rect, new Point(obj.x - 30, obj.y - 30));
			}
			//bmpdata.copyPixels(src, src.rect, new Point());
		}
		
    }
}