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

マルチタッチすきま妖怪

For Flash Player 10.1
For Multitouch Device

スキマを作って くぱぁ

参考 :Adobe Labs - Adobe AIR 2 Beta 2 Sample Applications
labs.adobe.com/technologies/air2/samples/
@author Shinichiro Sugimoto
Get Adobe Flash player
by moyashipan 15 Feb 2010
/**
 * Copyright moyashipan ( http://wonderfl.net/user/moyashipan )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/oemV
 */

package 
{
	import caurina.transitions.Equations;
	import caurina.transitions.Tweener;
	import flash.display.Sprite;
	import flash.events.TouchEvent;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.ui.Multitouch;
	import flash.ui.MultitouchInputMode;
	import flash.utils.Dictionary;
	import flash.ui.Mouse;
	
	/**
	* For Flash Player 10.1
	* For Multitouch Device
	* 
	* スキマを作って くぱぁ
	*
	* 参考 :Adobe Labs - Adobe AIR 2 Beta 2 Sample Applications
	* labs.adobe.com/technologies/air2/samples/
	* @author Shinichiro Sugimoto
	*/
	public class Main extends Sprite 
	{
		private var _downQueue:Vector.<int> = new Vector.<int>;
		private var tPointList:Dictionary = new Dictionary();
		private var lastSlit:Slit;
		
		public function Main():void 
		{
			Mouse.hide();
			
			Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
			
			stage.addEventListener(TouchEvent.TOUCH_BEGIN, tStart, false, 0, true);
		}
		
		private function tStart(e:TouchEvent):void 
		{
			if (e.target != e.currentTarget) return;
			
			if (tPointList[e.touchPointID] == null) {
				stage.addEventListener(TouchEvent.TOUCH_MOVE, tMove, false, 0, true);
				stage.addEventListener(TouchEvent.TOUCH_END, tEnd, false, 0, true);
			}
			
			_downQueue.push(e.touchPointID);
			
			tPointList[e.touchPointID] = new Point(e.stageX, e.stageY);
		}
		
		private function tMove(e:TouchEvent):void 
		{
			tPointList[e.touchPointID] = new Point(e.stageX, e.stageY);
			
			if (_downQueue.length >= 2) {
				this.graphics.clear();
				this.graphics.lineStyle(4, 0, 0.2);
				this.graphics.moveTo(p0.x, p0.y);
				this.graphics.lineTo(p1.x, p1.y);
			}else {
				this.graphics.clear();
			}
		}
		
		private function tEnd(e:TouchEvent):void 
		{
			if (_downQueue.length == 2) {
				createSlit(p0, p1);
			}else {
				this.graphics.clear();
			}
			
			tPointList[e.touchPointID] = null;
			var i:int = _downQueue.indexOf(e.touchPointID);
			if (i < 0) return;
			_downQueue.splice(i, 1);
			
		}
		
		private function createSlit(p0:Point, p1:Point):void
		{
			var len:Number = Point.distance(p0, p1);
			// 指が近すぎると誤認識するのでその対策
			if (len < 200) return;
			if (lastSlit != null) {
				lastSlit.close();
			}
			lastSlit = new Slit(p0, p1);
			
			this.addChild(lastSlit);
		}
		
		public function get p0():Point { return tPointList[_downQueue[0]]; }
		public function get p1():Point { return tPointList[_downQueue[1]]; }
		
	}
}

import caurina.transitions.Tweener;
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.TouchEvent;
import flash.filters.BlurFilter;
import flash.filters.GlowFilter;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.utils.Dictionary;

//スキマ
class Slit extends Sprite
{
	// くぱぁ可能領域(線)の太さ
	private static const kuparableThickness:uint = 96;
	
	private var p0:Point;
	private var p1:Point;
	private var g:Graphics;
	
	private var _downQueue:Vector.<int> = new Vector.<int>;
	private var tPointList:Dictionary = new Dictionary();

	private var controlPoint0:Point;
	private var controlPoint1:Point;
	private var anchorPoint0:Point;
	private var anchorPoint1:Point;
	
	private var middlePoint:Point;
	private var distPoint:Point;
	private var len:Number;
	private var texture:BitmapData;
	
	public function Slit(p0:Point, p1:Point) 
	{
		super();
		
		this.p0 = p0;
		this.p1 = p1;
		
		g = graphics;
		
		middlePoint = Point.interpolate(p0, p1, .5);
		distPoint = p1.subtract(p0);
		len = distPoint.length;
		var normalVec:Point = Point.polar(1, Math.atan2(distPoint.x, distPoint.y));
		normalVec.x *= len * 0.02;
		normalVec.y *= len * 0.02;
		
		controlPoint0 = middlePoint.add(normalVec);
		controlPoint1 = middlePoint.subtract(normalVec);
		
		anchorPoint0 = controlPoint0.clone();
		anchorPoint1 = controlPoint1.clone();
		
		filters = [new BlurFilter()];
		
		createTexture();
		draw();
		
		this.addEventListener(TouchEvent.TOUCH_BEGIN, tStart, false, 0, true);
	}
	
	private function createTexture():void
	{
		texture = new BitmapData(100, 100, false, 0x300020);
		
		var eye:Sprite = new Sprite();
		var g:Graphics = eye.graphics;
		g.lineStyle();
		g.beginFill(0xffffff, 1);
		g.moveTo(40, 0);
		g.curveTo(0, 20, -40, 0);
		g.curveTo(0, -20, 40, 0);
		g.endFill();
		
		g.beginFill(0xb00000, 1);
		g.drawCircle(0, 0, 10);
		g.endFill();
		
		g.beginFill(0, 1);
		g.drawCircle(0, 0, 4);
		g.endFill();
		
		texture.draw(eye, new Matrix(1, 0, 0, 1, 40, 25));
		texture.draw(eye, new Matrix(1, 0, 0, 1, 60, 75));
		
		eye = null;
	}
	
	public function close():void {
		mouseChildren = 
		mouseEnabled = false;
		Tweener.addTween(this, {delay:6, time: 4, alpha:0, transition:"easeoutquart", onUpdate:shutEye, onComplete:function():void { this.parent.removeChild(this); } } );
	}
	
	private function shutEye():void
	{
		controlPoint0 = Point.interpolate(middlePoint, controlPoint0, 0.1);
		controlPoint1 = Point.interpolate(middlePoint, controlPoint1, 0.1);
		draw();
	}
	
	private function draw():void {
		g.clear();
		
		var kuparablePoint0:Point = getKuparablePoint(controlPoint0);
		var kuparablePoint1:Point = getKuparablePoint(controlPoint1);
		
		g.lineStyle(4, 0, 0.5);
		//g.beginFill(0x300020);
		g.beginBitmapFill(texture, new Matrix(1, 0, 0, 1, middlePoint.x, middlePoint.y));
		g.moveTo(p0.x, p0.y);
		g.curveTo(controlPoint0.x, controlPoint0.y, p1.x, p1.y);
		g.curveTo(controlPoint1.x, controlPoint1.y, p0.x, p0.y);
		g.endFill();
		
		g.lineStyle(kuparableThickness, 0xff0000, 0);
		g.moveTo(p0.x, p0.y);
		g.curveTo(kuparablePoint0.x, kuparablePoint0.y, p1.x, p1.y);
		g.curveTo(kuparablePoint1.x, kuparablePoint1.y, p0.x, p0.y);
	}
	
	private function getKuparablePoint(controlPoint:Point):Point
	{
		return Point.interpolate(middlePoint, controlPoint, 0);
	}
	
	private function tStart(e:TouchEvent):void 
	{
		if (tPointList[e.touchPointID] == null) {
			stage.addEventListener(TouchEvent.TOUCH_MOVE, tMove, false, 0, true);
			stage.addEventListener(TouchEvent.TOUCH_END, tEnd, false, 0, true);
		}
		
		_downQueue.push(e.touchPointID);
		
		tPointList[e.touchPointID] = new Point(e.stageX, e.stageY);
	}
	
	private function tMove(e:TouchEvent):void 
	{
		var tp:Point = new Point(e.stageX, e.stageY);
		tPointList[e.touchPointID] = tp.clone();
		
		if (Point.distance(tp, controlPoint0) < Point.distance(tp, controlPoint1)) {
			controlPoint0 = tp;
		}else {
			controlPoint1 = tp;
		}
		
		draw();
	}
	
	private function tEnd(e:TouchEvent):void 
	{
		tPointList[e.touchPointID] = null;
		var i:int = _downQueue.indexOf(e.touchPointID);
		if (i < 0) return;
		_downQueue.splice(i, 1);
		
		if (_downQueue.length < 1) {
			stage.removeEventListener(TouchEvent.TOUCH_MOVE, tMove);
			stage.removeEventListener(TouchEvent.TOUCH_END, tEnd);
			
			//ピタリと閉じる
			//if (Point.distance(controlPoint0, controlPoint1) < 50) {
				//this.removeEventListener(TouchEvent.TOUCH_BEGIN, tStart);
				//this.parent.removeChild(this);
			//}
		}
	}
	
	public function get tp0():Point { return tPointList[_downQueue[0]]; }
	public function get tp1():Point { return tPointList[_downQueue[1]]; }
}