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

回転メッシュAS3

Get Adobe Flash player
by termat 05 Jun 2010
    Embed
/**
 * Copyright termat ( http://wonderfl.net/user/termat )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/aplQ
 */

package
{
	import flash.display.Sprite;

	public class Practice78 extends Sprite{
		
		public function Practice78() {
			for (var i:int = 0; i < 14; i++) {
				var xx:Number = i * 30 + (i+1) * 4;
				for (var j:int = 0; j < 14; j++) {
					var yy:Number = j * 30 + (j + 1) * 4;
					var t:Tile = new Tile();
					t.x = xx + t.W / 2, t.y = yy + t.H / 2;
					t.deg = 0;
					addChild(t);
				}
			}
			for (i = 0; i < 14; i++) {
				for (j = 0; j < 14; j++) {
					var tt:Tile = getChildAt(i * 14 + j) as Tile;
					if (j > 0) tt.neigh.push(getChildAt(i * 14 + j - 1));
					if (j < 13)tt.neigh.push(getChildAt(i * 14 + j + 1));
					if (i > 0) tt.neigh.push(getChildAt((i-1) * 14 + j ));
					if (i < 13)tt.neigh.push(getChildAt((i+1) * 14 + j));
				}
			}
		}
	}
}
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
class Tile extends MovieClip {
	private var sel:Boolean = false;
	public const W:Number = 30;
	public const H:Number = 30;
	public var deg:Number = 0;
	public var d:Number = W;
	public var neigh:Array = new Array();
	
	public function Tile():void {
		addEventListener(Event.ENTER_FRAME, update);
		addEventListener(MouseEvent.ROLL_OVER, function(e:MouseEvent):void {
			sel = true;
			d = 1;
			check(3, false);
		} );
		addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent):void {
			sel = true;
			d = 1;
			check(5, true);
		} );
	}
	
	private function check(n:int,b:Boolean):void {
		for each(var t:Tile in neigh) {
			if (t.d == W) t.d = 1;
			if (b && rotationZ % 180 == 0) rotationZ += 5;
			if (n > 0) t.check(n - 1,b);
		}
	}
	
	private function update(e:Event):void {
		graphics.clear();
		graphics.beginFill(getColor(deg,0.9,1.0));
		graphics.drawRect(-W/2, -H/2, W, H);
		graphics.endFill();
		if (sel||rotationZ%180!=0) {
			rotationZ += 5;
			sel = false;
			deg++;
		}
		if (d < W) {
			graphics.beginFill(getColor(deg,0.5,1.0));
			graphics.drawRect(-d/2, -d/2, d, d);
			graphics.endFill();
			d++;
		}
	}
	
	private static function getColor(i:int, saturation:Number, v:Number):uint {
		var h:Number = i / 60;
		var ii:Number = Math.floor(h);
		var ff:Number = h - ii;
		var p1:Number = (v - saturation);
		var p2:Number = (v - saturation * ff);
		var p3:Number = (v - saturation * (v - ff));
		var rv:Number, gv:Number, bv:Number;
		switch(ii) {
		case 0:
			rv = v, gv = p3, bv = p1;
			break;
		case 1:
			rv = p2, gv = v, bv = p1;
			break;
		case 2:
			rv = p1, gv = v, bv = p3;
			break;
		case 3:
			rv = p1, gv = p2, bv = v;
			break;
		case 4:
			rv = p3, gv = p1, bv = v;
			break;
		default:
			rv = v, gv = p1, bv = p2;
		}
		var color:uint = (Math.max(0, Math.min(255, rv * 255)) << 16) + (Math.max(0, Math.min(255, gv * 255)) << 8) + Math.max(0, Math.min(255, bv * 255));
		return color;
	}
}