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

forked from: 雨が降って波紋が広がる

クリック位置に雨が降って波紋が広がります
* forkと言うより大幅な修正
// forked from Kay's 雨が降って波紋が広がる
// forked from Kay's 水滴のようなフィルタ効果
/*
 * クリック位置に雨が降って波紋が広がります
 * forkと言うより大幅な修正
 */

package {
	
	import flash.display.Sprite;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BitmapDataChannel;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	import flash.geom.Point;
	import flash.filters.DisplacementMapFilter;
	import flash.filters.DisplacementMapFilterMode;
	import flash.filters.BlurFilter;
	
    [SWF(width=350, height=350, backgroundColor=0x000000, frameRate=24)]

	public class Take03 extends Sprite {
		
		private const SW:Number = stage.stageWidth;
		private const SH:Number = stage.stageHeight;
		private var map:BitmapData;
		private var backGround:Sprite;
		private var mapStage:Sprite = new Sprite();
		private var realStage:Sprite = new Sprite();
		private var xyFilter:DisplacementMapFilter = new DisplacementMapFilter();

		function Take03():void {
			
			// 背景を描画
			var patternA:BitmapData = new BitmapData(20,20,false,0x005544);
			patternA.fillRect(new Rectangle(4,4,12,12),0x003322);
			backGround = new Sprite();
			backGround.graphics.beginBitmapFill(patternA);
			backGround.graphics.drawRect(0, 0, SW, SH/2);
			backGround.graphics.endFill();
			var patternB:BitmapData = new BitmapData(20,8,false,0x666699);
			patternB.fillRect(new Rectangle(0,0,20,4),0x111144);
			backGround.graphics.beginBitmapFill(patternB);
			backGround.graphics.drawRect(0, SH/2, SW, SH/2);
			backGround.graphics.endFill();
			addChild(backGround);

			// 実体(ノックダウンしてフィルタをかける)
			addChild(realStage);

			// マップを作る
			map = new BitmapData(SW,SH,false,0x7f7f7f);
		
			xyFilter.mapBitmap=map;
			xyFilter.mapPoint=new Point(0,0);
			//xyFilter.componentX=BitmapDataChannel.RED;
			xyFilter.componentY=BitmapDataChannel.RED;
			//xyFilter.scaleX = 30;
			xyFilter.scaleY = 30;
			xyFilter.mode=DisplacementMapFilterMode.CLAMP;

			stage.addEventListener(MouseEvent.CLICK, dropSet);
			stage.addEventListener(Event.ENTER_FRAME, render);
		}
		private function render(e:Event):void {
			map.fillRect(map.rect,0x7f7f7f);
			map.draw(mapStage);
			backGround.filters=[xyFilter];
		}
		// 水滴を発生させる
		// 実体とマップ用と二つずつ描く
		private function dropSet(e:MouseEvent):void {
			var drop:Drop = new Drop(mouseX,"real");
			var xyDrop:Drop = new Drop(mouseX,"map");
			drop.z = mouseY-SH/2;
			xyDrop.z = mouseY-SH/2;
			// 時差を防ぐために描いてからaddChild
			mapStage.addChild(xyDrop);
			realStage.addChild(drop);
		}
	}
}

// 水滴のスプライト
import flash.display.Sprite;
import flash.display.Shape;
import flash.events.Event;
import flash.filters.BlurFilter;
import flash.filters.BevelFilter;
class Drop extends Sprite {
	private var isDrop:Boolean = true;
	private var isRipple:Boolean = false;
	private var speed:Number = 20;
	private var botomY:Number = 250;
	private var nX:Number;
	private var _drop:Shape;
	private var _ripple:Shape;
	public function Drop(x:Number, type:String):void {
		var fBevelD:BevelFilter = new BevelFilter();
		fBevelD.knockout = true;
		fBevelD.blurX = fBevelD.blurY = 4;
		fBevelD.highlightColor = 0xffffff;
		fBevelD.shadowColor = 0x003366;
		fBevelD.angle = 90;
		var fBevelR:BevelFilter = new BevelFilter();
		fBevelR.knockout = true;
		fBevelR.blurX = fBevelD.blurY = 2;
		fBevelR.highlightColor = 0xffffff;
		fBevelR.shadowColor = 0x003366;
		fBevelR.angle = 45;
		fBevelR.strength = 8;
		fBevelR.distance = 10;
		
		nX = x;
		_drop = new Shape();
		_drop.graphics.beginFill(0xffffff);
		_drop.graphics.drawCircle(0, 0, 10);
		_drop.graphics.endFill();
		if (type == "real") {
			_drop.filters = [fBevelD];
		}
		_drop.x = x;
		_drop.y = -200;
		addChild(_drop);
		_ripple = new Shape();
		_ripple.graphics.lineStyle( 8, 0xffffff);
		_ripple.graphics.drawCircle(0, 0, 56);
		_ripple.graphics.lineStyle( 6, 0xffffff);
		_ripple.graphics.drawCircle(0, 0, 56*0.6);
		_ripple.graphics.lineStyle( 4, 0xffffff);
		_ripple.graphics.drawCircle(0, 0, 56*0.3);
		if (type == "real") {
			_ripple.filters = [fBevelR];
		} else {
			_ripple.filters = [new BlurFilter(2,2)];
		}
		_ripple.x = nX;
		_ripple.y = botomY;
		addEventListener(Event.ENTER_FRAME, fall);
	}
	public function fall(e:Event):void {
		if (isDrop == true) {
			_drop.y += speed;
			if (isDrop == true && _drop.y > botomY || (speed < 0 && _drop.y < botomY)) {
				speed *= -0.9;
				if (isRipple == false) {
					addChild(_ripple);
					_ripple.rotationX = -70;
				}
				if (Math.abs(speed) < 1) {
					speed = 0;
					isDrop = false;
				}
				_drop.alpha -= 0.15;
			}
		}
		if (numChildren == 2) {
			_ripple.scaleX += 0.07; 
			_ripple.scaleY += 0.07;
			_ripple.alpha  -= 0.08;
			if (_ripple.alpha < 0) {
				removeEventListener(Event.ENTER_FRAME, fall);
				parent.removeChild(this);
			}
		}
	}
}