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: Checkmate Vol.6 Amatuer

2010/01/06こそっと投下
* 参考本 .fla2 http://www.wgn.co.jp/store/dat/3184/
* 1章参照P17~P30ほぼコードは拝借しました。
* ベクトル計算とか解説はこの本を買うといいです。
* 
* drawTrianglesについて勉強してみる。 
* 実写は無理でした!写真を撮らせてくれるおなごがいない!ごめんなさい!
* うわさではおしりがさわれて
* スカートをめくることができるらしい・・・
* 注意:やりすぎないように!!
* まったくリファクタリングしていない。。。
* 誰かがもっとリアルなのをつくってくれると信じている!
* @author OKASUKE
Get Adobe Flash player
by OKASUKE 06 Jan 2010
/**
 * Copyright OKASUKE ( http://wonderfl.net/user/OKASUKE )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/1Iyg
 */

// forked from checkmate's Checkmate Vol.6 Amatuer
/**2010/01/06こそっと投下
* 参考本 .fla2 http://www.wgn.co.jp/store/dat/3184/
* 1章参照P17~P30ほぼコードは拝借しました。
* ベクトル計算とか解説はこの本を買うといいです。
* 
* drawTrianglesについて勉強してみる。 
* 実写は無理でした!写真を撮らせてくれるおなごがいない!ごめんなさい!
* うわさではおしりがさわれて
* スカートをめくることができるらしい・・・
* 注意:やりすぎないように!!
* まったくリファクタリングしていない。。。
* 誰かがもっとリアルなのをつくってくれると信じている!
* @author OKASUKE
*/
package  
{	
	import flash.display.DisplayObject;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	import flash.net.URLRequest;
	import flash.net.URLLoader;
	import flash.system.LoaderContext;
	import flash.ui.MouseCursor;
	import flash.ui.Mouse;
		
	[SWF( width=465, height=465, backgroundColor=0xFFFFFF, frameRate=30 )]
	public class CheckmateAmatuer extends Sprite
	{
		private static const TEXTURE_W:uint = 350;
		private static const TEXTURE_H:uint = 212;
		
		private static const SEGMENT_W:uint = 16;
		private static const SEGMENT_H:uint = 24;
	;
		//private var url:String = "http://assets.wonderfl.net/images/related_images/a/a9/a9d1/a9d166b501ff52d0cf9940d3c8e2a60f5fb85fe3"
		private var url:String = "http://assets.wonderfl.net/images/related_images/3/38/380d/380d152814430d98f9283edad9595305651da854"
		private var _loader:Loader;	
		private var _nuno:Sprite = new Sprite();
		private var _nunobitmap:Bitmap;
	
		private var _texture:BitmapData;
		private var _vertices:Vector.<Number>;
		private var _uvData:Vector.<Number>;
		private var _indices:Vector.<int>;
		
		private var _baseVertices:Vector.<Number>;
		private var _powerVertices:Vector.<Number>;
		private var _energies:Vector.<Number>;
		private var _dragpower:Rectangle;
		
		private var _sp:Sprite = new Sprite();
		private var _spskirt:Sprite = new Sprite();
		
		public function CheckmateAmatuer() {
			/*
            コードでエッチなものごとを描写してください。
            公序良俗は守ってください。
            
            Represent something sexual by codes.
            DO NOT be offensive to public order and morals.
            */
			_loader = new Loader();			
			configureListeners(_loader.contentLoaderInfo);
			var req:URLRequest = new URLRequest(url);
            _loader.load(req, new LoaderContext(true));		
		}
		
		private function configureListeners(dispatcher:IEventDispatcher):void {			
			dispatcher.addEventListener(Event.COMPLETE, onComplete);
		}
	
		private function onComplete(event:Event):void {
			_nunobitmap = _loader.content as Bitmap;			
			
			
			addChild(new DrawH(this));
			setPoint();
				
			addChild(_sp);			
				
			stage.addEventListener(Event.ENTER_FRAME, enterloop);	
			stage.addEventListener(MouseEvent.MOUSE_DOWN, mousedown);
			stage.addEventListener(MouseEvent.MOUSE_MOVE, mousemove);
			stage.addEventListener(MouseEvent.MOUSE_UP, mouseup);
		}
		
		private function mousedown(e:Event):void {	
			
			if (stage.mouseX >= 140 && stage.mouseX <= 240 
					&& stage.mouseY >= 130 && stage.mouseY <= 230) {
					
				if (_dragpower == null) {
					_dragpower = new Rectangle();
					_dragpower.x = stage.mouseX;
					_dragpower.y = stage.mouseY;
				}			
			}		
		}
		
		private function mousemove(e:Event):void {
			if (stage.mouseX >= 140 && stage.mouseX <= 240 
					&& stage.mouseY >= 130 && stage.mouseY <= 230) {
				Mouse.cursor = MouseCursor.HAND;
			} else {
				Mouse.cursor = MouseCursor.ARROW;				
			}
			
			if (_dragpower != null) {				
				
				_dragpower.width = (stage.mouseX - _dragpower.x) / 2;
				_dragpower.height = (stage.mouseY - _dragpower.y) / 2;
				
				if (_dragpower != null && _dragpower.height > 0) {
					mouseup(e);
				}
				if (_dragpower != null && _dragpower.width > -40 && _dragpower.width <= 40) {
				} else {	
					mouseup(e);
				}
			}
		}
		
		private function mouseup(e:*):void {
			Mouse.cursor = MouseCursor.ARROW ;
			if (_dragpower != null) {
				_dragpower = null;
			}
		}
		
		private function enterloop(e:Event):void {			
			
			for (var i:uint = 0; i < (SEGMENT_W + 1) * (SEGMENT_H + 1) * 2; ++i) {				
				_powerVertices[i] = _baseVertices[i];
			}
			
			if (_dragpower != null) {
				addFlow(_dragpower, _powerVertices);
			}
			
			calcEnergy();	
	
			var g:Graphics = graphics;
			_sp.x = 25;
			//_sp.y = -50;
		
			with(_sp.graphics) {
				clear();
				//lineStyle(0,0x000000);
				beginBitmapFill(_nunobitmap.bitmapData);			
				drawTriangles(_vertices,_indices,_uvData);
				endFill();
			}
		}
		
		private function calcEnergy():void {
			var i:uint = 0;
			for (var x:uint = 0; x <= SEGMENT_W; ++x) {
				for (var y:uint = 0; y <= SEGMENT_H; ++y) {					
					_energies[i] = (_energies[i] + (_powerVertices[i] - _vertices[i])) * 0.096;
					_energies[i + 1] = (_energies[i + 1] + (_powerVertices[i + 1] - _vertices[i+1])) * 0.096;
					
					_vertices[i] += _energies[i];
					_vertices[i + 1] += _energies[i + 1];
					
					i += 2;
				}
				
			}
		}
			
		//めくる
		private function addFlow(power:Rectangle, vertices:Vector.<Number>):void {
			
			var px:Number = power.x;
			var py:Number = power.y;
			
			var vx:Number = power.width;
			var vy:Number = power.height;
			
			var v1:Number = Math.sqrt(vx * vx + vy * vy);
			
			var nvx:Number = v1 != 0 ? vx / v1 : 0;
			var nvy:Number = v1 != 0 ? vy / v1 : 0;
			var i:uint = 0;	
			for (var x:uint = 0; x <= SEGMENT_W; ++x) {
				for (var y:uint = 0 ; y <= SEGMENT_H; ++y) {					
					var baseX:Number = vertices[i];
					var baseY:Number = vertices[i + 1];
					
					var dx:Number = baseX - px;
					var dy:Number = baseY - py;
					var d:Number = dx * dx + dy * dy;
					var d1:Number = Math.sqrt(d);
					
					var ndx:Number = d1 != 0 ? dx / d1 :0;
					var ndy:Number = d1 != 0 ? dy / d1 :0;
						
					var t:Number = Math.atan2(nvx * ndy - nvy * ndx, nvx * ndx + nvy * ndy);
					var f:Number = 1.0 - Math.abs(t) / (Math.PI / 4);
					if (f < 0) {
						f = 0;
					}
					
					var l:Number = 120.0 * (1.0 + f * 1.2);
					
					var factor:Number = 1.0 - d / (l * l);
					if (factor < 0) {
						factor = 0;
					}
					
					vertices[i] = baseX + vx * factor;
					vertices[i + 1] = baseY + vy * factor;
					
					i += 2;
				}				
			}			
		}
			
		private function setPoint():void {
			
			var numVertices:int = (SEGMENT_W + 1) * (SEGMENT_H + 1) * 2;
				
			var i:uint = 0;
			var x:uint, y:uint;
			
			_baseVertices = new Vector.<Number>(numVertices, true);
			_powerVertices = new Vector.<Number>(numVertices, true);
			_vertices = new Vector.<Number>(numVertices, true);
			_energies = new Vector.<Number>(numVertices, true);
			_uvData = new Vector.<Number>(numVertices, true);
			_indices = new Vector.<int>(SEGMENT_W * (6 * SEGMENT_H), true);
			
			var w:Number = TEXTURE_W / SEGMENT_W;
			var h:Number = TEXTURE_H / SEGMENT_H;
						
			for (x = 0; x <= SEGMENT_W; ++x) {				
				for (y = 0; y <= SEGMENT_H; ++y) {
					i = (y * (SEGMENT_W + 1) + x) * 2;
					_vertices[i] = w * x;
					_vertices[i + 1] = h * y;
					_baseVertices[i] = _vertices[i];
					_baseVertices[i + 1] = _vertices[i + 1];
					_powerVertices[i] = _vertices[i];
					_powerVertices[i + 1] = _vertices[i + 1];
					
					_energies[i] = 0.0;
					_energies[i + 1] = 0.0;
					_uvData[i] = _vertices[i] / TEXTURE_W;
					_uvData[i + 1] = _vertices[i + 1] / TEXTURE_H;					
				}
			}
					
			for (x = 0; x < SEGMENT_W; ++x) {
				i = (x * (6 * SEGMENT_H));
				//trace(i);
				for (y = 0; y < SEGMENT_H; ++y) {
					_indices[i + y * 6 + 0] = (y + 0) * (SEGMENT_W + 1) + (x + 0);
					_indices[i + y * 6 + 1] = (y + 0) * (SEGMENT_W + 1) + (x + 1);
					_indices[i + y * 6 + 2] = (y + 1) * (SEGMENT_W + 1) + (x + 0);
					_indices[i + y * 6 + 3] = (y + 0) * (SEGMENT_W + 1) + (x + 1);
					_indices[i + y * 6 + 4] = (y + 1) * (SEGMENT_W + 1) + (x + 0);
					_indices[i + y * 6 + 5] = (y + 1) * (SEGMENT_W + 1) + (x + 1);					
				}				
			}			
		}		
	}
}

import flash.display.Sprite;
import flash.display.Graphics;
import flash.geom.Point;
// ベジェ曲線について リファクタリングしてない。。。たしかベクターにいれて一気にdrawできるのがあるはず。
// 参考 http://wonderfl.net/code/68b3660df66beea1ce702b63c267d41fa7f39f98
class DrawH extends Sprite {
	
   private var a:Point = new Point(0, 0);
    private var b:Point = new Point(0, 0);
    private var c:Point = new Point(0, 0);
		
	private var _stage:Sprite;
	
	public function DrawH(canvas:Sprite) {		
		_stage = canvas;
		ashiR();
		ashiL();		
	}
	
	private function ashiR():void {
		var koshiashiR:Sprite = new Sprite();
		_stage.addChild(koshiashiR);
		with (koshiashiR.graphics) {
			
			a = new Point(80, 0);
			b = new Point(70, 200);
			c = new Point(110, 465);
			lineStyle(-1);
			beginFill(0xffd3cc, 1.0);
			moveTo(a.x, a.y);			
			curveTo(b.x, b.y, c.x, c.y);
			
			a = new Point(222, 220);
			b = new Point(230, 300);
			c = new Point(210, 465);
				
			lineTo(c.x, c.y);
			curveTo(b.x, b.y, a.x, a.y);
				
			a = new Point(90, 0);
			b = new Point(260, 150);
			c = new Point(222, 220);
			
			lineTo(c.x, c.y);
			curveTo(b.x, b.y, a.x, a.y);	
			
			graphics.endFill();		
		}
	}	
		
	private function ashiL():void {
		var koshiashiL:Sprite = new Sprite();
		_stage.addChild(koshiashiL);
		with (koshiashiL.graphics) {
			
			a = new Point(340, 0);
			b = new Point(370, 100);
			c = new Point(340, 200);
		
			lineStyle(-1);
			moveTo(a.x, a.y);
			beginFill(0xffd3cc, 1.0);
			curveTo(b.x, b.y, c.x, c.y);			
			
			a = new Point(340, 200);
			b = new Point(350, 250);
			c = new Point(340, 465);	
			lineTo(a.x, a.y);			
			curveTo(b.x, b.y, c.x, c.y);			
		
			a = new Point(222, 220);
			b = new Point(230, 300);
			c = new Point(240, 465);		
			lineTo(c.x, c.y);
			curveTo(b.x, b.y, a.x, a.y); 
			
			a = new Point(330, 0);
			b = new Point(340, 160);
			c = new Point(222, 220);			
			lineTo(c.x, c.y);
			curveTo(b.x, b.y, a.x, a.y);		
			endFill();				
		}
	}	
}