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

Merry Christmas! Mr.wonderfl.

Merry Christamas
@author Hiiragi.

クリスマスイブは、これのためにActionScriptとイチャイチャ(?)してました。
一部のパートに反応してネオンが光るようになってます。音鳴らしてないけど。
本当はネオンをキラキラさせたかったんだけど、うまくいかなかった・・・。
独り者のあなたにも、彼女もちのリア充のあなたにも、そしてwonderflにも、

メリークリスマス。

BGM Arranged by Hiiragi(しょぼくてゴメンナサイ)
Get Adobe Flash player
by Hiiragi 25 Dec 2009
    Embed
package 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BlendMode;
	import flash.display.PixelSnapping;
	import flash.display.Sprite;
	import flash.display.GradientType;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.filters.BlurFilter;
	import flash.filters.GlowFilter;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.system.Security;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	import flash.text.TextFieldAutoSize;
	import flash.text.FontStyle;
	import flash.utils.Timer;
	
	import org.si.sion.SiONData;
	import org.si.sion.SiONVoice;
	import org.si.sion.utils.SiONPresetVoice;
	import org.si.sion.SiONDriver;
	import org.si.sion.events.SiONTrackEvent;
	import net.hires.debug.Stats;
	
	/**
	 * Merry Christamas
	 * @author Hiiragi.
	 * 
	 * クリスマスイブは、これのためにActionScriptとイチャイチャ(?)してました。
	 * 一部のパートに反応してネオンが光るようになってます。音鳴らしてないけど。
	 * 本当はネオンをキラキラさせたかったんだけど、うまくいかなかった・・・。
	 * 独り者のあなたにも、彼女もちのリア充のあなたにも、そしてwonderflにも、
	 * 
	 * メリークリスマス。
	 * 
	 * BGM Arranged by Hiiragi(しょぼくてゴメンナサイ)
	 */
	[SWF(width=465,height=465,frameRate=30,backgroundColor=0)]
	public class Main extends Sprite 
	{
		
		private var _rect:Rectangle;
		private var _colorTransform:ColorTransform;
		private var SW:int;
		private var SH:int;
		
		//backGround
		private var _backSp:Sprite;
		
		//star
		private var _starBmpd:BitmapData;
		private var _starBmp:Bitmap;
		private var _starNum:int = 100;
		
		//snow
		private var _snowNum:int = 100;
		private var _snowVector:Vector.<snowSprite>;
		private var _windSpeed:Number = 20;
		private var _gravity:Number = 5;
		
		//NeonText
		private const NEON_TEXT:String = "Merry\nChristmas!\nMr.wonderfl.";
		private var _tField:TextField;
		private var _tFormat:TextFormat;
		private var _txtRect:Rectangle;
		private var _neonPixelArray:Vector.<Vector.<Object>>;
		
		//TextBitmap,NeonTextBitmap
		private var _txtBmpd:BitmapData;
		private var _neonBmpd:BitmapData;
		private var _neonBmp:Bitmap;
		private var _neonEffectBmpd:BitmapData;
		private var _neonEffectBmp:Bitmap;
		private var _mtx:Matrix;
		
		//Utils
		private var _urlLoader:URLLoader;
		private var _sionDriver:SiONDriver;
		private var _sionVoice:SiONVoice;
		private var _sionPresetVoice:SiONPresetVoice;
		private var _sionData:SiONData;
		
		//Timer
		private var _timerForSnow:Timer;
		private var _timerForNeon:Timer;
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			
			//Setting
			SW = this.stage.stageWidth;
			SH = this.stage.stageHeight;
			_rect = new Rectangle(0, 0, SW, SH);
			_colorTransform = new ColorTransform(0.99, 0.99, 0.99, 0.99);
			
			//BackGround
			_backSp = new Sprite();
			var mtx:Matrix = new Matrix();
			mtx.createGradientBox(SW, SH, Math.PI / 2);
			_backSp.graphics.beginGradientFill(GradientType.LINEAR, [0x000000, 0x000033], [1, 1], [0, 255], mtx);
			_backSp.graphics.drawRect(0, 0, SW, SH);
			_backSp.graphics.endFill();
			this.addChild(_backSp);
			
			//Star
			_starBmpd = new BitmapData(SW, SH, true, 0);
			for (var i:int = 0; i < _starNum; i++)
			{
				_starBmpd.setPixel32(Math.random() * SW >> 0, Math.random() * SH >> 0, Math.random() * 0xFF << 24 | 0xFFFFCC);
			}
			_starBmp = new Bitmap(_starBmpd);
			_starBmp.filters = [new BlurFilter(1.2, 1.2, 2)];
			this.addChild(_starBmp);
			
			//TextSetting
			_tField = new TextField();
			_tField.autoSize = TextFieldAutoSize.LEFT;
			_tField.text = NEON_TEXT;
			_tFormat = new TextFormat();
			_tFormat.align = TextFormatAlign.CENTER;
			_tFormat.bold = FontStyle.BOLD;
			_tFormat.color = 0xFFFFFF;
			_tFormat.size = 75;
			_tField.setTextFormat(_tFormat);
			_txtRect = new Rectangle(	SW / 2 - _tField.width / 2, 
										SH / 2 - _tField.height / 2,
										_tField.width,
										_tField.height);
			//this.addChild(_tField);	//debug
			
			_txtBmpd = new BitmapData(_tField.width, _tField.height, true, 0);
			_txtBmpd.draw(_tField);
			//this.addChild(new Bitmap(_txtBmpd));	//debug
			
			//NeonSetting
			_neonBmpd = new BitmapData(SW, SH, true, 0);
			_neonBmp = new Bitmap(_neonBmpd);
			_neonBmp.filters = [new BlurFilter(2,2,1), new GlowFilter(0xFFFFFF, .5, 10 ,10, 2)];
			this.addChild(_neonBmp);
			
			_mtx = new Matrix(.25, 0, 0, .25);
			_neonEffectBmpd = new BitmapData(SW / 4, SH / 4, false, 0);
			_neonEffectBmp = new Bitmap(_neonBmpd, PixelSnapping.NEVER, true);
			_neonEffectBmp.blendMode = BlendMode.LIGHTEN;
			_neonEffectBmp.scaleX = _neonEffectBmp.scaleY = 4;
			this.addChild(_neonEffectBmp);
			
			//Stats(StatusDisplay)
			this.addChild(new Stats());
			
			//MMLTextLoad
			Security.loadPolicyFile("http://melancholy.raindrop.jp/crossdomain.xml");
			_urlLoader = new URLLoader();
			_urlLoader.addEventListener(Event.COMPLETE, txtLoadComplete);
			//_urlLoader.load(new URLRequest("testMML.txt"));
			_urlLoader.load(new URLRequest("http://melancholy.raindrop.jp/flash/jinglebell_mml.txt"));
		}
		
		private function txtLoadComplete(e:Event):void 
		{
			_sionDriver = new SiONDriver();
			_sionDriver.addEventListener(SiONTrackEvent.NOTE_ON_FRAME, SiONNoteEventHandler);
			_sionData = _sionDriver.compile(e.target.data);
			_sionPresetVoice = new SiONPresetVoice();
			_sionVoice = _sionPresetVoice["midi.percus1"];
			_sionData.setVoice(0, _sionVoice);
			
			_timerForNeon = new Timer(33);
			_timerForNeon.addEventListener(TimerEvent.TIMER, neonUpdate);
			
			_timerForSnow = new Timer(33);
			_timerForSnow.addEventListener(TimerEvent.TIMER, snowUpdate);
			
			neonCreate();
			snowCreate();
			
			//start
			_sionDriver.play(_sionData);
			_timerForNeon.start();
			_timerForSnow.start();
		}
		
		private function neonCreate():void
		{
			_neonPixelArray = new Vector.<Vector.<Object>>;
			
			for (var y:int = 0; y < _txtRect.height; y++)
			{
				_neonPixelArray[y] = new Vector.<Object>;
				for (var x:int = 0; x < _txtRect.width; x++)
				{
					if (_txtBmpd.getPixel(x, y) == 0xFFFFFF)
					{
						var tx:int = x + _txtRect.x;
						var ty:int = y + _txtRect.y;
						_neonPixelArray[y][x] = { x:tx, y:ty };
					}
					else
					{
						_neonPixelArray[y][x] = { x:-1, y:-1 };
					}
				}
			}
		}
		
		private function snowCreate():void
		{
			_snowVector = new Vector.<snowSprite>;
			
			var snow:snowSprite;
			for (var i:int = 0; i < _snowNum; i++)
			{
				snow = new snowSprite();
				snowInit(snow);
				this.addChild(snow);
				_snowVector[i] = snow;
			}
			_firstFlag = false;
		}
		
		private var _firstFlag:Boolean = true;
		private function snowInit(snow:snowSprite):void
		{
			snow.x = SW * Math.random();
			snow.y = (_firstFlag) ? -SH * Math.random() : 0;
			snow.init(_windSpeed * Math.random(), _gravity * (Math.random() * .8 + .2));
		}
		
		
		
		private function snowUpdate(e:TimerEvent):void 
		{
			var len:int = _snowVector.length;
			var snow:snowSprite;
			for (var i:int = 0; i < len; i++)
			{
				snow = _snowVector[i];
				snow.x += (snow.vx * Math.sin(snow.incrementer)) * .5;
				snow.y += snow.vy;
				snow.incrementer += .01;
				if (snow.y > SH)
				{
					snowInit(snow);
				}
			}
		}
		
		private var colorArray:Array = [0xFFFF0000, 0xFF00FF00, 0xFFFFFFFF];
		private var _neonTimerNowCnt:int = 10;	//一回目は即時表示させるためにMaxと同じにしておく
		private var _neonTimerMaxCnt:int = 10;
		
		private function neonUpdate(e:TimerEvent):void 
		{

			
			_neonBmpd.lock();
			_neonEffectBmpd.lock();
			_neonBmpd.colorTransform(_rect, _colorTransform);

			_neonEffectBmpd.unlock();
			_neonBmpd.unlock();
		}
		
		private function SiONNoteEventHandler(e:SiONTrackEvent):void 
		{
			_neonBmpd.lock();
			
			
			var xLen:int = _txtRect.width;
			var yLen:int = _txtRect.height;
			
			for (var y:int = 0; y < yLen; y++)
			{
				for (var x:int = 0; x < xLen; x++)
				{
					var obj:Object = _neonPixelArray[y][x];
					
					if (obj.x > -1 && Math.random() > 0.7)
					{
						_neonBmpd.setPixel32(obj.x, obj.y, colorArray[Math.random() * colorArray.length >> 0] | 0xFF >> 24);
					}
				}
			}
			
			_neonBmpd.colorTransform(_rect, new ColorTransform(2, 2, 2, 1));
			_neonEffectBmpd.draw(_neonBmpd, _mtx);
			_neonTimerNowCnt = 0;

			_neonBmpd.unlock();
		}
	}
	
}

import flash.display.Graphics;
import flash.display.Sprite;
import flash.filters.BlurFilter;

class snowSprite extends Sprite
{
	
	private var _vx:Number;
	private var _vy:Number;
	private var _incrementer:Number;
	
	public function snowSprite()
	{
		this.filters = [new BlurFilter(5,5,2)];
	}
	
	public function init(vx:int, vy:int):void
	{
		_vx = vx;
		_vy = vy;
		
		_incrementer = Math.random() * 3.14;
		
		var g:Graphics = this.graphics;
		g.clear();
		g.beginFill(0xFFFFFF, .9);
		g.drawCircle(0, 0, 3);
		g.endFill();
	}
	
	public function get vx():Number { return _vx; }
	
	public function set vx(value:Number):void 
	{
		_vx = value;
	}
	
	public function get vy():Number { return _vy; }
	
	public function set vy(value:Number):void 
	{
		_vy = value;
	}
	
	public function get incrementer():Number { return _incrementer; }
	
	public function set incrementer(value:Number):void 
	{
		_incrementer = value;
	}
	
}