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

asahi.com花火

asahi.com花火
-----------------------------------------------------------
forked from: HelloWorldParticle & asahi.com ぱーてぃくる 
- http://wonderfl.net/code/e5b01a40e32307ccb00fc5314c50873c8b016d41
- http://wonderfl.net/code/976ff62ab9686fbb6ade389d322ed5f5bca725f7
// asahi.com花火
//-----------------------------------------------------------
// forked from: HelloWorldParticle & asahi.com ぱーてぃくる 
// - http://wonderfl.net/code/e5b01a40e32307ccb00fc5314c50873c8b016d41
// - http://wonderfl.net/code/976ff62ab9686fbb6ade389d322ed5f5bca725f7
package {
	import flash.display.*;
	import flash.events.Event;
	import flash.geom.*;
	import flash.filters.*;
	import flash.text.*;
	import flash.net.*;
	
	[SWF(backgroundColor=0x000000)]
	public class StringParticle2 extends Sprite{
        private var URL:String = "http://pipes.yahooapis.com/pipes/pipe.run?_id=cEreGvJi3BG2_zgYxQnzeQ&_render=rss&url=http%3A%2F%2Fwww.asahi.com%2F";
		private static const WIDTH:Number = 475;
		private static const HEIGHT:Number = 475;
		private static const SPEED:Number = 3;
		private static var ptZero:Point = new Point();
		private var texts:Array = [];
		
		public function StringParticle2()
		{
			stage.scaleMode = "noScale";
			stage.align = "TL";

			var req:URLRequest = new URLRequest(URL);
			var loader:URLLoader = new URLLoader();
			loader.addEventListener("complete", function(event:Event):void{
	            for each (var x:XML in XML(loader.data)..item){
	            	texts.push(x.title.text().toString());
	            }
				start();
			});
			loader.load(req);
		}
		
		private function start():void{
			var filter1:BitmapFilter = new ColorMatrixFilter([
				.98, 0, 0, 0, 0, 
				0, .95, 0, 0, 0, 
				0, 0, .95, 0, 0,
				0, 0, 0, 1, 0]);
			var filter2:BitmapFilter = new BlurFilter(3, 3);

			var index:int = 0;
			var bmd:BitmapData = createBitmapData(texts[index++]);
			var particles:Array = initParticles(bmd);

			var canvas:BitmapData = new BitmapData(WIDTH, HEIGHT, false, 0x000000);
			addChild(new Bitmap(canvas));

			addEventListener("enterFrame", function(event:Event):void{
				if (Math.random() < .01 && particles.length < 30000){
					var bmd:BitmapData = createBitmapData(texts[index]);
					particles = particles.concat(initParticles(bmd));
					index = (index + 1) % texts.length;
				}

				canvas.lock();
				canvas.applyFilter(canvas, canvas.rect, ptZero, filter1);
				canvas.applyFilter(canvas, canvas.rect, ptZero, filter2);

				for (var i:int = particles.length - 1; i > 0; i--){
					var p:Particle = particles[i];
					if(p.counter > 0){
						p.counter--;
					}else{
						p.x += p.vx;
						p.y += p.vy;
						p.vy += .01 * SPEED;
						p.vx -= p.vx * .001 * SPEED;
						p.vy -= p.vy * .001 * SPEED;
						if(p.x < 0 || p.x > WIDTH || p.y < 0 || p.y > HEIGHT){
							particles.splice(i, 1);
						}
					}
					canvas.setPixel(p.x, p.y, p.c);
				}

				canvas.unlock();
			});
		}

		private static function createBitmapData(letters:String):BitmapData{
			var fmt:TextFormat = new TextFormat();
			fmt.size = 20 + Math.random() * 40;

			var tf:TextField = new TextField();
			tf.defaultTextFormat = fmt;
			tf.width = WIDTH * (.5 + Math.random() * .3);
			tf.height = HEIGHT;
			tf.wordWrap = true;
			tf.multiline = true;
			tf.textColor = Math.random() * 0x808080 + 0x808080;
			tf.text = letters;

			var bmd:BitmapData = new BitmapData(WIDTH, HEIGHT, true, 0x000000);
			var mtx:Matrix = new Matrix();
			mtx.translate((WIDTH - tf.textWidth) * Math.random(), (HEIGHT - tf.textHeight) * Math.random());
			bmd.draw(tf, mtx);
			bmd.applyFilter(bmd, bmd.rect, ptZero, new GlowFilter(0xffffff, 1, 2, 2));

			return bmd;
		}

		private static function initParticles(bmd:BitmapData):Array{
			var particles:Array = [];
			for (var yy:int = 0; yy < bmd.height; yy++){
				for (var xx:int = 0; xx < bmd.width; xx++){
					var c:uint = bmd.getPixel(xx, yy);
					if (c != 0){
						var p:Particle = new Particle();
						p.x = xx; p.y = yy; p.c = c;
						var theta:Number = Math.random() * SPEED * Math.PI;
						var f:Number = Math.random() * 1 * SPEED;
						p.vx = Math.cos(theta) * f;
						p.vy = Math.sin(theta) * f * .7;
						p.counter = 50;
						particles.push(p);
					}
				}
			}
			return particles;
		}
	}
}

class Particle{
	public var x:Number;
	public var y:Number;
	public var vx:Number;
	public var vy:Number;
	public var c:int;
	public var counter:int;
	
	public function Particle(){
		x = 0;
		y = 0;
		c = 0;
	}
}