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

燃えながら出てくる文字(修正版)

package {
	import __AS3__.vec.Vector;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BlendMode;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.geom.Matrix;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.utils.Timer;
	
	[SWF(backgroundColor=0x000000, frameRate=30)]

	public class String_Particle2 extends Sprite
	{
		//パーティクルを描写するBitmapData
		public var canvas:BitmapData;
		
		private var fire_canvas:BitmapData;
		
		//テキストを描画するBitmapData
		public var textCanvas:BitmapData;
		
		//パーティクルクラスのインスタンスを格納する配列
		private var particles:Vector.<Particle>;
		
		private var circle_particles:Vector.<Circle_Particle>;
		
		private var timer:Timer;
		
		private const GRAVITY:Number = 0.1;
		
		private var count:int = 0;
		
		private var w:Number;
		private var h:Number;
		private var str:String;
		private var fontSize:uint;
		
		public function String_Particle2(str:String="Every day is Carnival", fontSize:uint=40, w:Number=400, h:Number=100)
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			this.w = w;
			this.h = h;
			this.str = str;
			this.fontSize = fontSize;
			
			
			canvas = new BitmapData(w, h, false, 0x000000);
			var bmp:Bitmap = new Bitmap(canvas);
			bmp.x = stage.stageWidth / 2 - bmp.width / 2;
			bmp.y = stage.stageHeight / 2 - bmp.height / 2;
			addChild(bmp);
			fire_canvas = new BitmapData(w, h, true);
			var f_bmp:Bitmap = new Bitmap(fire_canvas);
			f_bmp.x = stage.stageWidth / 2 - f_bmp.width / 2;
			f_bmp.y = stage.stageHeight / 2 - f_bmp.height / 2;
			addChild(f_bmp);
			
			start();	
		}
		
		public function start():void{
			init(str, fontSize);
			
			circle_particles = new Vector.<Circle_Particle>;
			
			timer = new Timer(33);
			timer.addEventListener(TimerEvent.TIMER, loop);
			timer.start();
			
			addEventListener(Event.ENTER_FRAME, effect_loop);
		}
		
		private function init(str:String, size:uint):void{
			var tf:TextField = new TextField;
			tf.defaultTextFormat = new TextFormat("Swis721 BdRndBT", size, 0xFFFFFF );
			tf.autoSize = TextFieldAutoSize.LEFT;
			tf.text = str;
			
			//文字の描画
			textCanvas = new BitmapData(tf.textWidth+10, tf.textHeight, false, 0x000000);
			textCanvas.draw(tf);
			particles = new Vector.<Particle>;
			
			createText();
		}
		
		//文字からパーティクルの生成
		private function createText():void{
			//ステージを中心にテキストを配置するときの左上座標
			var ofx:Number = w / 2 - textCanvas.width / 2;
			var ofy:Number = h / 2 - textCanvas.height / 2;
			
			//textCanvasを1pxずつ見ていく
			for(var ex:uint = 0; ex < textCanvas.width; ex++){
				for(var ey:uint = 0; ey < textCanvas.height; ey++){
					//textCanvasの座標(ex, ey)のRGB値の取得
					var c:uint = textCanvas.getPixel(ex, ey);
					if(c != 0x000000){
						var p:Particle = new Particle();
						p.x = ex;
						p.y = ey;
						p.c = c;
						particles.push(p);
					}
				}
			}
		}
		
		private function loop(event:TimerEvent):void{
			//キャンパスをロック
			canvas.lock();
			
			var cp:Circle_Particle;
			
			//パーティクルを描画
			for(var i:int = 0; i < 15; i++){
				if(particles.length  <= count){
					timer.removeEventListener(TimerEvent.TIMER, loop);
					break;
				}

				canvas.setPixel(particles[count].x, particles[count].y, particles[count].c);
                               if(count % 3 < 2){
		             		cp = new Circle_Particle(particles[count].x, particles[count].y, Math.random()*4-2, -Math.random()*5+1.5, Math.random()*2+1, Math.random()*0x00FFFF+ 0xFF0000);
				        circle_particles.push(cp);
                                }
				count++;
			}
			
			
			//ロック解除
			canvas.unlock();
			
		}
		
		 private function func(item:Circle_Particle, index:int, vec:Vector.<Circle_Particle>):Boolean{
        	if(item.alpha <= 0){
        		return false;
        	}
        	else 
        		return true;
		}

		private function effect_loop(event:Event):void{
			fire_canvas.fillRect(fire_canvas.rect, 0x000000);
			circle_particles = circle_particles.filter(func);
			var mtx:Matrix;
			for each(var p:Circle_Particle in circle_particles){
				p.x  += p.vx;
    	    	p.y += p.vy;
        		p.vy += -GRAVITY;
        		p.alpha -= 0.1;
        		mtx = new Matrix();
	            mtx.translate(p.x, p.y);
        		fire_canvas.draw(p, mtx, null, BlendMode.ADD);
   			}
		}
	}
}


import flash.display.Shape;
import flash.display.BlendMode;
import flash.filters.BlurFilter;
	
class Particle{
	public var x:Number;
	public var y:Number;
	public var ex:Number;
	public var ey:Number;
	public var c:int;
	
	public function Particle(){
		x = 0;
		y = 0;
		ex = 0;
		ey = 0;
		c = 0;
	}
}

class Circle_Particle extends Shape{
	public var vx:Number;
	public var vy:Number;
	public var size:Number;
	public var color:uint;
	public function Circle_Particle(x:Number=0, y:Number=0, vx:Number=0, vy:Number=0, size:Number=5, color:uint=0xFFFFFF){
		this.x = x;
		this.y = y;
		this.vx = vx;
		this.vy = vy;
		this.size = size;
		this.color = color;
		this.blendMode = BlendMode.ADD;
		this.filters = [new BlurFilter(10, 10, 1)];
		graphics.beginFill(color);
		graphics.drawCircle(0, 0, size);
		graphics.endFill();
	}
}