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

Fontana

HANABIをとても参考にさせていただきました。
噴水に見えるだろうか……。
Get Adobe Flash player
by syunki 19 Aug 2009
    Embed
/**
 * Copyright syunki ( http://wonderfl.net/user/syunki )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/dtpD
 */

//        HANABIをとても参考にさせていただきました。
//        噴水に見えるだろうか……。

package 
{
	import flash.display.*;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.filters.BlurFilter;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	import flash.utils.Timer;
	
	[SWF(width="300", height="300", backgroundColor="0x000000", framerate="30")]
	public class Fontana extends Sprite 
	{
		private const WIDTH:Number = 300;
		private const HEIGH:Number = 300;
		
		private var _canvasb:BitmapData;
		private var _canvasf:BitmapData;
		private var _bpoint:Array;
		private var _rect:Rectangle;
		private var cTra:ColorTransform;
		private var button:CustomSimpleButton;
		private var title:TextField;
		private var timer:Timer;
		private var fontana:Boolean;
		
		public function Fontana():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			_bpoint = [];
			
			removeEventListener(Event.ADDED_TO_STAGE, init);

			_canvasf = new BitmapData(WIDTH, HEIGH, false, 0x0);
			addChild(new Bitmap(_canvasf));
			_canvasb = new BitmapData(WIDTH / 4, HEIGH / 4, false, 0x0);
			var bm:Bitmap = addChild(new Bitmap(_canvasb, PixelSnapping.NEVER, true)) as Bitmap;
			bm.scaleX = bm.scaleY = 4;
			bm.blendMode = BlendMode.ADD;
			
			_rect = new Rectangle(0, 0, WIDTH, HEIGH);
			cTra = new ColorTransform(.7, .7, .8);
			
			fontana = false;
			
			button = new CustomSimpleButton;
			button.addEventListener(MouseEvent.CLICK, mouseclickHandler);
			addChild(button);
			
			title = new TextField;
			title.width = 60;
			title.height = 20;
			title.textColor = 0xFFFFFF;
			title.x = 5;
			title.y = 10;
			title.text = "Start/Stop";
			addChild(title);
			
			this.stage.addEventListener(Event.ENTER_FRAME, enterframeHandler);
			
			timer = new Timer(10);
			timer.addEventListener(TimerEvent.TIMER, timereventHandler);
			timer.start();		
		}
		
		private function mouseclickHandler(e:MouseEvent):void {
			(fontana)? fontana = false : fontana = true;
		}
		
		private function timereventHandler(e:TimerEvent):void {
			var i:int = 10;
			while (i--) {
				(fontana)? CreateBPoint() : _bpoint.shift();
			}
		}
		
		private function CreateBPoint():void {
			var bpo:Bpoint = new Bpoint;
			bpo.x = WIDTH / 2;
			bpo.y = HEIGH - 20;
			
			bpo.vx = 2 - 4  * Math.random();
			bpo.vy = -35 + 10 *  Math.random();
			
			if (_bpoint.length > 2000) _bpoint.shift();
			_bpoint.push(bpo);
		}
		
		private function enterframeHandler(e:Event):void {
			UpDate();
		}
		
		private function UpDate():void {
			_canvasf.lock();
			_canvasf.applyFilter(_canvasf, _rect, new Point(), new BlurFilter(1, 1));
			_canvasf.colorTransform(_rect, cTra);
			
			var i:int = _bpoint.length;
			while(i--) {
				var p:Bpoint = _bpoint[i];
				p.vx *= 0.98;
				p.vy *= 0.9;
				p.vy += 0.2;
				
				p.x += p.vx;
				p.y += p.vy;

				_canvasf.setPixel32(p.x, p.y, p.c);
				if ((p.x < 0 || p.x > WIDTH) || p.y > HEIGH) {
					this._bpoint.splice(i, 1);
				}
			}
			_canvasf.unlock();
			_canvasb.draw(_canvasf, new Matrix(0.25, 0, 0, 0.25));
		}
	}
}

class Bpoint {
	public var x:Number;
	public var y:Number;
	public var vx:Number;
	public var vy:Number;
	public var c:uint;
	
	public function Bpoint() {
		x = 0;
		y = 0;
		c = 0xFFFFFFFF;
	}
}

import flash.display.DisplayObject;
import flash.display.Shape;
import flash.display.SimpleButton;

class CustomSimpleButton extends SimpleButton {
	private var upColor:uint	= 0xFFCC00;
	private var overColor:uint	= 0xCCFF00;
	private var downColor:uint	= 0x00CCFF;
	private var sx:uint		= 30;
	private var sy:uint		= 40;
	private var sr:uint		= 10;
	
	public function CustomSimpleButton() {
		downState		= new ButtonDisplayState(sx, sy, sr, downColor);
		overState		= new ButtonDisplayState(sx, sy, sr, overColor);
		upState			= new ButtonDisplayState(sx, sy, sr, upColor);
		hitTestState	= new ButtonDisplayState(sx, sy, sr, upColor);
		useHandCursor 	= true;
	}
}

class ButtonDisplayState extends Shape {
	private var bgColor:uint;
	private var sx:uint;
	private var sy:uint;
	private var sr:uint;
	
	public function ButtonDisplayState(sx:uint, sy:uint, sr:uint, bgColor:uint) {
		this.bgColor = bgColor;
		this.sx = sx;
		this.sy = sy;
		this.sr = sr;
		draw();
	}
	
	private function draw():void {
		graphics.beginFill(bgColor);
		graphics.drawCircle(sx, sy, sr);
		graphics.endFill();
	}
}